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/hls.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libavformat/hls.c') diff --git a/libavformat/hls.c b/libavformat/hls.c index dc3ab87b8a..d3b4b58d01 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -94,6 +94,7 @@ struct variant { }; typedef struct HLSContext { + AVFormatContext *ctx; int n_variants; struct variant **variants; int cur_seq_no; @@ -207,7 +208,7 @@ static int open_in(HLSContext *c, AVIOContext **in, const char *url) av_dict_copy(&tmp, c->avio_opts, 0); - ret = avio_open2(in, url, AVIO_FLAG_READ, c->interrupt_callback, &tmp); + ret = c->ctx->io_open(c->ctx, in, url, AVIO_FLAG_READ, &tmp); av_dict_free(&tmp); return ret; @@ -370,7 +371,7 @@ static int parse_playlist(HLSContext *c, const char *url, fail: av_free(new_url); if (close_in) - avio_close(in); + ff_format_io_close(c->ctx, &in); return ret; } @@ -514,6 +515,7 @@ static int hls_read_header(AVFormatContext *s) HLSContext *c = s->priv_data; int ret = 0, i, j, stream_offset = 0; + c->ctx = s; c->interrupt_callback = &s->interrupt_callback; if ((ret = parse_playlist(c, s->filename, NULL, s->pb)) < 0) -- cgit v1.2.3