[vlc-devel] [PATCH 2/3] libmp4: Add function MP4_BoxGetSmooBox()

Frédéric Yhuel fyhuel at viotech.net
Thu May 31 15:17:51 CEST 2012


also modify MP4_BoxGetNextChunk() so that a initialization
segment which has been put between two chunks is properly handled.
---
 modules/demux/mp4/libmp4.c |   54 +++++++++++++++++++++++++++++++++++++++++++-
 modules/demux/mp4/libmp4.h |    1 +
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 1058e8f..051419e 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -3422,6 +3422,39 @@ void MP4_BoxFree( stream_t *s, MP4_Box_t *p_box )
     free( p_box );
 }
 
+/* SmooBox is a very simple MP4 box, VLC specific, used only for the stream_filter 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) */
+MP4_Box_t *MP4_BoxGetSmooBox( stream_t *s )
+{
+    /* p_chunk is a virtual root container for the smoo box */
+    MP4_Box_t *p_chunk;
+    MP4_Box_t *p_smoo;
+
+    p_chunk = calloc( 1, sizeof( MP4_Box_t ) );
+    if( unlikely( p_chunk == NULL ) )
+        return NULL;
+
+    p_chunk->i_type = ATOM_root;
+    p_chunk->i_shortsize = 1;
+
+    p_smoo = MP4_ReadBox( s, p_chunk );
+    if( !p_smoo || p_smoo->i_type != ATOM_uuid || CmpUUID( &p_smoo->i_uuid, &SmooBoxUUID ) )
+    {
+        msg_Warn( s, "no smoo box found!");
+        goto error;
+    }
+
+    p_chunk->p_first = p_smoo;
+    p_chunk->p_last = p_smoo;
+
+    return p_chunk;
+
+error:
+        free( p_chunk );
+        return NULL;
+}
+
 MP4_Box_t *MP4_BoxGetInitFrag( stream_t *s )
 {
     /* p_chunk is a virtual root container for the ftyp and moov boxes */
@@ -3479,11 +3512,30 @@ MP4_Box_t *MP4_BoxGetNextChunk( stream_t *s )
     MP4_Box_t *p_chunk;
     MP4_Box_t *p_moof = NULL;
     MP4_Box_t *p_sidx = NULL;
+    MP4_Box_t *p_trash = NULL;
+
+    p_trash = calloc( 1, sizeof( MP4_Box_t ) );
+    if( unlikely( p_trash == NULL ) )
+        return NULL;
+
+    /* We might get a ftyp box or a SmooBox */
+    MP4_ReadBoxCommon( s, p_trash );
+    const uint32_t i_type = p_trash->i_type;
+    const UUID_t i_uuid = p_trash->i_uuid ;
+    free( p_trash );
+
+    if( (i_type == ATOM_uuid && !CmpUUID( &i_uuid, &SmooBoxUUID )) )
+    {
+        return MP4_BoxGetSmooBox( s );
+    }
+    else if( i_type == ATOM_ftyp )
+    {
+        return MP4_BoxGetInitFrag( s );
+    }
 
     p_chunk = calloc( 1, sizeof( MP4_Box_t ) );
     if( unlikely( p_chunk == NULL ) )
         return NULL;
-
     p_chunk->i_type = ATOM_root;
     p_chunk->i_shortsize = 1;
 
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index 05d5711..973689f 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -1459,6 +1459,7 @@ static const UUID_t StraBoxUUID = {
                 { 0xb0, 0x3e, 0xf7, 0x70, 0x33, 0xbd, 0x4b, 0xac,
                   0x96, 0xc7, 0xbf, 0x25, 0xf9, 0x7e, 0x24, 0x47 } };
 
+MP4_Box_t *MP4_BoxGetSmooBox( stream_t * );
 /*****************************************************************************
  * MP4_BoxGetInitFrag : Parse the initialization segment.
  *****************************************************************************
-- 
1.7.9.5




More information about the vlc-devel mailing list