diff options
author | sfan5 <sfan5@live.de> | 2017-06-16 22:40:42 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2017-06-16 22:48:44 +0200 |
commit | 2a0028aa130a542f10a2f88bd12025b6c240da27 (patch) | |
tree | fddea2b106a3badbe2e140ea3a447b6e8b181325 /stream/stream_file.c | |
parent | 986e10901dad89eed89ae79d2bc0f1634d1cacbd (diff) | |
download | mpv-2a0028aa130a542f10a2f88bd12025b6c240da27.tar.bz2 mpv-2a0028aa130a542f10a2f88bd12025b6c240da27.tar.xz |
stream_file: option to close fd after use -> fdclose://
fdclose://123 will instruct mpv to close the file descriptor
when it is no longer needed (usually when playing finishes).
Diffstat (limited to 'stream/stream_file.c')
-rw-r--r-- | stream/stream_file.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/stream/stream_file.c b/stream/stream_file.c index 7d2b82fb58..d12d0d20b1 100644 --- a/stream/stream_file.c +++ b/stream/stream_file.c @@ -246,13 +246,16 @@ static int open_f(stream_t *stream) filename = stream->path; } - if (strncmp(stream->url, "fd://", 5) == 0) { - char *end = NULL; - p->fd = strtol(stream->url + 5, &end, 0); - if (!end || end == stream->url + 5 || end[0]) { + bool is_fdclose = strncmp(stream->url, "fdclose://", 10) == 0; + if (strncmp(stream->url, "fd://", 5) == 0 || is_fdclose) { + char *begin = strstr(stream->url, "://") + 3, *end = NULL; + p->fd = strtol(begin, &end, 0); + if (!end || end == begin || end[0]) { MP_ERR(stream, "Invalid FD: %s\n", stream->url); return STREAM_ERROR; } + if (is_fdclose) + p->close = true; } else if (!strcmp(filename, "-")) { if (!write) { MP_INFO(stream, "Reading from stdin...\n"); @@ -322,7 +325,7 @@ static int open_f(stream_t *stream) const stream_info_t stream_info_file = { .name = "file", .open = open_f, - .protocols = (const char*const[]){ "file", "", "fd", NULL }, + .protocols = (const char*const[]){ "file", "", "fd", "fdclose", NULL }, .can_write = true, .is_safe = true, }; |