[vlc-commits] demux: ts: add SL header decoding
Francois Cartegnie
git at videolan.org
Tue Mar 31 21:22:39 CEST 2015
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Mar 28 15:05:46 2015 +0100| [ebc54664125809d4e4529c14fa7e025f9124110d] | committer: Francois Cartegnie
demux: ts: add SL header decoding
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ebc54664125809d4e4529c14fa7e025f9124110d
---
modules/demux/mpeg4_iod.c | 101 +++++++++++++++++++++++++++++++++++++++++++++
modules/demux/mpeg4_iod.h | 12 ++++++
2 files changed, 113 insertions(+)
diff --git a/modules/demux/mpeg4_iod.c b/modules/demux/mpeg4_iod.c
index 39dc161..eb6f8ee 100644
--- a/modules/demux/mpeg4_iod.c
+++ b/modules/demux/mpeg4_iod.c
@@ -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;
+}
diff --git a/modules/demux/mpeg4_iod.h b/modules/demux/mpeg4_iod.h
index 00bf2c1..0ef10b9 100644
--- a/modules/demux/mpeg4_iod.h
+++ b/modules/demux/mpeg4_iod.h
@@ -54,6 +54,15 @@ typedef struct
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;
uint8_t i_streamType;
@@ -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 );
More information about the vlc-commits
mailing list