From 0321d683b4b970fd1025f8613c6a0ce9fcc98716 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Tue, 3 May 2011 16:52:57 +0300 Subject: ad_ffmpeg: return failure from init() if initial decode fails The init() method in ad_ffmpeg tries to decode some audio data after opening the libavcodec decoder; however the method returned success even if this part failed. Change it to return failure instead, indicating that the codec could not be successfully opened. This improves behavior at least with some AAC files, for which the libavcodec decoder can be successfully initialized but decoding packets always fails. Before the audio would be decoded with libavcodec, producing only a constant stream of errors; after this commit audio decoder initialization falls back to FAAD (if available) which works for these samples. --- libmpcodecs/ad_ffmpeg.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'libmpcodecs') diff --git a/libmpcodecs/ad_ffmpeg.c b/libmpcodecs/ad_ffmpeg.c index 8f56e71b5d..b4ecd628c4 100644 --- a/libmpcodecs/ad_ffmpeg.c +++ b/libmpcodecs/ad_ffmpeg.c @@ -98,8 +98,6 @@ static int setup_format(sh_audio_t *sh_audio, const AVCodecContext *lavc_context static int init(sh_audio_t *sh_audio) { struct MPOpts *opts = sh_audio->opts; - int tries = 0; - int x; AVCodecContext *lavc_context; AVCodec *lavc_codec; @@ -168,10 +166,19 @@ static int init(sh_audio_t *sh_audio) } // Decode at least 1 byte: (to get header filled) - do { - x=decode_audio(sh_audio,sh_audio->a_buffer,1,sh_audio->a_buffer_size); - } while (x <= 0 && tries++ < 5); - if(x>0) sh_audio->a_buffer_len=x; + for (int tries = 0;;) { + int x = decode_audio(sh_audio, sh_audio->a_buffer, 1, + sh_audio->a_buffer_size); + if (x > 0) { + sh_audio->a_buffer_len = x; + break; + } + if (++tries >= 5) { + mp_msg(MSGT_DECAUDIO, MSGL_ERR, + "ad_ffmpeg: initial decode failed\n"); + return 0; + } + } sh_audio->i_bps=lavc_context->bit_rate/8; if (sh_audio->wf && sh_audio->wf->nAvgBytesPerSec) -- cgit v1.2.3