[vlc-devel] [PATCH 1/3] libmp4: Parse 'stra' and 'smoo' boxes

Frédéric Yhuel fyhuel at viotech.net
Tue Apr 24 10:22:28 CEST 2012


These are VLC specific boxes designed for communication between the MP4
demux and the stream_filter Smooth Streaming module. I chose a very
simple design, which may change in the future.
---
 modules/demux/mp4/libmp4.c |   48 ++++++++++++++++++++++++++++++++++++++++++++
 modules/demux/mp4/libmp4.h |   21 +++++++++++++++++++
 2 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index ece9f53..e0cffb4 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -2988,6 +2988,52 @@ static void MP4_FreeBox_tfra( MP4_Box_t *p_box )
     FREENULL( p_box->data.p_tfra->p_sample_number );
 }
 
+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_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_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 );
+}
 
 /* For generic */
 static int MP4_ReadBox_default( stream_t *p_stream, MP4_Box_t *p_box )
@@ -3253,6 +3299,7 @@ static const struct
     /* found in smoothstreaming */
     { ATOM_traf,    MP4_ReadBoxContainer,     MP4_FreeBox_Common },
     { ATOM_mfra,    MP4_ReadBoxContainer,     MP4_FreeBox_Common },
+    { ATOM_smoo,    MP4_ReadBoxContainer,     MP4_FreeBox_Common },
     { ATOM_mfhd,    MP4_ReadBox_mfhd,         MP4_FreeBox_Common },
     { ATOM_sidx,    MP4_ReadBox_sidx,         MP4_FreeBox_sidx },
     { ATOM_tfhd,    MP4_ReadBox_tfhd,         MP4_FreeBox_Common },
@@ -3261,6 +3308,7 @@ static const struct
     { ATOM_mehd,    MP4_ReadBox_mehd,         MP4_FreeBox_Common },
     { ATOM_sdtp,    MP4_ReadBox_sdtp,         MP4_FreeBox_sdtp },
     { ATOM_tfra,    MP4_ReadBox_tfra,         MP4_FreeBox_tfra },
+    { ATOM_stra,    MP4_ReadBox_stra,         MP4_FreeBox_stra },
     { ATOM_mfro,    MP4_ReadBox_mfro,         MP4_FreeBox_Common },
     { ATOM_uuid,    MP4_ReadBox_uuid,         MP4_FreeBox_uuid },
 
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index c25bcff..6e8a1d4 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -89,6 +89,8 @@
 #define ATOM_mfra VLC_FOURCC( 'm', 'f', 'r', 'a' )
 #define ATOM_mfro VLC_FOURCC( 'm', 'f', 'r', 'o' )
 #define ATOM_tfra VLC_FOURCC( 't', 'f', 'r', 'a' )
+#define ATOM_smoo VLC_FOURCC( 's', 'm', 'o', 'o' )
+#define ATOM_stra VLC_FOURCC( 's', 't', 'r', 'a' )
 
 #define ATOM_nmhd VLC_FOURCC( 'n', 'm', 'h', 'd' )
 #define ATOM_mp2v VLC_FOURCC( 'm', 'p', '2', 'v' )
@@ -1112,6 +1114,24 @@ typedef struct
     uint8_t *p_sample_number;
 } MP4_Box_data_tfra_t;
 
+typedef struct
+{
+    uint32_t i_timescale;
+    uint8_t  i_es_cat;
+    uint16_t i_track_ID;
+
+    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;
+    char     *CodecPrivateData;
+} MP4_Box_data_stra_t;
+
 /*
 typedef struct MP4_Box_data__s
 {
@@ -1162,6 +1182,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;
-- 
1.7.5.4




More information about the vlc-devel mailing list