[vlc-commits] codec: faad: always drop padding byte (fix #6601)

Francois Cartegnie git at videolan.org
Wed Feb 22 16:37:47 CET 2017


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Feb 22 16:34:49 2017 +0100| [077ede686dae270e358fdd6fdbe0bfcb77d9f99e] | committer: Francois Cartegnie

codec: faad: always drop padding byte (fix #6601)

Causes out of sync, frame dropping.

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

 modules/codec/faad.c | 53 +++++++++++++++++++++++++---------------------------
 1 file changed, 25 insertions(+), 28 deletions(-)

diff --git a/modules/codec/faad.c b/modules/codec/faad.c
index 3443543..6111475 100644
--- a/modules/codec/faad.c
+++ b/modules/codec/faad.c
@@ -75,7 +75,7 @@ struct decoder_sys_t
 
     /* temporary buffer */
     uint8_t *p_buffer;
-    int     i_buffer;
+    size_t  i_buffer;
     size_t  i_buffer_size;
 
     /* Channel positions of the current stream (for re-ordering) */
@@ -211,6 +211,27 @@ static void Flush( decoder_t *p_dec )
 }
 
 /*****************************************************************************
+ * FlushBuffer:
+ *****************************************************************************/
+static void FlushBuffer( decoder_sys_t *p_sys, size_t i_used )
+{
+    if( i_used > p_sys->i_buffer )
+    {
+        /* Drop padding */
+        if(p_sys->p_buffer[i_used] == 0x00)
+            i_used++;
+
+        p_sys->i_buffer -= i_used;
+        if( p_sys->i_buffer > 0 )
+        {
+            memmove( p_sys->p_buffer, &p_sys->p_buffer[i_used],
+                     p_sys->i_buffer );
+        }
+    }
+    else p_sys->i_buffer = 0;
+}
+
+/*****************************************************************************
  * DecodeBlock:
  *****************************************************************************/
 static int DecodeBlock( decoder_t *p_dec, block_t *p_block )
@@ -390,14 +411,7 @@ static int DecodeBlock( decoder_t *p_dec, block_t *p_block )
         if( frame.channels <= 0 || frame.channels > 8 || frame.channels == 7 )
         {
             msg_Warn( p_dec, "invalid channels count: %i", frame.channels );
-
-            /* Flush the buffer */
-            p_sys->i_buffer -= frame.bytesconsumed;
-            if( p_sys->i_buffer > 0 )
-            {
-                memmove( p_sys->p_buffer,&p_sys->p_buffer[frame.bytesconsumed],
-                         p_sys->i_buffer );
-            }
+            FlushBuffer( p_sys, frame.bytesconsumed );
             block_Release( p_block );
             return VLCDEC_SUCCESS;
         }
@@ -405,19 +419,7 @@ static int DecodeBlock( decoder_t *p_dec, block_t *p_block )
         if( frame.samples <= 0 )
         {
             msg_Warn( p_dec, "decoded zero sample" );
-
-            /* Flush the buffer */
-            p_sys->i_buffer -= frame.bytesconsumed;
-            if( p_sys->i_buffer > 1 )
-            {
-                memmove( p_sys->p_buffer,&p_sys->p_buffer[frame.bytesconsumed],
-                         p_sys->i_buffer );
-            }
-            else
-            {
-                /* Drop byte of padding */
-                p_sys->i_buffer = 0;
-            }
+            FlushBuffer( p_sys, frame.bytesconsumed );
             block_Release( p_block );
             return VLCDEC_SUCCESS;
         }
@@ -509,12 +511,7 @@ static int DecodeBlock( decoder_t *p_dec, block_t *p_block )
                       frame.samples / nbChannels, nbChannels,
                       p_sys->pi_channel_positions );
 
-        p_sys->i_buffer -= frame.bytesconsumed;
-        if( p_sys->i_buffer > 0 )
-        {
-            memmove( p_sys->p_buffer, &p_sys->p_buffer[frame.bytesconsumed],
-                     p_sys->i_buffer );
-        }
+        FlushBuffer( p_sys, frame.bytesconsumed );
 
         block_Release( p_block );
         decoder_QueueAudio( p_dec, p_out );



More information about the vlc-commits mailing list