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/avformat.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'libavformat/avformat.h') diff --git a/libavformat/avformat.h b/libavformat/avformat.h index cd53420215..4926a354f9 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1229,6 +1229,39 @@ typedef struct AVFormatContext { * Must not be accessed in any way by callers. */ AVFormatInternal *internal; + + /** + * Arbitrary user data set by the caller. + */ + void *opaque; + + /** + * A callback for opening new IO streams. + * + * Certain muxers or demuxers (e.g. for various playlist-based formats) need + * to open additional files during muxing or demuxing. This callback allows + * the caller to provide custom IO in such cases. + * + * @param s the format context + * @param pb on success, the newly opened IO context should be returned here + * @param url the url to open + * @param flags a combination of AVIO_FLAG_* + * @param options a dictionary of additional options, with the same + * semantics as in avio_open2() + * @return 0 on success, a negative AVERROR code on failure + * + * @note Certain muxers and demuxers do nesting, i.e. they open one or more + * additional internal format contexts. Thus the AVFormatContext pointer + * passed to this callback may be different from the one facing the caller. + * It will, however, have the same 'opaque' field. + */ + int (*io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, + int flags, AVDictionary **options); + + /** + * A callback for closing the streams opened with AVFormatContext.io_open(). + */ + void (*io_close)(struct AVFormatContext *s, AVIOContext *pb); } AVFormatContext; typedef struct AVPacketList { -- cgit v1.2.3