summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2017-06-16 22:40:42 +0200
committerwm4 <wm4@nowhere>2017-06-16 22:48:44 +0200
commit2a0028aa130a542f10a2f88bd12025b6c240da27 (patch)
treefddea2b106a3badbe2e140ea3a447b6e8b181325
parent986e10901dad89eed89ae79d2bc0f1634d1cacbd (diff)
downloadmpv-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).
-rw-r--r--DOCS/man/mpv.rst5
-rw-r--r--stream/stream_file.c13
2 files changed, 13 insertions, 5 deletions
diff --git a/DOCS/man/mpv.rst b/DOCS/man/mpv.rst
index 3ca135439d..a9fc5edab9 100644
--- a/DOCS/man/mpv.rst
+++ b/DOCS/man/mpv.rst
@@ -769,6 +769,11 @@ PROTOCOLS
Read data from the given file descriptor (for example 123). This is similar
to piping data to stdin via ``-``, but can use an arbitrary file descriptor.
+``fdclose://123``
+
+ Like ``fd://``, but the file descriptor is closed after use. When using this
+ you need to ensure that the same fd URL will only be used once.
+
``edl://[edl specification as in edl-mpv.rst]``
Stitch together parts of multiple files and play them.
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,
};