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/img2enc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'libavformat/img2enc.c') diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c index d5b664658f..4071c3545c 100644 --- a/libavformat/img2enc.c +++ b/libavformat/img2enc.c @@ -72,8 +72,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EIO); } for (i = 0; i < 3; i++) { - if (avio_open2(&pb[i], img->tmp, AVIO_FLAG_WRITE, - &s->interrupt_callback, NULL) < 0) { + if (s->io_open(s, &pb[i], img->tmp, AVIO_FLAG_WRITE, NULL) < 0) { av_log(s, AV_LOG_ERROR, "Could not open file : %s\n", img->tmp); return AVERROR(EIO); } @@ -91,8 +90,8 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) avio_write(pb[0], pkt->data, ysize); avio_write(pb[1], pkt->data + ysize, (pkt->size - ysize) / 2); avio_write(pb[2], pkt->data + ysize + (pkt->size - ysize) / 2, (pkt->size - ysize) / 2); - avio_close(pb[1]); - avio_close(pb[2]); + ff_format_io_close(s, &pb[1]); + ff_format_io_close(s, &pb[2]); } else { if (ff_guess_image2_codec(s->filename) == AV_CODEC_ID_JPEG2000) { AVStream *st = s->streams[0]; @@ -122,7 +121,7 @@ error: } avio_flush(pb[0]); if (!img->is_pipe) { - avio_close(pb[0]); + ff_format_io_close(s, &pb[0]); ff_rename(img->tmp, filename); } -- cgit v1.2.3