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/smoothstreamingenc.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'libavformat/smoothstreamingenc.c') diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c index 6af8b3991c..8e8a64513c 100644 --- a/libavformat/smoothstreamingenc.c +++ b/libavformat/smoothstreamingenc.c @@ -220,7 +220,7 @@ static int write_manifest(AVFormatContext *s, int final) snprintf(filename, sizeof(filename), "%s/Manifest", s->filename); snprintf(temp_filename, sizeof(temp_filename), "%s/Manifest.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; @@ -282,7 +282,7 @@ static int write_manifest(AVFormatContext *s, int final) } avio_printf(out, "\n"); avio_flush(out); - avio_close(out); + ff_format_io_close(s, &out); return ff_rename(temp_filename, filename); } @@ -409,7 +409,7 @@ static int parse_fragment(AVFormatContext *s, const char *filename, int64_t *sta AVIOContext *in; int ret; uint32_t len; - if ((ret = avio_open2(&in, filename, AVIO_FLAG_READ, &s->interrupt_callback, NULL)) < 0) + if ((ret = s->io_open(s, &in, filename, AVIO_FLAG_READ, NULL)) < 0) return ret; ret = AVERROR(EIO); *moof_size = avio_rb32(in); @@ -450,7 +450,7 @@ static int parse_fragment(AVFormatContext *s, const char *filename, int64_t *sta avio_seek(in, end, SEEK_SET); } fail: - avio_close(in); + ff_format_io_close(s, &in); return ret; } @@ -486,10 +486,10 @@ static int copy_moof(AVFormatContext *s, const char* infile, const char *outfile { AVIOContext *in, *out; int ret = 0; - if ((ret = avio_open2(&in, infile, AVIO_FLAG_READ, &s->interrupt_callback, NULL)) < 0) + if ((ret = s->io_open(s, &in, infile, AVIO_FLAG_READ, NULL)) < 0) return ret; - if ((ret = avio_open2(&out, outfile, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL)) < 0) { - avio_close(in); + if ((ret = s->io_open(s, &out, outfile, AVIO_FLAG_WRITE, NULL)) < 0) { + ff_format_io_close(s, &in); return ret; } while (size > 0) { @@ -504,8 +504,8 @@ static int copy_moof(AVFormatContext *s, const char* infile, const char *outfile size -= n; } avio_flush(out); - avio_close(out); - avio_close(in); + ff_format_io_close(s, &out); + ff_format_io_close(s, &in); return ret; } -- cgit v1.2.3