+static void UpdatePESFilters( demux_t *p_demux, bool b_all )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ ts_pat_t *p_pat = p_sys->pid[0].u.p_pat;
+ for( int i=0; i< p_pat->programs.i_size; i++ )
+ {
+ ts_pmt_t *p_pmt = p_pat->programs.p_elems[i]->u.p_pmt;
+ bool b_program_selected;
+ if( (p_sys->b_default_selection && !p_sys->b_access_control) || b_all )
+ b_program_selected = true;
+ else
+ b_program_selected = ProgramIsSelected( p_sys, p_pmt->i_number );
+
+ SetPIDFilter( p_sys, p_pat->programs.p_elems[i], b_program_selected );
+
+ for( int j=0; j<p_pmt->e_streams.i_size; j++ )
+ {
+ ts_pid_t *espid = p_pmt->e_streams.p_elems[j];
+ bool b_stream_selected = b_program_selected;
+ if( b_program_selected && !b_all && espid->u.p_pes->es.id )
+ es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE,
+ espid->u.p_pes->es.id, &b_stream_selected );
+
+ if( !p_sys->b_es_all && espid->u.p_pes->es.fmt.i_cat == UNKNOWN_ES )
+ b_stream_selected = false;
+
+ if( b_stream_selected )
+ msg_Dbg( p_demux, "enabling pid %d from program %d", espid->i_pid, p_pmt->i_number );
+
+ SetPIDFilter( p_sys, espid, b_stream_selected );
+ if( !b_stream_selected )
+ FlushESBuffer( espid->u.p_pes );
+ }
+
+ /* Select pcr last in case it is handled by unselected ES */
+ if( p_pmt->i_pid_pcr > 0 )
+ {
+ SetPIDFilter( p_sys, &p_sys->pid[p_pmt->i_pid_pcr], b_program_selected );
+ if( b_program_selected )
+ msg_Dbg( p_demux, "enabling pcr pid %d from program %d", p_pmt->i_pid_pcr, p_pmt->i_number );
+ }
+ }
+}
+