[vlc-devel] [RFC] Don't trust the PCR by default

Denis Charmet typx at dinauz.org
Sun Mar 16 19:10:55 CET 2014


The TS demux is PCR master but broken streams may have invalid PCR which stops the playback or at least the playback of some tracks.
Those file can be played with --demux=avformat since it uses the minimum dts off all the tracks as PCR.

The following patch implements the same thing.

Any idea/comments on this PoC?

Regards,
---
 modules/demux/ts.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/modules/demux/ts.c b/modules/demux/ts.c
index 093618e..04aa8d1 100644
--- a/modules/demux/ts.c
+++ b/modules/demux/ts.c
@@ -140,7 +140,7 @@ vlc_module_begin ()
     set_subcategory( SUBCAT_INPUT_DEMUX )
 
     add_string( "ts-extra-pmt", NULL, PMT_TEXT, PMT_LONGTEXT, true )
-    add_bool( "ts-trust-pcr", true, PCR_TEXT, PCR_LONGTEXT, true )
+    add_bool( "ts-trust-pcr", false, PCR_TEXT, PCR_LONGTEXT, true )
         change_safe()
     add_bool( "ts-es-id-pid", true, PID_TEXT, PID_LONGTEXT, true )
         change_safe()
@@ -272,6 +272,8 @@ typedef struct
     ts_es_t     **extra_es;
     int         i_extra_es;
 
+    mtime_t     i_last_dts;
+
 } ts_pid_t;
 
 struct demux_sys_t
@@ -374,6 +376,7 @@ static int UserPmt( demux_t *p_demux, const char * );
 
 static int  SetPIDFilter( demux_t *, int i_pid, bool b_selected );
 static void SetPrgFilter( demux_t *, int i_prg, bool b_selected );
+static mtime_t AdjustPCRWrapAround( demux_t *p_demux, mtime_t i_pcr );
 
 #define TS_PACKET_SIZE_188 188
 #define TS_PACKET_SIZE_192 192
@@ -1388,6 +1391,7 @@ static void PIDInit( ts_pid_t *pid, bool b_psi, ts_psi_t *p_owner )
     pid->b_scrambled = false;
     pid->p_owner    = p_owner;
     pid->i_owner_number = 0;
+    pid->i_last_dts = VLC_TS_INVALID;
 
     TAB_INIT( pid->i_extra_es, pid->extra_es );
 
@@ -1723,9 +1727,24 @@ static void ParsePES( demux_t *p_demux, ts_pid_t *pid, block_t *p_pes )
                          block_Duplicate( p_block ) );
         }
 
-        if (!p_sys->b_trust_pcr)
-            es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts);
+        pid->i_last_dts = i_dts;
+        if( !p_sys->b_trust_pcr )
+        {
+            mtime_t i_pcr = i_dts;
+            for( int i = 2 ; i < 8192 ; i++ )
+            {
+               ts_pid_t *p_pid = &p_sys->pid[i];
+               if( pid->b_valid && pid->p_owner == p_pid->p_owner &&
+                   pid->i_owner_number == p_pid->i_owner_number &&
+                   i_pcr > p_pid->i_last_dts )
+               {
+                   i_pcr = p_pid->i_last_dts;
+               }
+            }
+            es_out_Control( p_demux->out, ES_OUT_SET_GROUP_PCR,
+                      (int) pid->i_owner_number, (int64_t) i_pcr );
 
+        }
         es_out_Send( p_demux->out, pid->es->id, p_block );
     }
     else
-- 
1.9.rc1




More information about the vlc-devel mailing list