]> git.sesse.net Git - vlc/commitdiff
demux: ts: parse SL config
authorFrancois Cartegnie <fcvlcdev@free.fr>
Fri, 27 Mar 2015 00:38:22 +0000 (01:38 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Fri, 27 Mar 2015 13:39:08 +0000 (14:39 +0100)
modules/demux/mpeg4_iod.c
modules/demux/mpeg4_iod.h

index b8276562db2ee4a97399e1f29f1c20727b6992b2..5958ab423c2fb87a237f99dc5396e84ca5609427 100644 (file)
@@ -27,6 +27,7 @@
 #endif
 
 #include <vlc_common.h>
+#include <vlc_bits.h>
 
 #include "mpeg4_iod.h"
 
@@ -108,17 +109,69 @@ typedef union
     iod_descriptor_t *p_iod;
     es_mpeg4_descriptor_t *es_descr;
     decoder_config_descriptor_t *p_dec_config;
+    sl_config_descriptor_t *sl_descr;
 } iod_read_params_t;
 
 static uint8_t IOD_Desc_Read( vlc_object_t *, unsigned *, const uint8_t **, uint8_t, uint8_t, iod_read_params_t params );
 
+#define SL_Predefined_Custom 0x00
+#define SL_Predefined_NULL   0x01
+#define SL_Predefined_MP4    0x02
 static bool IOD_SLDesc_Read( vlc_object_t *p_object, unsigned i_data, const uint8_t *p_data,
                              iod_read_params_t params )
 {
-    VLC_UNUSED(p_object);
-    VLC_UNUSED(i_data);
-    VLC_UNUSED(p_data);
-    VLC_UNUSED(params);
+    sl_config_descriptor_t *sl_descr = params.sl_descr;
+
+    uint8_t i_predefined = IODGetBytes( &i_data, &p_data, 1 );
+    switch( i_predefined )
+    {
+    case SL_Predefined_Custom:
+        if( i_data < 15 )
+            return false;
+        sl_descr->i_flags = IODGetBytes( &i_data, &p_data, 1 );
+        sl_descr->i_timestamp_resolution = IODGetBytes( &i_data, &p_data, 4 );
+        sl_descr->i_OCR_resolution = IODGetBytes( &i_data, &p_data, 4 );
+        sl_descr->i_timestamp_length = IODGetBytes( &i_data, &p_data, 4 );
+        sl_descr->i_OCR_length = IODGetBytes( &i_data, &p_data, 1 );
+        sl_descr->i_AU_length = IODGetBytes( &i_data, &p_data, 1 );
+        sl_descr->i_instant_bitrate_length = IODGetBytes( &i_data, &p_data, 1 );
+        uint16_t i16 = IODGetBytes( &i_data, &p_data, 2 );
+        sl_descr->i_degradation_priority_length = i16 >> 12;
+        sl_descr->i_AU_seqnum_length = (i16 >> 7) & 0x1f;
+        sl_descr->i_packet_seqnum_length = (i16 >> 2) & 0x1f;
+        break;
+    case SL_Predefined_NULL:
+        memset( sl_descr, 0, sizeof(*sl_descr) );
+        sl_descr->i_timestamp_resolution = 1000;
+        sl_descr->i_timestamp_length = 32;
+        break;
+    case SL_Predefined_MP4:
+        memset( sl_descr, 0, sizeof(*sl_descr) );
+        sl_descr->i_flags = USE_TIMESTAMPS_FLAG;
+        break;
+    default:
+        /* reserved */
+        return false;
+    }
+
+    if( sl_descr->i_flags & USE_DURATION_FLAG )
+    {
+        if( i_data < 8 )
+            return false;
+        sl_descr->i_timescale = IODGetBytes( &i_data, &p_data, 4 );
+        sl_descr->i_accessunit_duration = IODGetBytes( &i_data, &p_data, 2 );
+        sl_descr->i_compositionunit_duration = IODGetBytes( &i_data, &p_data, 2 );
+    }
+
+    if( (sl_descr->i_flags & USE_TIMESTAMPS_FLAG) == 0 )
+    {
+        bs_t s;
+        bs_init( &s, p_data, i_data );
+        sl_descr->i_startdecoding_timestamp = bs_read( &s, sl_descr->i_timestamp_length );
+        sl_descr->i_startcomposition_timestamp = bs_read( &s, sl_descr->i_timestamp_length );
+    }
+
+    iod_debug( p_object, "   * read sl desc predefined: 0x%x", i_predefined );
     return true;
 }
 
@@ -200,6 +253,7 @@ static bool IOD_ESDesc_Read( vlc_object_t *p_object, unsigned i_data, const uint
         return false;
 
     /* SLDescr */
+    params.sl_descr = &es_descr->sl_descr;
     IOD_Desc_Read( p_object, &i_data, &p_data, IODTag_SLDescr, 1, params );
 
     /* IPI / IP / IPMP ... */
index af47b2b40ff68bb384afc509fca67ea9e58f7189..00bf2c1da0d1776a342931a7bf1eb59dfe97d03c 100644 (file)
  *****************************************************************************/
 
 #define ES_DESCRIPTOR_COUNT 255
+typedef enum
+{
+    USE_ACCESS_UNIT_START_FLAG = 1 << 7,
+    USE_ACCESS_UNIT_END_FLAG   = 1 << 6,
+    USE_RANDOM_ACCESS_POINT_FLAG  = 1 << 5,
+    HAS_RANDOM_ACCESS_UNITS_ONLY_FLAG  = 1 << 4,
+    USE_PADDING_FLAG  = 1 << 3,
+    USE_TIMESTAMPS_FLAG  = 1 << 2,
+    USE_IDLE_FLAG  = 1 << 1,
+    USE_DURATION_FLAG  = 1
+} sl_config_flags;
+
+typedef struct
+{
+    uint32_t i_timestamp_resolution;
+    uint32_t i_OCR_resolution;
+    uint8_t i_flags;
+    uint8_t i_timestamp_length;
+    uint8_t i_OCR_length;
+    uint8_t i_AU_length;
+    uint8_t i_instant_bitrate_length;
+    uint8_t i_degradation_priority_length;
+    uint8_t i_AU_seqnum_length;
+    uint8_t i_packet_seqnum_length;
+
+    uint32_t i_timescale;
+    uint16_t i_accessunit_duration;
+    uint16_t i_compositionunit_duration;
+
+    uint64_t i_startdecoding_timestamp;
+    uint64_t i_startcomposition_timestamp;
+} sl_config_descriptor_t;
 
 typedef struct
 {
@@ -38,6 +70,7 @@ typedef struct
     char                    *psz_url;
 
     decoder_config_descriptor_t    dec_descr;
+    sl_config_descriptor_t         sl_descr;
 
 } es_mpeg4_descriptor_t;