]> git.sesse.net Git - vlc/commitdiff
demux: ts: fix delayed es creation after filtering
authorFrancois Cartegnie <fcvlcdev@free.fr>
Fri, 13 Mar 2015 15:24:52 +0000 (16:24 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Sun, 15 Mar 2015 13:07:13 +0000 (14:07 +0100)
modules/demux/ts.c

index 6ef23dad88711f288a41854c2aa72d4b30c2aea6..8b251c9d4f154e8a33e662afd3641140de3e48b7 100644 (file)
@@ -507,7 +507,7 @@ static inline int PIDGet( block_t *p )
 }
 
 static bool GatherData( demux_t *p_demux, ts_pid_t *pid, block_t *p_bk );
-static void AddAndCreateES( demux_t *p_demux, ts_pid_t *pid );
+static void AddAndCreateES( demux_t *p_demux, ts_pid_t *pid, bool );
 static void ProgramSetPCR( demux_t *p_demux, ts_pmt_t *p_prg, mtime_t i_pcr );
 
 static block_t* ReadTSPacket( demux_t *p_demux );
@@ -1331,7 +1331,7 @@ static int Demux( demux_t *p_demux )
             p_sys->b_end_preparse = true;
             if( p_sys->es_creation == DELAY_ES ) /* No longer delay ES since that pid's program sends data */
             {
-                AddAndCreateES( p_demux, NULL );
+                AddAndCreateES( p_demux, p_pid, true );
             }
             b_frame = GatherData( p_demux, p_pid, p_pkt );
 
@@ -5053,36 +5053,33 @@ static void PMTParseEsIso639( demux_t *p_demux, ts_pes_es_t *p_es,
 #endif
 }
 
-static void AddAndCreateES( demux_t *p_demux, ts_pid_t *pid )
+static void AddAndCreateES( demux_t *p_demux, ts_pid_t *pid, bool b_create_delayed )
 {
     demux_sys_t  *p_sys = p_demux->p_sys;
-    bool b_create_delayed = false;
 
-    if( pid )
+    if( b_create_delayed )
+        p_sys->es_creation = CREATE_ES;
+
+    if( pid && p_sys->es_creation == CREATE_ES )
     {
-        if( SEEN(*pid) && p_sys->es_creation == DELAY_ES )
+        pid->u.p_pes->es.id = es_out_Add( p_demux->out, &pid->u.p_pes->es.fmt );
+        for( int i = 0; i < pid->u.p_pes->extra_es.i_size; i++ )
         {
-            p_sys->es_creation = CREATE_ES;
-            b_create_delayed = true;
+            pid->u.p_pes->extra_es.p_elems[i]->id =
+                    es_out_Add( p_demux->out, &pid->u.p_pes->extra_es.p_elems[i]->fmt );
         }
+        p_sys->i_pmt_es += 1 + pid->u.p_pes->extra_es.i_size;
 
-        if( p_sys->es_creation == CREATE_ES )
+        /* Update the default program == first created ES group */
+        if( p_sys->b_default_selection )
         {
-            pid->u.p_pes->es.id = es_out_Add( p_demux->out, &pid->u.p_pes->es.fmt );
-            for( int i = 0; i < pid->u.p_pes->extra_es.i_size; i++ )
-            {
-                pid->u.p_pes->extra_es.p_elems[i]->id =
-                    es_out_Add( p_demux->out, &pid->u.p_pes->extra_es.p_elems[i]->fmt );
-            }
-            p_sys->i_pmt_es += 1 + pid->u.p_pes->extra_es.i_size;
-            UpdatePESFilters( p_demux, p_sys->b_es_all );
+            p_sys->b_default_selection = false;
+            assert(p_sys->programs.i_size == 1);
+            if( p_sys->programs.p_elems[0] != pid->p_parent->u.p_pmt->i_number )
+                p_sys->programs.p_elems[0] = pid->p_parent->u.p_pmt->i_number;
+            msg_Dbg( p_demux, "Default program is %d", pid->p_parent->u.p_pmt->i_number );
         }
     }
-    else if( p_sys->es_creation == DELAY_ES )
-    {
-        p_sys->es_creation = CREATE_ES;
-        b_create_delayed = true;
-    }
 
     if( b_create_delayed )
     {
@@ -5103,13 +5100,11 @@ static void AddAndCreateES( demux_t *p_demux, ts_pid_t *pid )
                         es_out_Add( p_demux->out, &pid->u.p_pes->extra_es.p_elems[k]->fmt );
                 }
                 p_sys->i_pmt_es += 1 + pid->u.p_pes->extra_es.i_size;
-
-                if( pid->u.p_pes->es.id != NULL && ProgramIsSelected( p_sys, pid->p_parent->u.p_pmt->i_number ) )
-                    SetPIDFilter( p_sys, pid, true );
             }
         }
-        UpdatePESFilters( p_demux, p_sys->b_es_all );
     }
+
+    UpdatePESFilters( p_demux, p_sys->b_es_all );
 }
 
 static void PMTCallBack( void *data, dvbpsi_pmt_t *p_dvbpsipmt )
@@ -5501,7 +5496,7 @@ static void PMTCallBack( void *data, dvbpsi_pmt_t *p_dvbpsipmt )
             }
             else
             {
-                AddAndCreateES( p_demux, pespid );
+                AddAndCreateES( p_demux, pespid, false );
             }
         }