Commit 98b3a797 authored by Andreas Cadhalpun's avatar Andreas Cadhalpun

flvdec: require need_context_update when changing codec id

Otherwise the codec context and codecpar might disagree on the codec id,
triggering asserts in av_parser_parse2.
Reviewed-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
Signed-off-by: 's avatarAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
parent 06f94149
...@@ -291,7 +291,9 @@ static int flv_same_video_codec(AVCodecParameters *vpar, int flags) ...@@ -291,7 +291,9 @@ static int flv_same_video_codec(AVCodecParameters *vpar, int flags)
static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream,
int flv_codecid, int read) int flv_codecid, int read)
{ {
int ret = 0;
AVCodecParameters *par = vstream->codecpar; AVCodecParameters *par = vstream->codecpar;
enum AVCodecID old_codec_id = vstream->codecpar->codec_id;
switch (flv_codecid) { switch (flv_codecid) {
case FLV_CODECID_H263: case FLV_CODECID_H263:
par->codec_id = AV_CODEC_ID_FLV1; par->codec_id = AV_CODEC_ID_FLV1;
...@@ -319,20 +321,28 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, ...@@ -319,20 +321,28 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream,
else else
avio_skip(s->pb, 1); avio_skip(s->pb, 1);
} }
return 1; // 1 byte body size adjustment for flv_read_packet() ret = 1; // 1 byte body size adjustment for flv_read_packet()
break;
case FLV_CODECID_H264: case FLV_CODECID_H264:
par->codec_id = AV_CODEC_ID_H264; par->codec_id = AV_CODEC_ID_H264;
vstream->need_parsing = AVSTREAM_PARSE_HEADERS; vstream->need_parsing = AVSTREAM_PARSE_HEADERS;
return 3; // not 4, reading packet type will consume one byte ret = 3; // not 4, reading packet type will consume one byte
break;
case FLV_CODECID_MPEG4: case FLV_CODECID_MPEG4:
par->codec_id = AV_CODEC_ID_MPEG4; par->codec_id = AV_CODEC_ID_MPEG4;
return 3; ret = 3;
break;
default: default:
avpriv_request_sample(s, "Video codec (%x)", flv_codecid); avpriv_request_sample(s, "Video codec (%x)", flv_codecid);
par->codec_tag = flv_codecid; par->codec_tag = flv_codecid;
} }
return 0; if (!vstream->internal->need_context_update && par->codec_id != old_codec_id) {
avpriv_request_sample(s, "Changing the codec id midstream");
return AVERROR_PATCHWELCOME;
}
return ret;
} }
static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize) static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
...@@ -547,7 +557,9 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, ...@@ -547,7 +557,9 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
st->codecpar->codec_id = AV_CODEC_ID_TEXT; st->codecpar->codec_id = AV_CODEC_ID_TEXT;
} else if (flv->trust_metadata) { } else if (flv->trust_metadata) {
if (!strcmp(key, "videocodecid") && vpar) { if (!strcmp(key, "videocodecid") && vpar) {
flv_set_video_codec(s, vstream, num_val, 0); int ret = flv_set_video_codec(s, vstream, num_val, 0);
if (ret < 0)
return ret;
} else if (!strcmp(key, "audiocodecid") && apar) { } else if (!strcmp(key, "audiocodecid") && apar) {
int id = ((int)num_val) << FLV_AUDIO_CODECID_OFFSET; int id = ((int)num_val) << FLV_AUDIO_CODECID_OFFSET;
flv_set_audio_codec(s, astream, apar, id); flv_set_audio_codec(s, astream, apar, id);
...@@ -1098,7 +1110,10 @@ retry_duration: ...@@ -1098,7 +1110,10 @@ retry_duration:
avcodec_parameters_free(&par); avcodec_parameters_free(&par);
} }
} else if (stream_type == FLV_STREAM_TYPE_VIDEO) { } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
size -= flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK, 1); int ret = flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK, 1);
if (ret < 0)
return ret;
size -= ret;
} else if (stream_type == FLV_STREAM_TYPE_DATA) { } else if (stream_type == FLV_STREAM_TYPE_DATA) {
st->codecpar->codec_id = AV_CODEC_ID_TEXT; st->codecpar->codec_id = AV_CODEC_ID_TEXT;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment