[vlc-devel] [PATCH 2/3] mpeg_audio packetizer: output last block

Rafaël Carré rafael.carre at gmail.com
Tue Aug 2 05:17:37 CEST 2011


refs: #3178
---
 modules/codec/mpeg_audio.c |   51 +++++++++++++++++++++++++-------------------
 1 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/modules/codec/mpeg_audio.c b/modules/codec/mpeg_audio.c
index 2335c4e..bd52ee2 100644
--- a/modules/codec/mpeg_audio.c
+++ b/modules/codec/mpeg_audio.c
@@ -203,32 +203,40 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     uint32_t i_header;
     uint8_t *p_buf;
     block_t *p_out_buffer;
+    block_t *p_block = pp_block ? *pp_block : NULL;
 
-    if( !pp_block || !*pp_block ) return 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) )
         {
-            p_sys->i_state = STATE_NOSYNC;
-            block_BytestreamEmpty( &p_sys->bytestream );
+            if( p_block->i_flags&BLOCK_FLAG_CORRUPTED )
+            {
+                p_sys->i_state = STATE_NOSYNC;
+                block_BytestreamEmpty( &p_sys->bytestream );
+            }
+            date_Set( &p_sys->end_date, 0 );
+            block_Release( *pp_block );
+            p_sys->b_discontinuity = true;
+            return NULL;
         }
-        date_Set( &p_sys->end_date, 0 );
-        block_Release( *pp_block );
-        p_sys->b_discontinuity = true;
-        return NULL;
-    }
 
-    if( !date_Get( &p_sys->end_date ) && (*pp_block)->i_pts <= VLC_TS_INVALID )
+        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. */
+            msg_Dbg( p_dec, "waiting for PTS" );
+            block_Release( p_block );
+            return NULL;
+        }
+
+        block_BytestreamPush( &p_sys->bytestream, p_block );
+    }
+    else
     {
-        /* We've just started the stream, wait for the first PTS. */
-        msg_Dbg( p_dec, "waiting for PTS" );
-        block_Release( *pp_block );
-        return NULL;
+        if( p_sys->i_frame_size == -1 )
+            return NULL; // no more data
+        p_sys->i_state = STATE_SEND_DATA;
     }
 
-    block_BytestreamPush( &p_sys->bytestream, *pp_block );
-
     while( 1 )
     {
         switch( p_sys->i_state )
@@ -312,9 +320,6 @@ static void *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,
@@ -474,13 +479,15 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
             }
 
             p_sys->i_state = STATE_NOSYNC;
+            p_sys->i_frame_size = -1;
 
             /* Make sure we don't reuse the same pts twice */
             if( p_sys->i_pts == p_sys->bytestream.p_block->i_pts )
                 p_sys->i_pts = p_sys->bytestream.p_block->i_pts = VLC_TS_INVALID;
 
             /* 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 );
 
             return p_out_buffer;
         }
-- 
1.7.5.4





More information about the vlc-devel mailing list