[vlc-commits] Faad: Reinitialize decoder when we got Unexpected channel configuration change.

Naohiro KORIYAMA git at videolan.org
Tue Dec 13 22:20:26 CET 2011


vlc | branch: master | Naohiro KORIYAMA <nkoriyama at gmail.com> | Tue Dec 13 23:44:43 2011 +0900| [d800af88bccc194075ef6af7cc51fb5f7f4f326e] | committer: Jean-Baptiste Kempf

Faad: Reinitialize decoder when we got Unexpected channel configuration change.

Very classic in ISDB streams

Closes #3714 #5448

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/codec/faad.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/modules/codec/faad.c b/modules/codec/faad.c
index 6d1c927..a9218f9 100644
--- a/modules/codec/faad.c
+++ b/modules/codec/faad.c
@@ -325,6 +325,47 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         {
             msg_Warn( p_dec, "%s", faacDecGetErrorMessage( frame.error ) );
 
+            if( frame.error == 21 )
+            {
+                /*
+                 * Once an "Unexpected channel configuration change" error
+                 * occurs, it will occurs afterwards, and we got no sound.
+                 * Reinitialization of the decoder is required.
+                 */
+                unsigned long i_rate;
+                unsigned char i_channels;
+                faacDecHandle *hfaad;
+                faacDecConfiguration *cfg,*oldcfg;
+
+                oldcfg = faacDecGetCurrentConfiguration( p_sys->hfaad );
+                hfaad = faacDecOpen();
+                cfg = faacDecGetCurrentConfiguration( hfaad );
+                if( oldcfg->defSampleRate )
+                    cfg->defSampleRate = oldcfg->defSampleRate;
+                cfg->defObjectType = oldcfg->defObjectType;
+                cfg->outputFormat = oldcfg->outputFormat;
+                faacDecSetConfiguration( hfaad, cfg );
+
+                if( faacDecInit( hfaad, p_sys->p_buffer, p_sys->i_buffer,
+                                &i_rate,&i_channels ) < 0 )
+                {
+                    /* reinitialization failed */
+                    faacDecClose( hfaad );
+                    faacDecSetConfiguration( p_sys->hfaad, oldcfg );
+                }
+                else
+                {
+                    faacDecClose( p_sys->hfaad );
+                    p_sys->hfaad = hfaad;
+                    p_dec->fmt_out.audio.i_rate = i_rate;
+                    p_dec->fmt_out.audio.i_channels = i_channels;
+                    p_dec->fmt_out.audio.i_physical_channels
+                        = p_dec->fmt_out.audio.i_original_channels
+                        = pi_channels_guessed[i_channels];
+                    date_Init( &p_sys->date, i_rate, 1 );
+                }
+            }
+
             /* Flush the buffer */
             p_sys->i_buffer = 0;
             block_Release( p_block );



More information about the vlc-commits mailing list