Commit db37ca8b authored by François Cartegnie's avatar François Cartegnie 🤞

demux: ts: split PES header parsing

parent 2b51d31e
......@@ -2050,30 +2050,12 @@ static block_t *Opus_Parse(demux_t *demux, block_t *block)
/****************************************************************************
* gathering stuff
****************************************************************************/
static void ParsePES( demux_t *p_demux, ts_pid_t *pid, block_t *p_pes )
static int ParsePESHeader( demux_t *p_demux, const uint8_t *p_header,
unsigned *pi_skip, mtime_t *pi_dts, mtime_t *pi_pts )
{
demux_sys_t *p_sys = p_demux->p_sys;
uint8_t header[34];
unsigned i_pes_size = 0;
unsigned i_skip = 0;
mtime_t i_dts = -1;
mtime_t i_pts = -1;
mtime_t i_length = 0;
/* FIXME find real max size */
/* const int i_max = */ block_ChainExtract( p_pes, header, 34 );
if( pid->b_scrambled || header[0] != 0 || header[1] != 0 || header[2] != 1 )
{
if ( !pid->b_scrambled )
msg_Warn( p_demux, "invalid header [0x%02x:%02x:%02x:%02x] (pid: %d)",
header[0], header[1],header[2],header[3], pid->i_pid );
block_ChainRelease( p_pes );
return;
}
unsigned i_skip;
/* TODO check size */
switch( header[3] )
switch( p_header[3] )
{
case 0xBC: /* Program stream map */
case 0xBE: /* Padding */
......@@ -2086,48 +2068,43 @@ static void ParsePES( demux_t *p_demux, ts_pid_t *pid, block_t *p_pes )
i_skip = 6;
break;
default:
if( ( header[6]&0xC0 ) == 0x80 )
if( ( p_header[6]&0xC0 ) == 0x80 )
{
/* mpeg2 PES */
i_skip = header[8] + 9;
i_skip = p_header[8] + 9;
if( header[7]&0x80 ) /* has pts */
if( p_header[7]&0x80 ) /* has pts */
{
i_pts = ExtractPESTimestamp( &header[9] );
i_pts = AdjustPTSWrapAround( p_demux, i_pts );
*pi_pts = ExtractPESTimestamp( &p_header[9] );
if( header[7]&0x40 ) /* has dts */
{
i_dts = ExtractPESTimestamp( &header[14] );
i_dts = AdjustPTSWrapAround( p_demux, i_dts );
}
if( p_header[7]&0x40 ) /* has dts */
*pi_dts = ExtractPESTimestamp( &p_header[14] );
}
}
else
{
i_skip = 6;
while( i_skip < 23 && header[i_skip] == 0xff )
while( i_skip < 23 && p_header[i_skip] == 0xff )
{
i_skip++;
}
if( i_skip == 23 )
{
msg_Err( p_demux, "too much MPEG-1 stuffing" );
block_ChainRelease( p_pes );
return;
return VLC_EGENERIC;
}
if( ( header[i_skip] & 0xC0 ) == 0x40 )
if( ( p_header[i_skip] & 0xC0 ) == 0x40 )
{
i_skip += 2;
}
if( header[i_skip]&0x20 )
if( p_header[i_skip]&0x20 )
{
i_pts = ExtractPESTimestamp( &header[i_skip] );
*pi_pts = ExtractPESTimestamp( &p_header[i_skip] );
if( header[i_skip]&0x10 ) /* has dts */
if( p_header[i_skip]&0x10 ) /* has dts */
{
i_dts = ExtractPESTimestamp( &header[i_skip+5] );
*pi_dts = ExtractPESTimestamp( &p_header[i_skip+5] );
i_skip += 10;
}
else
......@@ -2143,6 +2120,46 @@ static void ParsePES( demux_t *p_demux, ts_pid_t *pid, block_t *p_pes )
break;
}
*pi_skip = i_skip;
return VLC_SUCCESS;
}
static void ParsePES( demux_t *p_demux, ts_pid_t *pid, block_t *p_pes )
{
demux_sys_t *p_sys = p_demux->p_sys;
uint8_t header[34];
unsigned i_pes_size = 0;
unsigned i_skip = 0;
mtime_t i_dts = -1;
mtime_t i_pts = -1;
mtime_t i_length = 0;
/* FIXME find real max size */
/* const int i_max = */ block_ChainExtract( p_pes, header, 34 );
if( pid->b_scrambled || header[0] != 0 || header[1] != 0 || header[2] != 1 )
{
if ( !pid->b_scrambled )
msg_Warn( p_demux, "invalid header [0x%02x:%02x:%02x:%02x] (pid: %d)",
header[0], header[1],header[2],header[3], pid->i_pid );
block_ChainRelease( p_pes );
return;
}
/* TODO check size */
if( ParsePESHeader( p_demux, (uint8_t*)&header, &i_skip, &i_dts, &i_pts ) == VLC_EGENERIC )
{
block_ChainRelease( p_pes );
return;
}
else
{
if( i_pts != -1 )
i_pts = AdjustPTSWrapAround( p_demux, i_pts );
if( i_dts != -1 )
i_dts = AdjustPTSWrapAround( p_demux, i_dts );
}
if( pid->es->fmt.i_codec == VLC_FOURCC( 'a', '5', '2', 'b' ) ||
pid->es->fmt.i_codec == VLC_FOURCC( 'd', 't', 's', 'b' ) )
{
......
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