From 2a0028aa130a542f10a2f88bd12025b6c240da27 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 16 Jun 2017 22:40:42 +0200 Subject: 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). --- stream/stream_file.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'stream/stream_file.c') 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, }; -- cgit v1.2.3