[vlc-commits] packetizer: mpegaudio: implement draining and proper discontinuity handling

Francois Cartegnie git at videolan.org
Wed Oct 26 19:07:02 CEST 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Oct 26 12:08:56 2016 +0200| [8de506e9aa7648d722f36a41b25ccd724a4c15e1] | committer: Francois Cartegnie

packetizer: mpegaudio: implement draining and proper discontinuity handling

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

 modules/packetizer/mpegaudio.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/modules/packetizer/mpegaudio.c b/modules/packetizer/mpegaudio.c
index 1f7ad0f..685a251 100644
--- a/modules/packetizer/mpegaudio.c
+++ b/modules/packetizer/mpegaudio.c
@@ -291,16 +291,18 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     {
         if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
         {
+            /* First always drain complete blocks before discontinuity */
+            block_t *p_drain = DecodeBlock( p_dec, NULL );
+            if( p_drain )
+                return p_drain;
+
+            Flush( p_dec );
+
             if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
             {
-                Flush( p_dec );
                 block_Release( p_block );
-                *pp_block = NULL;
                 return NULL;
             }
-            else /* BLOCK_FLAG_DISCONTINUITY */
-                date_Set( &p_sys->end_date, 0 );
-            p_sys->b_discontinuity = true;
         }
 
         if( !date_Get( &p_sys->end_date ) && p_block->i_pts <= VLC_TS_INVALID )
@@ -312,10 +314,7 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
         }
 
         block_BytestreamPush( &p_sys->bytestream, p_block );
-    } else if (p_sys->i_frame_size)
-        p_sys->i_state = STATE_SEND_DATA; /* return all the data we have left */
-    else
-        return NULL;
+    }
 
     while( 1 )
     {
@@ -406,14 +405,16 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
             p_sys->i_state = STATE_NEXT_SYNC;
 
         case STATE_NEXT_SYNC:
-            /* TODO: If p_block == NULL, flush the buffer without checking the
-             * next sync word */
-
             /* Check if next expected frame contains the sync word */
             if( block_PeekOffsetBytes( &p_sys->bytestream,
                                        p_sys->i_frame_size, p_header,
                                        MAD_BUFFER_GUARD ) != VLC_SUCCESS )
             {
+                if( p_block == NULL ) /* drain */
+                {
+                    p_sys->i_state = STATE_SEND_DATA;
+                    break;
+                }
                 /* Need more data */
                 return NULL;
             }



More information about the vlc-commits mailing list