]> git.sesse.net Git - vlc/commitdiff
TS mux: fix ebcc69cfb1569a0fcedf10498606b231ae6fcb7c
authorRafaël Carré <funman@videolan.org>
Wed, 10 Sep 2014 15:15:45 +0000 (17:15 +0200)
committerRafaël Carré <funman@videolan.org>
Wed, 10 Sep 2014 15:15:45 +0000 (17:15 +0200)
Only modify bitstream (PCR & PES), but not VLC core timestamps

modules/mux/mpeg/pes.c
modules/mux/mpeg/pes.h
modules/mux/mpeg/ps.c
modules/mux/mpeg/ts.c

index 5f1bd0b1315310a98efa374b3773b7686d654cab..634f6d086cccae0c2413d2fa3114508bc9835432 100644 (file)
@@ -319,11 +319,10 @@ static inline int PESHeader( uint8_t *p_hdr, mtime_t i_pts, mtime_t i_dts,
 void EStoPES ( block_t **pp_pes,
                    es_format_t *p_fmt, int i_stream_id,
                    int b_mpeg2, int b_data_alignment, int i_header_size,
-                   int i_max_pes_size )
+                   int i_max_pes_size, mtime_t ts_offset )
 {
     block_t *p_es = *pp_pes;
     block_t *p_pes = NULL;
-    mtime_t i_pts, i_dts, i_length;
 
     uint8_t *p_data;
     int     i_size;
@@ -383,8 +382,12 @@ void EStoPES ( block_t **pp_pes,
 
     }
 
-    i_pts = p_es->i_pts <= 0 ? 0 : p_es->i_pts * 9 / 100; // 90000 units clock
-    i_dts = p_es->i_dts <= 0 ? 0 : p_es->i_dts * 9 / 100; // 90000 units clock
+    mtime_t i_dts = 0;
+    mtime_t i_pts = 0;
+    if (p_es->i_pts > VLC_TS_INVALID)
+        i_pts = (p_es->i_pts - ts_offset) * 9 / 100;
+    if (p_es->i_dts > VLC_TS_INVALID)
+        i_dts = (p_es->i_dts - ts_offset) * 9 / 100;
 
     i_size = p_es->i_buffer;
     p_data = p_es->p_buffer;
@@ -434,7 +437,7 @@ void EStoPES ( block_t **pp_pes,
 
     /* Now redate all pes */
     i_dts    = p_pes->i_dts;
-    i_length = p_pes->i_length / i_pes_count;
+    mtime_t i_length = p_pes->i_length / i_pes_count;
     while( p_pes )
     {
         p_pes->i_dts = i_dts;
index 17dda532af9f57c58f75c8f6c96f3b467488048a..71eb699ee3f8e64462ba73f0c13006457c06bb88 100644 (file)
@@ -38,4 +38,4 @@
 void EStoPES ( block_t **pp_pes,
                    es_format_t *p_fmt, int i_stream_id,
                    int b_mpeg2, int b_data_alignment, int i_header_size,
-                   int i_max_pes_size );
+                   int i_max_pes_size, mtime_t ts_offset );
index 599dfb1489f4d6227cf32d3510ca97a3d7ac37e1..6dd65c93095ce59b733434634d0cf0dbe4e7afee 100644 (file)
@@ -514,7 +514,7 @@ static int Mux( sout_mux_t *p_mux )
         /* Get and mux a packet */
         p_data = block_FifoGet( p_input->p_fifo );
         EStoPES ( &p_data, p_input->p_fmt, p_stream->i_stream_id,
-                       p_sys->b_mpeg2, 0, 0, p_sys->i_pes_max_size );
+                       p_sys->b_mpeg2, 0, 0, p_sys->i_pes_max_size, 0 );
 
         block_ChainAppend( &p_ps, p_data );
 
index 8d440ecda46305f8fd53756c71bcd28e404656cc..3d7badb299a2c119c9482b7d890391cad91a88dd 100644 (file)
@@ -1274,7 +1274,7 @@ static bool MuxStreams(sout_mux_t *p_mux )
                 /* Don't mux the SPU yet if it is too early */
                 block_t *p_spu = block_FifoShow( p_input->p_fifo );
 
-                int64_t i_spu_delay = p_spu->i_dts - p_sys->first_dts - p_pcr_stream->i_pes_dts;
+                int64_t i_spu_delay = p_spu->i_dts - p_pcr_stream->i_pes_dts;
                 if( ( i_spu_delay > i_shaping_delay ) &&
                     ( i_spu_delay < 100 * CLOCK_FREQ ) )
                     continue;
@@ -1320,9 +1320,6 @@ static bool MuxStreams(sout_mux_t *p_mux )
         if (p_sys->first_dts == 0)
             p_sys->first_dts = p_data->i_dts;
 
-        p_data->i_dts -= p_sys->first_dts;
-        p_data->i_pts -= p_sys->first_dts;
-
         if( ( p_pcr_stream->i_pes_dts > 0 &&
               p_data->i_dts - 10 * CLOCK_FREQ > p_pcr_stream->i_pes_dts +
               p_pcr_stream->i_pes_length ) ||
@@ -1384,7 +1381,7 @@ static bool MuxStreams(sout_mux_t *p_mux )
                 p_spu->p_buffer[2] = ' ';
 
                 EStoPES( &p_spu, p_input->p_fmt,
-                             p_stream->i_stream_id, 1, 0, 0, 0 );
+                             p_stream->i_stream_id, 1, 0, 0, 0, p_sys->first_dts );
                 p_data->p_next = p_spu;
             }
             break;
@@ -1431,7 +1428,7 @@ static bool MuxStreams(sout_mux_t *p_mux )
 
         EStoPES ( &p_data, p_input->p_fmt, p_stream->i_stream_id,
                        1, b_data_alignment, i_header_size,
-                       i_max_pes_size );
+                       i_max_pes_size, p_sys->first_dts );
 
         BufferChainAppend( &p_stream->chain_pes, p_data );
 
@@ -1799,7 +1796,7 @@ static void TSDate( sout_mux_t *p_mux, sout_buffer_chain_t *p_chain_ts,
         if( p_ts->i_flags & BLOCK_FLAG_CLOCK )
         {
             /* msg_Dbg( p_mux, "pcr=%lld ms", p_ts->i_dts / 1000 ); */
-            TSSetPCR( p_ts, p_ts->i_dts - p_sys->i_dts_delay );
+            TSSetPCR( p_ts, p_ts->i_dts - p_sys->i_dts_delay - p_sys->first_dts );
         }
         if( p_ts->i_flags & BLOCK_FLAG_SCRAMBLED )
         {