From 9f61abc8111c7c43f49ca012e957a108b9cc7610 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 16 Jan 2016 17:53:43 +0100 Subject: lavf: allow custom IO for all files Some (de)muxers open additional files beyond the main IO context. Currently, they call avio_open() directly, which prevents the caller from using custom IO for such streams. This commit adds callbacks to AVFormatContext that default to avio_open2()/avio_close(), but can be overridden by the caller. All muxers and demuxers using AVIO are switched to using those callbacks instead of calling avio_open()/avio_close() directly. (de)muxers that use the URLProtocol layer directly instead of AVIO remain unconverted for now. This should be fixed in later commits. --- libavformat/options.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libavformat/options.c') diff --git a/libavformat/options.c b/libavformat/options.c index a6fbbd2623..c7fa51f41f 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -90,12 +90,26 @@ static const AVClass av_format_context_class = { .child_class_next = format_child_class_next, }; +static int io_open_default(AVFormatContext *s, AVIOContext **pb, + const char *url, int flags, AVDictionary **options) +{ + return avio_open2(pb, url, flags, &s->interrupt_callback, options); +} + +static void io_close_default(AVFormatContext *s, AVIOContext *pb) +{ + avio_close(pb); +} + static void avformat_get_context_defaults(AVFormatContext *s) { memset(s, 0, sizeof(AVFormatContext)); s->av_class = &av_format_context_class; + s->io_open = io_open_default; + s->io_close = io_close_default; + av_opt_set_defaults(s); } -- cgit v1.2.3