[vlc-commits] mpeg_audio packetizer: flush remaining data

Rafaël Carré git at videolan.org
Tue Nov 12 11:55:21 CET 2013


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Tue Nov 12 11:51:15 2013 +0100| [6f6bd492c52c263d1f1d08ccce89cd96a6c9033f] | committer: Rafaël Carré

mpeg_audio packetizer: flush remaining data

vlc 1.mp3 --sout 2.mp3 && vlc 2.mp3 --sout 3.mp3
will now give identical 2.mp3 and 3.mp3

Refs: #3178

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

 modules/codec/mpeg_audio.c |   49 ++++++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/modules/codec/mpeg_audio.c b/modules/codec/mpeg_audio.c
index cced5ad..8a1daba 100644
--- a/modules/codec/mpeg_audio.c
+++ b/modules/codec/mpeg_audio.c
@@ -190,32 +190,33 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     uint8_t *p_buf;
     block_t *p_out_buffer;
 
-    if( !pp_block || !*pp_block ) return NULL;
+    block_t *p_block = pp_block ? *pp_block : NULL;
 
-    block_t *p_block = *pp_block;
-
-    if( p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
-    {
-        if( p_block->i_flags&BLOCK_FLAG_CORRUPTED )
+    if (p_block) {
+        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( p_block );
+            p_sys->b_discontinuity = true;
+            return NULL;
         }
-        date_Set( &p_sys->end_date, 0 );
-        block_Release( p_block );
-        p_sys->b_discontinuity = true;
-        return NULL;
-    }
 
-    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;
-    }
+        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 );
+        block_BytestreamPush( &p_sys->bytestream, p_block );
+    } else
+        p_sys->i_state = STATE_SEND_DATA; /* return all the data we have left */
 
     while( 1 )
     {
@@ -470,7 +471,11 @@ static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 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 );
+            p_block = block_BytestreamPop( &p_sys->bytestream );
+            if (pp_block)
+                *pp_block = p_block;
+            else if (p_block)
+                block_Release(p_block);
 
             return p_out_buffer;
         }



More information about the vlc-commits mailing list