[vlc-devel] [PATCH] packetizer: a52: replace i_pts with bytestream pts dedup

Francois Cartegnie fcvlcdev at free.fr
Wed Nov 15 11:12:23 CET 2017


clears assertion

solves remainder error on interpolation
3125696723 32000
3125728723 32000
3125760723 32000
3125792712 32000 <
3125824712 32000 <
3125856712 32000 <
3125888712 32000 <
3125920712 32000 <
3125952723 32000
3125984723 32000
---
 modules/packetizer/a52.c | 71 +++++++++++++++++++++++++-----------------------
 1 file changed, 37 insertions(+), 34 deletions(-)

diff --git a/modules/packetizer/a52.c b/modules/packetizer/a52.c
index 59d6aa9701..ebb5a02725 100644
--- a/modules/packetizer/a52.c
+++ b/modules/packetizer/a52.c
@@ -66,8 +66,7 @@ struct decoder_sys_t
      * Common properties
      */
     date_t  end_date;
-
-    mtime_t i_pts;
+    mtime_t i_prev_bytestream_pts;
     bool    b_discontuinity;
 
     vlc_a52_header_t frame;
@@ -80,6 +79,7 @@ static void PacketizeFlush( decoder_t *p_dec )
     p_sys->b_discontuinity = true;
     date_Set( &p_sys->end_date, VLC_TS_INVALID );
     p_sys->i_state = STATE_NOSYNC;
+    p_sys->i_prev_bytestream_pts = VLC_TS_INVALID;
     block_BytestreamEmpty( &p_sys->bytestream );
 }
 
@@ -87,21 +87,29 @@ static block_t *GetOutBuffer( decoder_t *p_dec )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
 
-    if( date_Get( &p_sys->end_date ) == VLC_TS_INVALID
-     || p_dec->fmt_out.audio.i_rate != p_sys->frame.i_rate )
-    {
-        if( p_sys->i_pts == VLC_TS_INVALID )
-            return NULL;
+    assert( p_sys->frame.i_rate > 0 );
+
+    block_t *p_block = block_Alloc( p_sys->frame.i_size );
+    if( p_block == NULL )
+        return NULL;
 
+    if( p_dec->fmt_out.audio.i_rate != p_sys->frame.i_rate )
+    {
         msg_Dbg( p_dec, "A/52 channels:%d samplerate:%d bitrate:%d",
                  p_sys->frame.i_channels, p_sys->frame.i_rate, p_sys->frame.i_bitrate );
+        if( p_sys->end_date.i_divider_num )
+            date_Change( &p_sys->end_date, p_sys->frame.i_rate, 1 );
+        else
+            date_Init( &p_sys->end_date, p_sys->frame.i_rate, 1 );
+    }
 
-        assert( p_sys->frame.i_rate > 0 );
-        date_Init( &p_sys->end_date, p_sys->frame.i_rate, 1 );
-        date_Set( &p_sys->end_date, p_sys->i_pts );
+    if( p_sys->bytestream.p_block->i_pts != date_Get( &p_sys->end_date ) &&
+        p_sys->bytestream.p_block->i_pts != VLC_TS_INVALID )
+    {
+        date_Set( &p_sys->end_date, p_sys->bytestream.p_block->i_pts );
+        p_sys->bytestream.p_block->i_pts = VLC_TS_INVALID;
     }
 
-    assert( p_sys->i_pts > VLC_TS_INVALID );
     p_dec->fmt_out.audio.i_rate     = p_sys->frame.i_rate;
     p_dec->fmt_out.audio.i_channels = p_sys->frame.i_channels;
     if( p_dec->fmt_out.audio.i_bytes_per_frame < p_sys->frame.i_size )
@@ -113,14 +121,12 @@ static block_t *GetOutBuffer( decoder_t *p_dec )
 
     p_dec->fmt_out.i_bitrate = p_sys->frame.i_bitrate;
 
-    block_t *p_block = block_Alloc( p_sys->frame.i_size );
-    if( p_block == NULL )
-        return NULL;
-
     p_block->i_nb_samples = p_sys->frame.i_samples;
     p_block->i_pts = p_block->i_dts = date_Get( &p_sys->end_date );
-    p_block->i_length =
-        date_Increment( &p_sys->end_date, p_block->i_nb_samples ) - p_block->i_pts;
+    if( p_block->i_pts != VLC_TS_INVALID )
+        p_block->i_length = date_Increment( &p_sys->end_date,
+                                            p_block->i_nb_samples ) - p_block->i_pts;
+
     return p_block;
 }
 
@@ -150,11 +156,13 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
             }
         }
 
-        if( !date_Get( &p_sys->end_date ) && p_block->i_pts <= VLC_TS_INVALID)
+        /* Make sure we don't reuse the same pts twice */
+        if( 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( p_block->i_pts == p_sys->i_prev_bytestream_pts )
+                p_block->i_pts = VLC_TS_INVALID;
+            else
+                p_sys->i_prev_bytestream_pts = p_block->i_pts;
         }
 
         block_BytestreamPush( &p_sys->bytestream, p_block );
@@ -185,13 +193,6 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
             /* fallthrough */
 
         case STATE_SYNC:
-            /* New frame, set the Presentation Time Stamp */
-            p_sys->i_pts = p_sys->bytestream.p_block->i_pts;
-            if( p_sys->i_pts > VLC_TS_INVALID &&
-                p_sys->i_pts != date_Get( &p_sys->end_date ) )
-            {
-                date_Set( &p_sys->end_date, p_sys->i_pts );
-            }
             p_sys->i_state = STATE_HEADER;
             /* fallthrough */
 
@@ -281,9 +282,13 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
             block_GetBytes( &p_sys->bytestream, p_out_buffer->p_buffer,
                             __MIN( p_sys->frame.i_size, p_out_buffer->i_buffer ) );
 
-            /* 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;
+            p_sys->i_state = STATE_NOSYNC;
+
+            if( p_out_buffer->i_dts == VLC_TS_INVALID )
+            {
+                block_Release( p_out_buffer );
+                return NULL;
+            }
 
             if( p_sys->b_discontuinity )
             {
@@ -295,8 +300,6 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
             if( pp_block )
                 *pp_block = block_BytestreamPop( &p_sys->bytestream );
 
-            p_sys->i_state = STATE_NOSYNC;
-
             return p_out_buffer;
         }
     }
@@ -334,8 +337,8 @@ static int Open( vlc_object_t *p_this )
     /* Misc init */
     p_sys->i_state = STATE_NOSYNC;
     date_Set( &p_sys->end_date, VLC_TS_INVALID );
-    p_sys->i_pts = VLC_TS_INVALID;
     p_sys->b_discontuinity = false;
+    p_sys->i_prev_bytestream_pts = VLC_TS_INVALID;
     memset(&p_sys->frame, 0, sizeof(vlc_a52_header_t));
 
     block_BytestreamInit( &p_sys->bytestream );
-- 
2.13.6



More information about the vlc-devel mailing list