[vlc-commits] avcodec/audio: fix inconsistent sample rate

Thomas Guillem git at videolan.org
Thu Dec 22 17:30:07 CET 2016


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Dec 22 17:24:46 2016 +0100| [e49b4cafd6793003bace8e11215b432c5e745eb5] | committer: Thomas Guillem

avcodec/audio: fix inconsistent sample rate

The sample rate was only initialized during opening because the
(fmt_out.audio.i_rate != ctx->sample_rate) check was always false after the
SetupOutputFormat() call. To fix this issue, move SetupOutputFormat() after a
successfull call to avcodec_receive_frame() and after the date_Init() check.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e49b4cafd6793003bace8e11215b432c5e745eb5
---

 modules/codec/avcodec/audio.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index 251ed36..35cd258 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -265,10 +265,10 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
     SetupOutputFormat( p_dec, false );
 
     date_Set( &p_sys->end_date, VLC_TS_INVALID );
+    if( !p_dec->fmt_out.audio.i_rate )
+        p_dec->fmt_out.audio.i_rate = p_dec->fmt_in.audio.i_rate;
     if( p_dec->fmt_out.audio.i_rate )
         date_Init( &p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1 );
-    else if( p_dec->fmt_in.audio.i_rate )
-        date_Init( &p_sys->end_date, p_dec->fmt_in.audio.i_rate, 1 );
 
     p_dec->pf_decode_audio = DecodeAudio;
     p_dec->pf_flush        = Flush;
@@ -393,11 +393,6 @@ static block_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
 
                 block_Release( p_block );
                 *pp_block = p_block = NULL;
-
-                /* FIXME: Should those init be really done after block and not frame ? */
-                SetupOutputFormat( p_dec, true );
-                if( decoder_UpdateAudioFormat( p_dec ) )
-                    goto drop;
             }
             else if ( ret != AVERROR(EAGAIN) ) /* Errors other than buffer full */
             {
@@ -424,6 +419,10 @@ static block_t *DecodeAudio( decoder_t *p_dec, block_t **pp_block )
                 date_Init( &p_sys->end_date, ctx->sample_rate, 1 );
             }
 
+            SetupOutputFormat( p_dec, true );
+            if( decoder_UpdateAudioFormat( p_dec ) )
+                goto drop;
+
             block_t *p_converted = ConvertAVFrame( p_dec, frame ); /* Consumes frame */
             if( p_converted )
             {



More information about the vlc-commits mailing list