summaryrefslogtreecommitdiff
path: root/libavformat/avformat.h
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2016-01-16 17:53:43 +0100
committerAnton Khirnov <anton@khirnov.net>2016-01-24 16:45:32 +0100
commit9f61abc8111c7c43f49ca012e957a108b9cc7610 (patch)
tree87af58cf56a1298f4b9b6a242d9c3a9451388ec8 /libavformat/avformat.h
parent68395f8c99393c281a08139d20a7a04398b2fd04 (diff)
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.
Diffstat (limited to 'libavformat/avformat.h')
-rw-r--r--libavformat/avformat.h33
1 files changed, 33 insertions, 0 deletions
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 {