summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-10-19 15:27:42 +0200
committerwm4 <wm4@nowhere>2015-10-19 15:27:42 +0200
commit667b968939fc3dea63e010c3b64e465225a2321a (patch)
tree3421a2d2dd73f9ba3bcc91d3aaa386ca1b77687e /demux
parente1128c8b28a467c131eba6ce8f48f150f8ef5fd7 (diff)
downloadmpv-667b968939fc3dea63e010c3b64e465225a2321a.tar.bz2
mpv-667b968939fc3dea63e010c3b64e465225a2321a.tar.xz
demux_lavf: always copy codec headers
If this is not done, libavformat could change the headers while demuxing, all while the decoder thread reads these fields during initialization.
Diffstat (limited to 'demux')
-rw-r--r--demux/demux_lavf.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index f73c8693ba..fbe4290758 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -635,7 +635,10 @@ static void handle_stream(demuxer_t *demuxer, int i)
sh->ff_index = st->index;
sh->codec = mp_codec_from_av_codec_id(codec->codec_id);
sh->codec_tag = codec->codec_tag;
- sh->lav_headers = codec;
+ sh->lav_headers = avcodec_alloc_context3(NULL);
+ if (!sh->lav_headers)
+ return;
+ mp_copy_lav_codec_headers(sh->lav_headers, codec);
if (st->disposition & AV_DISPOSITION_DEFAULT)
sh->default_track = true;
@@ -1076,6 +1079,10 @@ static void demux_close_lavf(demuxer_t *demuxer)
if (priv->pb)
av_freep(&priv->pb->buffer);
av_freep(&priv->pb);
+ for (int n = 0; n < priv->num_streams; n++) {
+ if (priv->streams[n])
+ avcodec_free_context(&priv->streams[n]->lav_headers);
+ }
talloc_free(priv);
demuxer->priv = NULL;
}