[vlc-devel] [PATCH 1/2] libmp4: 'tfhd' parsing
Frédéric Yhuel
fyhuel at viotech.net
Fri Mar 23 10:40:16 CET 2012
- Take into account 'duration-is-empty' flag
- Avoid a full level of indentation
---
modules/demux/mp4/libmp4.c | 78 +++++++++++++++++++++++++------------------
modules/demux/mp4/libmp4.h | 2 +
2 files changed, 47 insertions(+), 33 deletions(-)
diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 13057ca..a81c27c 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -569,45 +569,57 @@ 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 );
+ p_box->data.p_tfhd->b_empty = false;
+ 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;
+ }
+
+ 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..c5e71fb 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -870,10 +870,12 @@ 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;
uint32_t i_flags;
+ bool b_empty;
uint32_t i_track_ID;
/* optional fields */
--
1.7.5.4
More information about the vlc-devel
mailing list