[vlc-commits] stream_filter: smooth: parse chunks using libmp4.h

Francois Cartegnie git at videolan.org
Mon Nov 10 12:59:23 CET 2014


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Nov  9 19:51:08 2014 +0100| [0d862d0b1c84ad6800636b57792339bad4a9e587] | committer: Francois Cartegnie

stream_filter: smooth: parse chunks using libmp4.h

Gets rid of the checkless and expecting in-order data
read functions.

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

 modules/stream_filter/Makefile.am         |    7 ++-
 modules/stream_filter/smooth/downloader.c |   95 +++++++++++------------------
 2 files changed, 41 insertions(+), 61 deletions(-)

diff --git a/modules/stream_filter/Makefile.am b/modules/stream_filter/Makefile.am
index 3de529d..42c2053 100644
--- a/modules/stream_filter/Makefile.am
+++ b/modules/stream_filter/Makefile.am
@@ -99,9 +99,12 @@ libsmooth_plugin_la_SOURCES = \
     stream_filter/smooth/smooth.c \
     stream_filter/smooth/utils.c \
     stream_filter/smooth/downloader.c \
-    stream_filter/smooth/smooth.h
-
+    stream_filter/smooth/smooth.h \
+    demux/mp4/libmp4.c demux/mp4/libmp4.h
 libsmooth_plugin_la_CFLAGS = $(AM_CFLAGS)
+if HAVE_ZLIB
+libsmooth_plugin_la_LIBADD = -lz
+endif
 stream_filter_LTLIBRARIES += libsmooth_plugin.la
 
 libhds_plugin_la_SOURCES = \
diff --git a/modules/stream_filter/smooth/downloader.c b/modules/stream_filter/smooth/downloader.c
index 1216f20..e1efcdd 100644
--- a/modules/stream_filter/smooth/downloader.c
+++ b/modules/stream_filter/smooth/downloader.c
@@ -297,77 +297,54 @@ BandwidthAdaptation( stream_t *s, sms_stream_t *sms,
 
 static int get_new_chunks( stream_t *s, chunk_t *ck, sms_stream_t *sms )
 {
-    stream_sys_t *p_sys = s->p_sys;
-
-    uint8_t *slice = ck->data;
-    if( !slice )
+    if( ck->size < 24 )
         return VLC_EGENERIC;
-    uint8_t version, fragment_count;
-    uint32_t size, type, flags;
-    UUID_t uuid;
-    TfrfBoxDataFields_t *tfrf_df;
-
-    SMS_GET4BYTES( size );
-    SMS_GETFOURCC( type );
-    assert( type == ATOM_moof );
-
-    SMS_GET4BYTES( size );
-    SMS_GETFOURCC( type );
-    assert( type == ATOM_mfhd );
-    slice += size - 8;
 
-    SMS_GET4BYTES( size );
-    SMS_GETFOURCC( type );
-    assert( type == ATOM_traf );
+    stream_t *ck_s = stream_MemoryNew( s, ck->data, ck->size, true );
+    if ( !ck_s )
+        return VLC_EGENERIC;
 
-    for(;;)
+    MP4_Box_t root_box = { 0 };
+    root_box.i_type = ATOM_root;
+    root_box.i_size = ck->size;
+    if ( MP4_ReadBoxContainerChildren( ck_s, &root_box, 0 ) != 1 )
     {
-        SMS_GET4BYTES( size );
-        assert( size > 1 );
-        SMS_GETFOURCC( type );
-        if( type == ATOM_mdat )
-        {
-            msg_Err( s, "No uuid box found :-(" );
-            return VLC_EGENERIC;
-        }
-        else if( type == ATOM_uuid )
-        {
-            GetUUID( &uuid, slice);
-            if( !CmpUUID( &uuid, &TfrfBoxUUID ) )
-                break;
-        }
-        slice += size - 8;
-    }
-
-    slice += 16;
-    SMS_GET1BYTE( version );
-    SMS_GET3BYTES( flags );
-    SMS_GET1BYTE( fragment_count );
-
-    tfrf_df = calloc( fragment_count, sizeof( TfrfBoxDataFields_t ) );
-    if( unlikely( tfrf_df == NULL ) )
+        stream_Delete( ck_s );
         return VLC_EGENERIC;
+    }
+#ifndef NDEBUG
+    MP4_BoxDumpStructure( ck_s, &root_box );
+#endif
 
-    for( uint8_t i = 0; i < fragment_count; i++ )
+    const MP4_Box_t *uuid_box = MP4_BoxGet( &root_box, "moof/traf/uuid" );
+    while( uuid_box && uuid_box->i_type == ATOM_uuid )
     {
-        SMS_GET4or8BYTES( tfrf_df[i].i_fragment_abs_time );
-        SMS_GET4or8BYTES( tfrf_df[i].i_fragment_duration );
+        if ( !CmpUUID( &uuid_box->i_uuid, &TfrfBoxUUID ) )
+            break;
+        uuid_box = uuid_box->p_next;
     }
 
-    msg_Dbg( s, "read box: \"tfrf\" version %d, flags 0x%x, "\
-            "fragment count %"PRIu8, version, flags, fragment_count );
-
-    for( uint8_t i = 0; i < fragment_count; i++ )
+    if ( uuid_box )
     {
-        uint64_t dur = tfrf_df[i].i_fragment_duration;
-        uint64_t stime = tfrf_df[i].i_fragment_abs_time;
-        msg_Dbg( s, "\"tfrf\" fragment duration %"PRIu64", "\
-                    "fragment abs time %"PRIu64, dur, stime);
+        const MP4_Box_data_tfrf_t *p_tfrfdata = uuid_box->data.p_tfrf;
+        for ( uint8_t i=0; i<p_tfrfdata->i_fragment_count; i++ )
+        {
+            uint64_t dur = p_tfrfdata->p_tfrf_data_fields[i].i_fragment_duration;
+            uint64_t stime = p_tfrfdata->p_tfrf_data_fields[i].i_fragment_abs_time;
+            msg_Dbg( s, "\"tfrf\" fragment duration %"PRIu64", "
+                        "fragment abs time %"PRIu64, dur, stime );
+            if( !chunk_Get( sms, stime + dur ) )
+                chunk_AppendNew( sms, dur, stime );
+        }
+    }
 
-        if( !chunk_Get( sms, stime + dur ) )
-            chunk_AppendNew( sms, dur, stime );
+    MP4_Box_t *p_box = root_box.p_first;
+    while( p_box )
+    {
+        MP4_BoxFree( ck_s, p_box );
+        p_box = p_box->p_next;
     }
-    free( tfrf_df );
+    stream_Delete( ck_s );
 
     return VLC_SUCCESS;
 }



More information about the vlc-commits mailing list