[vlc-devel] [PATCH] packetizer: a52: remove i_pts

Francois Cartegnie fcvlcdev at free.fr
Tue Nov 14 21:10:36 CET 2017


Removes the i_pts and failing assert,
and provides earlier sync in case the pts is
missing on first packet.

might introduce an audio sync delay as I can see some
delay on ts streams, but also seems without patch.
(might be a different issue)

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

diff --git a/modules/packetizer/a52.c b/modules/packetizer/a52.c
index 59d6aa9701..ba2c2f4c12 100644
--- a/modules/packetizer/a52.c
+++ b/modules/packetizer/a52.c
@@ -66,8 +66,6 @@ struct decoder_sys_t
      * Common properties
      */
     date_t  end_date;
-
-    mtime_t i_pts;
     bool    b_discontuinity;
 
     vlc_a52_header_t frame;
@@ -87,21 +85,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 );
-
-        assert( p_sys->frame.i_rate > 0 );
+        mtime_t i_prev = date_Get( &p_sys->end_date );
         date_Init( &p_sys->end_date, p_sys->frame.i_rate, 1 );
-        date_Set( &p_sys->end_date, p_sys->i_pts );
+        date_Set( &p_sys->end_date, i_prev );
+    }
+
+    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 );
+        /* Make sure we don't reuse the same pts twice */
+        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 +119,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,13 +154,6 @@ 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)
-        {
-            /* We've just started the stream, wait for the first PTS. */
-            block_Release( p_block );
-            return NULL;
-        }
-
         block_BytestreamPush( &p_sys->bytestream, p_block );
     }
 
@@ -185,13 +182,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 +271,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 +289,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,7 +326,6 @@ 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;
     memset(&p_sys->frame, 0, sizeof(vlc_a52_header_t));
 
-- 
2.13.6



More information about the vlc-devel mailing list