From: "Ronald S. Bultje" <[email protected]> Hej,
On Fri, Oct 28, 2011 at 08:36:04AM -0700, Ronald S. Bultje wrote: > > Let me know if the rest is OK and I'll commit. I still prefer a local variable. Trying to pack every function argument in creates monsters like MpegEncContext. Adding the number of decoded frames as function argument for has_decode_delay_been_guessed makes it imho easier to follow. It's visible from the call site that the function uses that specific value. I would have to look at the function if takes only a struct as argument. It is easier as long as it is a small number (at most 2 or maybe 3). Especially in this case were it is just used to simplify a complex if condition. Otoh, I don't care more than preparing this patch, push which you like more. Janne ---8<--- This fixes false positives of has_codec_delay_been_guessed() for streams where not every input picture generates an output picture, such as interlaced H264. Signed-off-by: Janne Grunau <[email protected]> --- libavformat/utils.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 637d615..354b268 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2108,17 +2108,17 @@ static int has_codec_parameters(AVCodecContext *avctx) return avctx->codec_id != CODEC_ID_NONE && val != 0; } -static int has_decode_delay_been_guessed(AVStream *st) +static int has_decode_delay_been_guessed(AVStream *st, int nb_decoded_frames) { return st->codec->codec_id != CODEC_ID_H264 || - st->codec_info_nb_frames >= 6 + st->codec->has_b_frames; + nb_decoded_frames >= 6; } static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **options) { int16_t *samples; AVCodec *codec; - int got_picture, data_size, ret=0; + int got_picture, data_size, ret=0, nb_decoded_frames=0; AVFrame picture; if(!st->codec->codec){ @@ -2130,13 +2130,16 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **option return ret; } - if(!has_codec_parameters(st->codec) || !has_decode_delay_been_guessed(st) || + if(!has_codec_parameters(st->codec) || + !has_decode_delay_been_guessed(st, nb_decoded_frames) || (!st->codec_info_nb_frames && st->codec->codec->capabilities & CODEC_CAP_CHANNEL_CONF)) { switch(st->codec->codec_type) { case AVMEDIA_TYPE_VIDEO: avcodec_get_frame_defaults(&picture); ret = avcodec_decode_video2(st->codec, &picture, &got_picture, avpkt); + if (got_picture) + nb_decoded_frames++; break; case AVMEDIA_TYPE_AUDIO: data_size = FFMAX(avpkt->size, AVCODEC_MAX_AUDIO_FRAME_SIZE); -- 1.7.7.1 _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
