avcodec/mpeg4videodec: Fix nonsense warning

Since db77230894 parsing of
mpeg4-extradata lead to a "Failed to parse extradata" warning, because
ff_mpeg4_decode_picture_header returns AVERROR_INVALIDDATA in case that
no VOP was found. This patch adds a parameter to signify whether a
header (where the absence of a VOP does not raise an error) or not is
parsed. The first mode is of course used for parsing headers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Andreas Rheinhardt 2019-03-11 11:32:05 +01:00 committed by Michael Niedermayer
parent 5ab44ff20c
commit 3f086a2f66
4 changed files with 13 additions and 9 deletions

View File

@ -500,9 +500,9 @@ retry:
GetBitContext gb;
if (init_get_bits8(&gb, s->avctx->extradata, s->avctx->extradata_size) >= 0 )
ff_mpeg4_decode_picture_header(avctx->priv_data, &gb);
ff_mpeg4_decode_picture_header(avctx->priv_data, &gb, 1);
}
ret = ff_mpeg4_decode_picture_header(avctx->priv_data, &s->gb);
ret = ff_mpeg4_decode_picture_header(avctx->priv_data, &s->gb, 0);
} else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) {
ret = ff_intel_h263_decode_picture_header(s);
} else if (CONFIG_FLV_DECODER && s->h263_flv) {

View File

@ -163,7 +163,7 @@ void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n,
void ff_set_mpeg4_time(MpegEncContext *s);
int ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb);
int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, int header);
void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);
void ff_mpeg4_clean_buffers(MpegEncContext *s);
void ff_mpeg4_stuffing(PutBitContext *pbc);

View File

@ -89,13 +89,13 @@ static int mpeg4_decode_header(AVCodecParserContext *s1, AVCodecContext *avctx,
if (avctx->extradata_size && pc->first_picture) {
init_get_bits(gb, avctx->extradata, avctx->extradata_size * 8);
ret = ff_mpeg4_decode_picture_header(dec_ctx, gb);
if (ret < -1)
ret = ff_mpeg4_decode_picture_header(dec_ctx, gb, 1);
if (ret < 0)
av_log(avctx, AV_LOG_WARNING, "Failed to parse extradata\n");
}
init_get_bits(gb, buf, 8 * buf_size);
ret = ff_mpeg4_decode_picture_header(dec_ctx, gb);
ret = ff_mpeg4_decode_picture_header(dec_ctx, gb, 0);
if (s->width && (!avctx->width || !avctx->height ||
!avctx->coded_width || !avctx->coded_height)) {
ret = ff_set_dimensions(avctx, s->width, s->height);

View File

@ -3203,11 +3203,13 @@ static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
/**
* Decode MPEG-4 headers.
* @return <0 if no VOP found (or a damaged one)
*
* @param header If set the absence of a VOP is not treated as error; otherwise, it is treated as such.
* @return <0 if an error occured
* FRAME_SKIPPED if a not coded VOP is found
* 0 if a VOP is found
* 0 else
*/
int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb)
int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, int header)
{
MpegEncContext *s = &ctx->m;
unsigned startcode, v;
@ -3236,6 +3238,8 @@ int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb)
(ctx->divx_version >= 0 || ctx->xvid_build >= 0) || s->codec_tag == AV_RL32("QMP4")) {
av_log(s->avctx, AV_LOG_VERBOSE, "frame skip %d\n", gb->size_in_bits);
return FRAME_SKIPPED; // divx bug
} else if (header && get_bits_count(gb) == gb->size_in_bits) {
return 0; // ordinary return value for parsing of extradata
} else
return AVERROR_INVALIDDATA; // end of stream
}