[vlc-commits] libmp4: Parse StraBox and SmooBox

Frédéric Yhuel git at videolan.org
Wed Jul 18 17:06:48 CEST 2012


vlc | branch: master | Frédéric Yhuel <fyhuel at viotech.net> | Wed Jul 18 16:52:34 2012 +0200| [e93131818521d921e4ae7aa219b899c7c66676c9] | committer: Jean-Baptiste Kempf

libmp4: Parse StraBox and SmooBox

SmooBox is a very simple MP4 box, VLC specific, used only
for the Smooth Streaming module to send information to the demux.
SmooBox is actually a simplified moov box (we wanted to avoid
the hassle of building a moov box at the stream_filter level).

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/demux/mp4/libmp4.c |   58 ++++++++++++++++++++++++++++++++++++++++++++
 modules/demux/mp4/libmp4.h |   28 +++++++++++++++++++++
 2 files changed, 86 insertions(+)

diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 5a89935..03da565 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -475,12 +475,66 @@ static void MP4_FreeBox_tfrf( MP4_Box_t *p_box )
     FREENULL( p_box->data.p_tfrf->p_tfrf_data_fields );
 }
 
+static int MP4_ReadBox_stra( stream_t *p_stream, MP4_Box_t *p_box )
+{
+    MP4_READBOX_ENTER( MP4_Box_data_stra_t );
+    MP4_Box_data_stra_t *p_stra = p_box->data.p_stra;
+
+    uint8_t i_reserved;
+    MP4_GET1BYTE( p_stra->i_es_cat );
+    MP4_GET1BYTE( i_reserved );
+    MP4_GET2BYTES( p_stra->i_track_ID );
+
+    MP4_GET4BYTES( p_stra->i_timescale );
+    MP4_GET8BYTES( p_stra->i_duration );
+
+    MP4_GET4BYTES( p_stra->FourCC );
+    MP4_GET4BYTES( p_stra->Bitrate );
+    MP4_GET4BYTES( p_stra->MaxWidth );
+    MP4_GET4BYTES( p_stra->MaxHeight );
+    MP4_GET4BYTES( p_stra->SamplingRate );
+    MP4_GET4BYTES( p_stra->Channels );
+    MP4_GET4BYTES( p_stra->BitsPerSample );
+    MP4_GET4BYTES( p_stra->PacketSize );
+    MP4_GET4BYTES( p_stra->AudioTag );
+    MP4_GET2BYTES( p_stra->nBlockAlign );
+
+    MP4_GET1BYTE( i_reserved );
+    MP4_GET1BYTE( i_reserved );
+    MP4_GET1BYTE( i_reserved );
+    uint8_t codec_data_length;
+    MP4_GET1BYTE( codec_data_length );
+    p_stra->CodecPrivateData = malloc( codec_data_length + 1);
+    if( unlikely( p_stra->CodecPrivateData == NULL ) )
+        goto error;
+    MP4_GETSTRINGZ( p_stra->CodecPrivateData );
+
+#ifdef MP4_VERBOSE
+    msg_Dbg( p_stream, "es_cat is %"PRIu8", birate is %"PRIu32", "\
+            "CodecPrivateData is %s", p_stra->i_es_cat,
+            p_stra->Bitrate, p_stra->CodecPrivateData );
+#endif
+
+    MP4_READBOX_EXIT( 1 );
+error:
+    MP4_READBOX_EXIT( 0 );
+}
+
+static void MP4_FreeBox_stra( MP4_Box_t *p_box )
+{
+    FREENULL( p_box->data.p_stra->CodecPrivateData );
+}
+
 static int MP4_ReadBox_uuid( stream_t *p_stream, MP4_Box_t *p_box )
 {
     if( !CmpUUID( &p_box->i_uuid, &TfrfBoxUUID ) )
         return MP4_ReadBox_tfrf( p_stream, p_box );
     if( !CmpUUID( &p_box->i_uuid, &TfxdBoxUUID ) )
         return MP4_ReadBox_tfxd( p_stream, p_box );
+    if( !CmpUUID( &p_box->i_uuid, &SmooBoxUUID ) )
+        return MP4_ReadBoxContainer( p_stream, p_box );
+    if( !CmpUUID( &p_box->i_uuid, &StraBoxUUID ) )
+        return MP4_ReadBox_stra( p_stream, p_box );
 
     msg_Warn( p_stream, "Unknown uuid type box" );
     return 1;
@@ -492,6 +546,10 @@ static void MP4_FreeBox_uuid( MP4_Box_t *p_box )
         return MP4_FreeBox_tfrf( p_box );
     if( !CmpUUID( &p_box->i_uuid, &TfxdBoxUUID ) )
         return MP4_FreeBox_Common( p_box );
+    if( !CmpUUID( &p_box->i_uuid, &SmooBoxUUID ) )
+        return MP4_FreeBox_Common( p_box );
+    if( !CmpUUID( &p_box->i_uuid, &StraBoxUUID ) )
+        return MP4_FreeBox_stra( p_box );
 }
 
 static int MP4_ReadBox_sidx(  stream_t *p_stream, MP4_Box_t *p_box )
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index 9485c94..c1f72fd 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -1128,6 +1128,26 @@ typedef struct
     uint8_t *p_sample_number;
 } MP4_Box_data_tfra_t;
 
+typedef struct
+{
+    uint64_t i_duration;
+    uint32_t i_timescale;
+    uint16_t i_track_ID;
+    uint8_t  i_es_cat;
+
+    uint32_t FourCC;
+    uint32_t Bitrate;
+    uint32_t MaxWidth;
+    uint32_t MaxHeight;
+    uint32_t SamplingRate;
+    uint32_t Channels;
+    uint32_t BitsPerSample;
+    uint32_t PacketSize;
+    uint32_t AudioTag;
+    uint16_t nBlockAlign;
+    char     *CodecPrivateData;
+} MP4_Box_data_stra_t;
+
 /*
 typedef struct MP4_Box_data__s
 {
@@ -1178,6 +1198,7 @@ typedef union MP4_Box_data_s
 
     MP4_Box_data_tfra_t *p_tfra;
     MP4_Box_data_mfro_t *p_mfro;
+    MP4_Box_data_stra_t *p_stra;
 
     MP4_Box_data_stsz_t *p_stsz;
     MP4_Box_data_stz2_t *p_stz2;
@@ -1447,6 +1468,13 @@ static const UUID_t TfxdBoxUUID = {
                 { 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
                   0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2 } };
 
+static const UUID_t SmooBoxUUID = {
+                { 0xe1, 0xda, 0x72, 0xba, 0x24, 0xd7, 0x43, 0xc3,
+                  0xa6, 0xa5, 0x1b, 0x57, 0x59, 0xa1, 0xa9, 0x2c } };
+
+static const UUID_t StraBoxUUID = {
+                { 0xb0, 0x3e, 0xf7, 0x70, 0x33, 0xbd, 0x4b, 0xac,
+                  0x96, 0xc7, 0xbf, 0x25, 0xf9, 0x7e, 0x24, 0x47 } };
 
 /*****************************************************************************
  * MP4_BoxGetInitFrag : Parse the initialization segment.



More information about the vlc-commits mailing list