--- Sometimes you receive a seekable fd from the outside.
libavformat/file.c | 32 ++++++++++++++++++++++++++++++++ libavformat/protocols.c | 1 + 2 files changed, 33 insertions(+) diff --git a/libavformat/file.c b/libavformat/file.c index 27ce4de6eb..6a74ebbf48 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -204,3 +204,35 @@ const URLProtocol ff_pipe_protocol = { }; #endif /* CONFIG_PIPE_PROTOCOL */ + +#if CONFIG_FD_PROTOCOL + +static int fd_open(URLContext *h, const char *filename, int flags) +{ + FileContext *c = h->priv_data; + int fd; + char *final; + av_strstart(filename, "fd:", &filename); + + fd = strtol(filename, &final, 10); + if ((filename == final) || *final ) { + return AVERROR(EINVAL); + } +#if HAVE_SETMODE + setmode(fd, O_BINARY); +#endif + c->fd = fd; + return 0; +} + +const URLProtocol ff_pipe_protocol = { + .name = "fd", + .url_open = fd_open, + .url_read = file_read, + .url_write = file_write, + .url_get_file_handle = file_get_handle, + .url_check = file_check, + .priv_data_size = sizeof(FileContext), +}; + +#endif /* CONFIG_FD_PROTOCOL */ diff --git a/libavformat/protocols.c b/libavformat/protocols.c index 15b9ed736d..b3f8b4af56 100644 --- a/libavformat/protocols.c +++ b/libavformat/protocols.c @@ -27,6 +27,7 @@ extern const URLProtocol ff_concat_protocol; extern const URLProtocol ff_crypto_protocol; extern const URLProtocol ff_ffrtmpcrypt_protocol; extern const URLProtocol ff_ffrtmphttp_protocol; +extern const URLProtocol ff_fd_protocol; extern const URLProtocol ff_file_protocol; extern const URLProtocol ff_gopher_protocol; extern const URLProtocol ff_hls_protocol; -- 2.12.2 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel