[vlc-commits] packetizer: a52: add draining and handle discontinuities

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


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Oct 26 14:50:49 2016 +0200| [1cecce8337e4223e3248c9767fd6dc8746aa8220] | committer: Francois Cartegnie

packetizer: a52: add draining and handle discontinuities

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

 modules/packetizer/a52.c | 49 +++++++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/modules/packetizer/a52.c b/modules/packetizer/a52.c
index 2d67ced..8d7621b 100644
--- a/modules/packetizer/a52.c
+++ b/modules/packetizer/a52.c
@@ -126,32 +126,36 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
     uint8_t p_header[VLC_A52_HEADER_SIZE];
     block_t *p_out_buffer;
 
-    if( !pp_block || !*pp_block ) return NULL;
+    block_t *p_block = pp_block ? *pp_block : NULL;
 
-    if( (*pp_block)->i_flags & (BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED) )
+    if( p_block )
     {
-        if( (*pp_block)->i_flags & BLOCK_FLAG_CORRUPTED )
+        if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY | BLOCK_FLAG_CORRUPTED) )
         {
+            /* First always drain complete blocks before discontinuity */
+            block_t *p_drain = PacketizeBlock( p_dec, NULL );
+            if(p_drain)
+                return p_drain;
+
             PacketizeFlush( p_dec );
-            block_Release( *pp_block );
-            *pp_block = NULL;
-            return NULL;
+
+            if( p_block->i_flags & BLOCK_FLAG_CORRUPTED )
+            {
+                block_Release( p_block );
+                return NULL;
+            }
         }
-        else /* BLOCK_FLAG_DISCONTINUITY */
-            date_Set( &p_sys->end_date, 0 );
 
-    }
+        if( !date_Get( &p_sys->end_date ) && p_block->i_pts <= VLC_TS_INVALID)
+        {
+            /* We've just started the stream, wait for the first PTS. */
+            block_Release( p_block );
+            return NULL;
+        }
 
-    if( !date_Get( &p_sys->end_date ) && (*pp_block)->i_pts <= VLC_TS_INVALID)
-    {
-        /* We've just started the stream, wait for the first PTS. */
-        block_Release( *pp_block );
-        *pp_block = NULL;
-        return NULL;
+        block_BytestreamPush( &p_sys->bytestream, p_block );
     }
 
-    block_BytestreamPush( &p_sys->bytestream, *pp_block );
-
     while( 1 )
     {
         switch( p_sys->i_state )
@@ -218,14 +222,16 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
             p_sys->i_state = STATE_NEXT_SYNC;
 
         case STATE_NEXT_SYNC:
-            /* TODO: If pp_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->frame.i_size, p_header, 2 )
                 != VLC_SUCCESS )
             {
+                if( p_block == NULL ) /* drain */
+                {
+                    p_sys->i_state = STATE_SEND_DATA;
+                    break;
+                }
                 /* Need more data */
                 return NULL;
             }
@@ -282,7 +288,8 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
             }
 
             /* So p_block doesn't get re-added several times */
-            *pp_block = block_BytestreamPop( &p_sys->bytestream );
+            if( pp_block )
+                *pp_block = block_BytestreamPop( &p_sys->bytestream );
 
             p_sys->i_state = STATE_NOSYNC;
 



More information about the vlc-commits mailing list