Commit ebc54664 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: ts: add SL header decoding

parent b209b71e
......@@ -454,3 +454,104 @@ void IODFree( iod_descriptor_t *p_iod )
}
free( p_iod );
}
/*****************************************************************************
* SL Packet Parser
*****************************************************************************/
sl_header_data DecodeSLHeader( unsigned i_data, const uint8_t *p_data,
const sl_config_descriptor_t *sl )
{
sl_header_data ret = { 0 };
bs_t s;
bs_init( &s, p_data, i_data );
bool b_has_ocr = false;
bool b_is_idle = false;
bool b_has_padding = false;
uint8_t i_padding = 0;
if( sl->i_flags & USE_ACCESS_UNIT_START_FLAG )
ret.b_au_start = bs_read1( &s );
if( sl->i_flags & USE_ACCESS_UNIT_END_FLAG )
ret.b_au_end = bs_read1( &s );
if( sl->i_OCR_length > 0 )
b_has_ocr = bs_read1( &s );
if( sl->i_flags & USE_IDLE_FLAG )
b_is_idle = bs_read1( &s );
if( sl->i_flags & USE_PADDING_FLAG )
b_has_padding = bs_read1( &s );
if( ret.b_au_end == ret.b_au_start && ret.b_au_start == false )
ret.b_au_end = ret.b_au_start = true;
if( b_has_padding )
i_padding = bs_read( &s, 3 );
/* Optional fields */
if( !b_is_idle && ( !b_has_padding || !i_padding ) ) /* When not idle and not only padding */
{
bool b_has_dts = false;
bool b_has_cts = false;
bool b_has_instant_bitrate = false;
struct
{
bool *p_b;
mtime_t *p_t;
} const timestamps[2] = { { &b_has_dts, &ret.i_dts }, { &b_has_cts, &ret.i_pts } };
bs_read( &s, sl->i_packet_seqnum_length );
if( sl->i_degradation_priority_length && bs_read1( &s ) )
bs_read( &s, sl->i_degradation_priority_length );
if( b_has_ocr )
bs_read( &s, sl->i_OCR_length );
if ( ret.b_au_start )
{
if( sl->i_flags & USE_RANDOM_ACCESS_POINT_FLAG )
bs_read1( &s );
bs_read( &s, sl->i_AU_seqnum_length );
if ( sl->i_flags & USE_TIMESTAMPS_FLAG )
{
b_has_dts = bs_read1( &s );
b_has_cts = bs_read1( &s );
}
if( sl->i_instant_bitrate_length )
b_has_instant_bitrate = bs_read1( &s );
for( int i=0; i<2; i++ )
{
if( !*(timestamps[i].p_b) )
continue;
uint64_t i_read = bs_read( &s, __MIN( 32, sl->i_timestamp_length ) );
if( sl->i_timestamp_length > 32 )
{
uint8_t i_bits = __MAX( 1, sl->i_timestamp_length - 32 );
i_read = i_read << i_bits;
i_read |= bs_read( &s, i_bits );
}
if( sl->i_timestamp_resolution )
*(timestamps[i].p_t) = VLC_TS_0 + CLOCK_FREQ * i_read / sl->i_timestamp_resolution;
}
bs_read( &s, sl->i_AU_length );
if( b_has_instant_bitrate )
bs_read( &s, sl->i_instant_bitrate_length );
}
/* more to read if ExtSLConfigDescrTag */
}
if ( b_has_padding && !i_padding ) /* all padding */
ret.i_size = i_data;
else
ret.i_size = (bs_pos( &s ) + 7) / 8;
return ret;
}
......@@ -52,6 +52,15 @@ typedef struct
uint64_t i_startcomposition_timestamp;
} sl_config_descriptor_t;
typedef struct
{
unsigned i_size;
bool b_au_start;
bool b_au_end;
mtime_t i_dts;
mtime_t i_pts;
} sl_header_data;
typedef struct
{
uint8_t i_objectTypeIndication;
......@@ -85,3 +94,6 @@ typedef struct
iod_descriptor_t *IODNew( vlc_object_t *p_object, unsigned i_data, const uint8_t *p_data );
void IODFree( iod_descriptor_t *p_iod );
sl_header_data DecodeSLHeader( unsigned i_data, const uint8_t *p_data,
const sl_config_descriptor_t *sl );
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