[vlc-commits] demux: libmp4: read sbgp atoms

Francois Cartegnie git at videolan.org
Fri Mar 25 10:01:17 CET 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Mar 24 18:18:06 2016 +0100| [e2e9f813caad61a5ed267c21ccba75d799408610] | committer: Francois Cartegnie

demux: libmp4: read sbgp atoms

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e2e9f813caad61a5ed267c21ccba75d799408610
---

 modules/demux/mp4/libmp4.c |   67 ++++++++++++++++++++++++++++++++++++++++++++
 modules/demux/mp4/libmp4.h |   17 +++++++++++
 2 files changed, 84 insertions(+)

diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 3b9bb1b..0bc1f3c 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -1680,6 +1680,69 @@ static int MP4_ReadBox_ASF( stream_t *p_stream, MP4_Box_t *p_box )
     MP4_READBOX_EXIT( 1 );
 }
 
+static void MP4_FreeBox_sbgp( MP4_Box_t *p_box )
+{
+    MP4_Box_data_sbgp_t *p_sbgp = p_box->data.p_sbgp;
+    free( p_sbgp->entries.pi_sample_count );
+    free( p_sbgp->entries.pi_group_description_index );
+}
+
+static int MP4_ReadBox_sbgp( stream_t *p_stream, MP4_Box_t *p_box )
+{
+    MP4_READBOX_ENTER( MP4_Box_data_sbgp_t, MP4_FreeBox_sbgp );
+    MP4_Box_data_sbgp_t *p_sbgp = p_box->data.p_sbgp;
+    uint32_t i_flags;
+
+    if ( i_read < 12 )
+        MP4_READBOX_EXIT( 0 );
+
+    MP4_GET1BYTE( p_sbgp->i_version );
+    MP4_GET3BYTES( i_flags );
+    if( i_flags != 0 )
+        MP4_READBOX_EXIT( 0 );
+
+    MP4_GETFOURCC( p_sbgp->i_grouping_type );
+
+    if( p_sbgp->i_version == 1 )
+    {
+        if( i_read < 8 )
+            MP4_READBOX_EXIT( 0 );
+        MP4_GET4BYTES( p_sbgp->i_grouping_type_parameter );
+    }
+
+    MP4_GET4BYTES( p_sbgp->i_entry_count );
+    if( p_sbgp->i_entry_count > i_read / (4 + 4) )
+        p_sbgp->i_entry_count = i_read / (4 + 4);
+
+    p_sbgp->entries.pi_sample_count = malloc( p_sbgp->i_entry_count * sizeof(uint32_t) );
+    p_sbgp->entries.pi_group_description_index = malloc( p_sbgp->i_entry_count * sizeof(uint32_t) );
+
+    if( !p_sbgp->entries.pi_sample_count || !p_sbgp->entries.pi_group_description_index )
+    {
+        MP4_FreeBox_sbgp( p_box );
+        MP4_READBOX_EXIT( 0 );
+    }
+
+    for( uint32_t i=0; i<p_sbgp->i_entry_count; i++ )
+    {
+        MP4_GET4BYTES( p_sbgp->entries.pi_sample_count[i] );
+        MP4_GET4BYTES( p_sbgp->entries.pi_group_description_index[i] );
+    }
+
+#ifdef MP4_VERBOSE
+    msg_Dbg( p_stream,
+        "read box: \"sbgp\" grouping type %4.4s", (char*) &p_sbgp->i_grouping_type );
+ #ifdef MP4_ULTRA_VERBOSE
+    for (uint32_t i = 0; i < p_sbgp->i_entry_count; i++)
+        msg_Dbg( p_stream, "\t samples %" PRIu32 " group %" PRIu32,
+                 p_sbgp->entries.pi_sample_count[i],
+                 p_sbgp->entries.pi_group_description_index[i] );
+ #endif
+#endif
+
+    MP4_READBOX_EXIT( 1 );
+}
+
 static void MP4_FreeBox_stsdext_chan( MP4_Box_t *p_box )
 {
     MP4_Box_data_chan_t *p_chan = p_box->data.p_chan;
@@ -3688,6 +3751,10 @@ static const struct
     { ATOM_btrt,    MP4_ReadBox_btrt,         0 }, /* codecs bitrate stsd/????/btrt */
     { ATOM_keys,    MP4_ReadBox_keys,         ATOM_meta },
 
+    /* Samples groups specific information */
+    { ATOM_sbgp,    MP4_ReadBox_sbgp,         ATOM_stbl },
+    { ATOM_sbgp,    MP4_ReadBox_sbgp,         ATOM_traf },
+
     /* Quicktime preview atoms, all at root */
     { ATOM_pnot,    MP4_ReadBox_pnot,         0 },
     { ATOM_pict,    MP4_ReadBox_Binary,       0 },
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index 8da1109..0575b3c 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -93,6 +93,7 @@ typedef int64_t stime_t;
 #define ATOM_stsc VLC_FOURCC( 's', 't', 's', 'c' )
 #define ATOM_stco VLC_FOURCC( 's', 't', 'c', 'o' )
 #define ATOM_co64 VLC_FOURCC( 'c', 'o', '6', '4' )
+#define ATOM_sbgp VLC_FOURCC( 's', 'b', 'g', 'p' )
 #define ATOM_stss VLC_FOURCC( 's', 't', 's', 's' )
 #define ATOM_stsh VLC_FOURCC( 's', 't', 's', 'h' )
 #define ATOM_stdp VLC_FOURCC( 's', 't', 'd', 'p' )
@@ -1146,6 +1147,19 @@ typedef struct
     uint8_t i_stream_number;
 } MP4_Box_data_ASF_t;
 
+typedef struct
+{
+    uint8_t i_version;
+    uint32_t i_grouping_type;
+    uint32_t i_grouping_type_parameter;
+    uint32_t i_entry_count;
+    struct
+    {
+        uint32_t *pi_sample_count;
+        uint32_t *pi_group_description_index;
+    } entries;
+} MP4_Box_data_sbgp_t;
+
 /* According to Apple's CoreAudio/CoreAudioTypes.h */
 #define MP4_CHAN_USE_CHANNELS_DESC           0
 #define MP4_CHAN_USE_CHANNELS_BITMAP         (1<<16)
@@ -1416,6 +1430,9 @@ typedef union MP4_Box_data_s
     MP4_Box_data_lcont_t *p_lcont;
     MP4_Box_data_stts_t *p_stts;
     MP4_Box_data_ctts_t *p_ctts;
+
+    MP4_Box_data_sbgp_t *p_sbgp;
+
     MP4_Box_data_sample_vide_t *p_sample_vide;
     MP4_Box_data_sample_soun_t *p_sample_soun;
     MP4_Box_data_sample_text_t *p_sample_text;



More information about the vlc-commits mailing list