Commit 0aa39f4e authored by Francois Cartegnie's avatar Francois Cartegnie

demux: ts: update pid states before parsing data

parent b8c639dd
...@@ -500,6 +500,7 @@ static ts_pmt_t * GetProgramByID( demux_sys_t *, int i_program ); ...@@ -500,6 +500,7 @@ static ts_pmt_t * GetProgramByID( demux_sys_t *, int i_program );
static bool ProgramIsSelected( demux_sys_t *, uint16_t i_pgrm ); static bool ProgramIsSelected( demux_sys_t *, uint16_t i_pgrm );
static void UpdatePESFilters( demux_t *p_demux, bool b_all ); static void UpdatePESFilters( demux_t *p_demux, bool b_all );
static inline void FlushESBuffer( ts_pes_t *p_pes ); static inline void FlushESBuffer( ts_pes_t *p_pes );
static void UpdateScrambledState( demux_t *p_demux, ts_pid_t *p_pid, bool );
static inline int PIDGet( block_t *p ) static inline int PIDGet( block_t *p )
{ {
return ( (p->p_buffer[1]&0x1f)<<8 )|p->p_buffer[2]; return ( (p->p_buffer[1]&0x1f)<<8 )|p->p_buffer[2];
...@@ -1287,6 +1288,16 @@ static int Demux( demux_t *p_demux ) ...@@ -1287,6 +1288,16 @@ static int Demux( demux_t *p_demux )
/* Parse the TS packet */ /* Parse the TS packet */
ts_pid_t *p_pid = &p_sys->pid[PIDGet( p_pkt )]; ts_pid_t *p_pid = &p_sys->pid[PIDGet( p_pkt )];
if( SCRAMBLED(*p_pid) != !!(p_pkt->p_buffer[3] & 0x80) )
UpdateScrambledState( p_demux, p_pid, p_pkt->p_buffer[3] & 0x80 );
if( !SEEN(*p_pid) )
{
if( p_pid->type == TYPE_FREE )
msg_Dbg( p_demux, "pid[%d] unknown", p_pid->i_pid );
p_pid->i_flags |= FLAG_SEEN;
}
/* Probe streams to build PAT/PMT after MIN_PAT_INTERVAL in case we don't see any PAT */ /* Probe streams to build PAT/PMT after MIN_PAT_INTERVAL in case we don't see any PAT */
if( !SEEN(p_sys->pid[0]) && if( !SEEN(p_sys->pid[0]) &&
(p_pid->probed.i_type == 0 || p_pid->i_pid == p_sys->patfix.i_timesourcepid) && (p_pid->probed.i_type == 0 || p_pid->i_pid == p_sys->patfix.i_timesourcepid) &&
...@@ -1346,17 +1357,12 @@ static int Demux( demux_t *p_demux ) ...@@ -1346,17 +1357,12 @@ static int Demux( demux_t *p_demux )
break; break;
default: default:
if( !SEEN(*p_pid) )
msg_Dbg( p_demux, "pid[%d] unknown", p_pid->i_pid );
/* We have to handle PCR if present */ /* We have to handle PCR if present */
PCRHandle( p_demux, p_pid, p_pkt ); PCRHandle( p_demux, p_pid, p_pkt );
block_Release( p_pkt ); block_Release( p_pkt );
break; break;
} }
p_pid->i_flags |= FLAG_SEEN;
if( b_frame || ( b_wait_es && p_sys->i_pmt_es > 0 ) ) if( b_frame || ( b_wait_es && p_sys->i_pmt_es > 0 ) )
break; break;
} }
...@@ -2618,6 +2624,29 @@ static mtime_t GetPCR( block_t *p_pkt ) ...@@ -2618,6 +2624,29 @@ static mtime_t GetPCR( block_t *p_pkt )
return i_pcr; return i_pcr;
} }
static void UpdateScrambledState( demux_t *p_demux, ts_pid_t *p_pid, bool b_scrambled )
{
if( !SCRAMBLED(*p_pid) == !b_scrambled )
return;
msg_Warn( p_demux, "scrambled state changed on pid %d (%d->%d)",
p_pid->i_pid, SCRAMBLED(*p_pid), b_scrambled );
p_pid->i_flags |= (b_scrambled) ? FLAG_SCRAMBLED : FLAGS_NONE;
if( p_pid->type == TYPE_PES && p_pid->u.p_pes->es.id )
{
for( int i = 0; i < p_pid->u.p_pes->extra_es.i_size; i++ )
{
if( p_pid->u.p_pes->extra_es.p_elems[i]->id )
es_out_Control( p_demux->out, ES_OUT_SET_ES_SCRAMBLED_STATE,
p_pid->u.p_pes->extra_es.p_elems[i]->id, b_scrambled );
}
es_out_Control( p_demux->out, ES_OUT_SET_ES_SCRAMBLED_STATE,
p_pid->u.p_pes->es.id, b_scrambled );
}
}
static inline void FlushESBuffer( ts_pes_t *p_pes ) static inline void FlushESBuffer( ts_pes_t *p_pes )
{ {
if( p_pes->p_data ) if( p_pes->p_data )
...@@ -3083,7 +3112,6 @@ static bool GatherData( demux_t *p_demux, ts_pid_t *pid, block_t *p_bk ) ...@@ -3083,7 +3112,6 @@ static bool GatherData( demux_t *p_demux, ts_pid_t *pid, block_t *p_bk )
{ {
const uint8_t *p = p_bk->p_buffer; const uint8_t *p = p_bk->p_buffer;
const bool b_unit_start = p[1]&0x40; const bool b_unit_start = p[1]&0x40;
const bool b_scrambled = p[3]&0x80;
const bool b_adaptation = p[3]&0x20; const bool b_adaptation = p[3]&0x20;
const bool b_payload = p[3]&0x10; const bool b_payload = p[3]&0x10;
const int i_cc = p[3]&0x0f; /* continuity counter */ const int i_cc = p[3]&0x0f; /* continuity counter */
...@@ -3189,23 +3217,6 @@ static bool GatherData( demux_t *p_demux, ts_pid_t *pid, block_t *p_bk ) ...@@ -3189,23 +3217,6 @@ static bool GatherData( demux_t *p_demux, ts_pid_t *pid, block_t *p_bk )
return i_ret; return i_ret;
} }
/* */
if( !SCRAMBLED(*pid) != !b_scrambled )
{
msg_Warn( p_demux, "scrambled state changed on pid %d (%d->%d)",
pid->i_pid, SCRAMBLED(*pid), b_scrambled );
pid->i_flags |= (b_scrambled) ? FLAG_SCRAMBLED : FLAGS_NONE;
for( int i = 0; i < pid->u.p_pes->extra_es.i_size; i++ )
{
es_out_Control( p_demux->out, ES_OUT_SET_ES_SCRAMBLED_STATE,
pid->u.p_pes->extra_es.p_elems[i]->id, b_scrambled );
}
es_out_Control( p_demux->out, ES_OUT_SET_ES_SCRAMBLED_STATE,
pid->u.p_pes->es.id, b_scrambled );
}
/* We have to gather it */ /* We have to gather it */
p_bk->p_buffer += i_skip; p_bk->p_buffer += i_skip;
p_bk->i_buffer -= i_skip; p_bk->i_buffer -= i_skip;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment