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/dashenc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'libavformat/dashenc.c') diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index cedd83b67b..12d3a8c45b 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -444,7 +444,7 @@ static int write_manifest(AVFormatContext *s, int final) AVDictionaryEntry *title = av_dict_get(s->metadata, "title", NULL, 0); snprintf(temp_filename, sizeof(temp_filename), "%s.tmp", s->filename); - ret = avio_open2(&out, temp_filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL); + ret = s->io_open(s, &out, temp_filename, AVIO_FLAG_WRITE, NULL); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename); return ret; @@ -532,7 +532,7 @@ static int write_manifest(AVFormatContext *s, int final) avio_printf(out, "\t\n"); avio_printf(out, "\n"); avio_flush(out); - avio_close(out); + ff_format_io_close(s, &out); return ff_rename(temp_filename, s->filename); } @@ -604,6 +604,9 @@ static int dash_write_header(AVFormatContext *s) os->ctx = ctx; ctx->oformat = oformat; ctx->interrupt_callback = s->interrupt_callback; + ctx->opaque = s->opaque; + ctx->io_close = s->io_close; + ctx->io_open = s->io_open; if (!(st = avformat_new_stream(ctx, NULL))) { ret = AVERROR(ENOMEM); -- cgit v1.2.3