[vlc-commits] libmp4: 'tfhd' parsing

Frédéric Yhuel git at videolan.org
Fri Mar 23 11:54:23 CET 2012


vlc | branch: master | Frédéric Yhuel <fyhuel at viotech.net> | Fri Mar 23 10:40:16 2012 +0100| [3ceb6fcaf187cf052ad2551db0fb4a314afeabae] | committer: Jean-Baptiste Kempf

libmp4: 'tfhd' parsing

- Take into account 'duration-is-empty' flag
- Avoid a full level of indentation

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

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

 modules/demux/mp4/libmp4.c |   85 +++++++++++++++++++++++++------------------
 modules/demux/mp4/libmp4.h |    2 +
 2 files changed, 51 insertions(+), 36 deletions(-)

diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 13057ca..9faf92d 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -569,45 +569,58 @@ static int MP4_ReadBox_tfhd(  stream_t *p_stream, MP4_Box_t *p_box )
 
     MP4_GETVERSIONFLAGS( p_box->data.p_tfhd );
 
+    if( p_box->data.p_tfhd->i_version != 0 )
+    {
+        msg_Warn( p_stream, "'tfhd' box with version != 0. "\
+                " Don't know what to do with that, please patch" );
+        MP4_READBOX_EXIT( 0 );
+    }
+
     MP4_GET4BYTES( p_box->data.p_tfhd->i_track_ID );
 
-    if( p_box->data.p_tfhd->i_version == 0 )
-    {
-        if( p_box->data.p_tfhd->i_flags & MP4_TFHD_BASE_DATA_OFFSET )
-            MP4_GET8BYTES( p_box->data.p_tfhd->i_base_data_offset );
-        if( p_box->data.p_tfhd->i_flags & MP4_TFHD_SAMPLE_DESC_INDEX )
-            MP4_GET4BYTES( p_box->data.p_tfhd->i_sample_description_index );
-        if( p_box->data.p_tfhd->i_flags & MP4_TFHD_DFLT_SAMPLE_DURATION )
-            MP4_GET4BYTES( p_box->data.p_tfhd->i_default_sample_duration );
-        if( p_box->data.p_tfhd->i_flags & MP4_TFHD_DFLT_SAMPLE_SIZE )
-            MP4_GET4BYTES( p_box->data.p_tfhd->i_default_sample_size );
-        if( p_box->data.p_tfhd->i_flags & MP4_TFHD_DFLT_SAMPLE_FLAGS )
-            MP4_GET4BYTES( p_box->data.p_tfhd->i_default_sample_flags );
-
-#ifdef MP4_VERBOSE
-        char psz_base[128] = "\0";
-        char psz_desc[128] = "\0";
-        char psz_dura[128] = "\0";
-        char psz_size[128] = "\0";
-        char psz_flag[128] = "\0";
-        if( p_box->data.p_tfhd->i_flags & MP4_TFHD_BASE_DATA_OFFSET )
-            snprintf(psz_base, sizeof(psz_base), "base offset %"PRId64, p_box->data.p_tfhd->i_base_data_offset);
-        if( p_box->data.p_tfhd->i_flags & MP4_TFHD_SAMPLE_DESC_INDEX )
-            snprintf(psz_desc, sizeof(psz_desc), "sample description index %d", p_box->data.p_tfhd->i_sample_description_index);
-        if( p_box->data.p_tfhd->i_flags & MP4_TFHD_DFLT_SAMPLE_DURATION )
-            snprintf(psz_dura, sizeof(psz_dura), "sample duration %d", p_box->data.p_tfhd->i_default_sample_duration);
-        if( p_box->data.p_tfhd->i_flags & MP4_TFHD_DFLT_SAMPLE_SIZE )
-            snprintf(psz_size, sizeof(psz_size), "sample size %d", p_box->data.p_tfhd->i_default_sample_size);
-        if( p_box->data.p_tfhd->i_flags & MP4_TFHD_DFLT_SAMPLE_FLAGS )
-            snprintf(psz_flag, sizeof(psz_flag), "sample flags 0x%x", p_box->data.p_tfhd->i_default_sample_flags);
-
-        msg_Dbg( p_stream, "read box: \"tfhd\" version %d flags 0x%x track ID %d %s %s %s %s %s",
-                    p_box->data.p_tfhd->i_version,
-                    p_box->data.p_tfhd->i_flags,
-                    p_box->data.p_tfhd->i_track_ID,
-                    psz_base, psz_desc, psz_dura, psz_size, psz_flag );
-#endif
+    if( p_box->data.p_tfhd->i_flags & MP4_TFHD_DURATION_IS_EMPTY )
+    {
+        msg_Dbg( p_stream, "'duration-is-empty' flag is present "\
+                "=> no samples for this time interval." );
+        p_box->data.p_tfhd->b_empty = true;
     }
+    else
+        p_box->data.p_tfhd->b_empty = false;
+
+    if( p_box->data.p_tfhd->i_flags & MP4_TFHD_BASE_DATA_OFFSET )
+        MP4_GET8BYTES( p_box->data.p_tfhd->i_base_data_offset );
+    if( p_box->data.p_tfhd->i_flags & MP4_TFHD_SAMPLE_DESC_INDEX )
+        MP4_GET4BYTES( p_box->data.p_tfhd->i_sample_description_index );
+    if( p_box->data.p_tfhd->i_flags & MP4_TFHD_DFLT_SAMPLE_DURATION )
+        MP4_GET4BYTES( p_box->data.p_tfhd->i_default_sample_duration );
+    if( p_box->data.p_tfhd->i_flags & MP4_TFHD_DFLT_SAMPLE_SIZE )
+        MP4_GET4BYTES( p_box->data.p_tfhd->i_default_sample_size );
+    if( p_box->data.p_tfhd->i_flags & MP4_TFHD_DFLT_SAMPLE_FLAGS )
+        MP4_GET4BYTES( p_box->data.p_tfhd->i_default_sample_flags );
+
+#ifdef MP4_VERBOSE
+    char psz_base[128] = "\0";
+    char psz_desc[128] = "\0";
+    char psz_dura[128] = "\0";
+    char psz_size[128] = "\0";
+    char psz_flag[128] = "\0";
+    if( p_box->data.p_tfhd->i_flags & MP4_TFHD_BASE_DATA_OFFSET )
+        snprintf(psz_base, sizeof(psz_base), "base offset %"PRId64, p_box->data.p_tfhd->i_base_data_offset);
+    if( p_box->data.p_tfhd->i_flags & MP4_TFHD_SAMPLE_DESC_INDEX )
+        snprintf(psz_desc, sizeof(psz_desc), "sample description index %d", p_box->data.p_tfhd->i_sample_description_index);
+    if( p_box->data.p_tfhd->i_flags & MP4_TFHD_DFLT_SAMPLE_DURATION )
+        snprintf(psz_dura, sizeof(psz_dura), "sample duration %d", p_box->data.p_tfhd->i_default_sample_duration);
+    if( p_box->data.p_tfhd->i_flags & MP4_TFHD_DFLT_SAMPLE_SIZE )
+        snprintf(psz_size, sizeof(psz_size), "sample size %d", p_box->data.p_tfhd->i_default_sample_size);
+    if( p_box->data.p_tfhd->i_flags & MP4_TFHD_DFLT_SAMPLE_FLAGS )
+        snprintf(psz_flag, sizeof(psz_flag), "sample flags 0x%x", p_box->data.p_tfhd->i_default_sample_flags);
+
+    msg_Dbg( p_stream, "read box: \"tfhd\" version %d flags 0x%x track ID %d %s %s %s %s %s",
+                p_box->data.p_tfhd->i_version,
+                p_box->data.p_tfhd->i_flags,
+                p_box->data.p_tfhd->i_track_ID,
+                psz_base, psz_desc, psz_dura, psz_size, psz_flag );
+#endif
 
     MP4_READBOX_EXIT( 1 );
 }
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index d548f9e..40eb70c 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -870,9 +870,11 @@ typedef struct MP4_Box_data_sidx_s
 #define MP4_TFHD_DFLT_SAMPLE_DURATION (1LL<<3)
 #define MP4_TFHD_DFLT_SAMPLE_SIZE     (1LL<<4)
 #define MP4_TFHD_DFLT_SAMPLE_FLAGS    (1LL<<5)
+#define MP4_TFHD_DURATION_IS_EMPTY    (1LL<<16)
 typedef struct MP4_Box_data_tfhd_s
 {
     uint8_t  i_version;
+    bool     b_empty;
     uint32_t i_flags;
     uint32_t i_track_ID;
 



More information about the vlc-commits mailing list