[vlc-commits] packetizer_helper: implement draining

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 10:36:22 2016 +0200| [ab77df12256e3b5149d2584cf902df024a7852ef] | committer: Francois Cartegnie

packetizer_helper: implement draining

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

 modules/packetizer/packetizer_helper.h | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/modules/packetizer/packetizer_helper.h b/modules/packetizer/packetizer_helper.h
index 74ded19..00e98d8 100644
--- a/modules/packetizer/packetizer_helper.h
+++ b/modules/packetizer/packetizer_helper.h
@@ -45,7 +45,6 @@ typedef struct
     int i_state;
     block_bytestream_t bytestream;
     size_t i_offset;
-    bool   b_flushing;
 
     int i_startcode;
     const uint8_t *p_startcode;
@@ -76,7 +75,6 @@ static inline void packetizer_Init( packetizer_t *p_pack,
     p_pack->i_state = STATE_NOSYNC;
     block_BytestreamInit( &p_pack->bytestream );
     p_pack->i_offset = 0;
-    p_pack->b_flushing = false;
 
     p_pack->i_au_prepend = i_au_prepend;
     p_pack->p_au_prepend = p_au_prepend;
@@ -106,24 +104,31 @@ static inline void packetizer_Flush( packetizer_t *p_pack )
 
 static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_block )
 {
-    if( !pp_block || !*pp_block )
-        return NULL;
+    block_t *p_block = ( pp_block ) ? *pp_block : NULL;
 
-    if( unlikely( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) )
+    if( p_block == NULL && p_pack->bytestream.p_block == NULL )
+        return NULL; /* nothing to do */
+
+    if( p_block && unlikely( p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) )
     {
-        const bool b_broken = ( (*pp_block)->i_flags&BLOCK_FLAG_CORRUPTED ) != 0;
+        block_t *p_drained = packetizer_Packetize( p_pack, NULL );
+        if( p_drained )
+            return p_drained;
+
+        const bool b_broken = !!( p_block->i_flags&BLOCK_FLAG_CORRUPTED );
         p_pack->i_state = STATE_NOSYNC;
         block_BytestreamEmpty( &p_pack->bytestream );
         p_pack->i_offset = 0;
         p_pack->pf_reset( p_pack->p_private, b_broken );
         if( b_broken )
         {
-            block_Release( *pp_block );
+            block_Release( p_block );
             return NULL;
         }
     }
 
-    block_BytestreamPush( &p_pack->bytestream, *pp_block );
+    if( p_block )
+        block_BytestreamPush( &p_pack->bytestream, p_block );
 
     for( ;; )
     {
@@ -157,7 +162,7 @@ static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_
                                                p_pack->p_startcode, p_pack->i_startcode,
                                                p_pack->pf_startcode_helper ) )
             {
-                if( !p_pack->b_flushing || !p_pack->bytestream.p_chain )
+                if( pp_block /* not flushing */ || !p_pack->bytestream.p_chain )
                     return NULL; /* Need more data */
 
                 /* When flusing and we don't find a startcode, suppose that
@@ -215,7 +220,8 @@ static inline block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_
             }
 
             /* So p_block doesn't get re-added several times */
-            *pp_block = block_BytestreamPop( &p_pack->bytestream );
+            if( pp_block )
+                *pp_block = block_BytestreamPop( &p_pack->bytestream );
 
             p_pack->i_state = STATE_NOSYNC;
 
@@ -233,16 +239,15 @@ static inline void packetizer_Header( packetizer_t *p_pack,
 
     memcpy( p_init->p_buffer, p_header, i_header );
 
-    p_pack->b_flushing = true;
-
     block_t *p_pic;
     while( ( p_pic = packetizer_Packetize( p_pack, &p_init ) ) )
         block_Release( p_pic ); /* Should not happen (only sequence header) */
+    while( ( p_pic = packetizer_Packetize( p_pack, NULL ) ) )
+        block_Release( p_pic );
 
     p_pack->i_state = STATE_NOSYNC;
     block_BytestreamEmpty( &p_pack->bytestream );
     p_pack->i_offset = 0;
-    p_pack->b_flushing = false;
 }
 
 #endif



More information about the vlc-commits mailing list