summaryrefslogtreecommitdiff
path: root/libavformat/hlsenc.c
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/hlsenc.c
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/hlsenc.c')
-rw-r--r--libavformat/hlsenc.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 8f01047be0..843f37d82c 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -74,6 +74,9 @@ static int hls_mux_init(AVFormatContext *s)
oc->oformat = hls->oformat;
oc->interrupt_callback = s->interrupt_callback;
+ oc->opaque = s->opaque;
+ oc->io_open = s->io_open;
+ oc->io_close = s->io_close;
for (i = 0; i < s->nb_streams; i++) {
AVStream *st;
@@ -140,8 +143,7 @@ static int hls_window(AVFormatContext *s, int last)
int64_t sequence = FFMAX(hls->start_sequence, hls->sequence - hls->size);
snprintf(temp_filename, sizeof(temp_filename), "%s.tmp", s->filename);
- if ((ret = avio_open2(&out, temp_filename, AVIO_FLAG_WRITE,
- &s->interrupt_callback, NULL)) < 0)
+ if ((ret = s->io_open(s, &out, temp_filename, AVIO_FLAG_WRITE, NULL)) < 0)
goto fail;
for (en = hls->list; en; en = en->next) {
@@ -178,7 +180,7 @@ static int hls_window(AVFormatContext *s, int last)
avio_printf(out, "#EXT-X-ENDLIST\n");
fail:
- avio_closep(&out);
+ ff_format_io_close(s, &out);
if (ret >= 0)
ff_rename(temp_filename, s->filename);
return ret;
@@ -195,8 +197,7 @@ static int hls_start(AVFormatContext *s)
return AVERROR(EINVAL);
c->number++;
- if ((err = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,
- &s->interrupt_callback, NULL)) < 0)
+ if ((err = s->io_open(s, &oc->pb, oc->filename, AVIO_FLAG_WRITE, NULL)) < 0)
return err;
if (oc->oformat->priv_class && oc->priv_data)
@@ -300,7 +301,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
hls->duration = 0;
av_write_frame(oc, NULL); /* Flush any buffered data */
- avio_close(oc->pb);
+ ff_format_io_close(s, &oc->pb);
ret = hls_start(s);
@@ -324,7 +325,7 @@ static int hls_write_trailer(struct AVFormatContext *s)
AVFormatContext *oc = hls->avf;
av_write_trailer(oc);
- avio_closep(&oc->pb);
+ ff_format_io_close(s, &oc->pb);
avformat_free_context(oc);
av_free(hls->basename);
append_entry(hls, hls->duration);