[vlc-devel] [PATCH] libmp4: add macro MP4_GET4or8BYTES

Frédéric Yhuel fyhuel at viotech.net
Tue Mar 27 11:22:02 CEST 2012


---
 modules/demux/mp4/libmp4.c |  114 ++++++++++++++------------------------------
 1 files changed, 36 insertions(+), 78 deletions(-)

diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index e921398..a25da8d 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -61,6 +61,12 @@ static inline size_t mp4_box_headersize( MP4_Box_t *p_box )
 #define MP4_GETFOURCC( dst ) MP4_GETX_PRIVATE( dst, \
                 VLC_FOURCC(p_peek[0],p_peek[1],p_peek[2],p_peek[3]), 4)
 
+#define MP4_GET4or8BYTES( dst ) \
+    if( (i_version) == 0 ) \
+        MP4_GET4BYTES( dst ); \
+    else \
+        MP4_GET8BYTES( dst ); \
+
 #define MP4_GETVERSIONFLAGS( p_void ) \
     MP4_GET1BYTE( p_void->i_version ); \
     MP4_GET3BYTES( p_void->i_flags )
@@ -437,21 +443,13 @@ static int MP4_ReadBox_mvhd(  stream_t *p_stream, MP4_Box_t *p_box )
     MP4_READBOX_ENTER( MP4_Box_data_mvhd_t );
 
     MP4_GETVERSIONFLAGS( p_box->data.p_mvhd );
+    uint8_t i_version = p_box->data.p_mvhd->i_version;
+
+    MP4_GET4or8BYTES( p_box->data.p_mvhd->i_creation_time );
+    MP4_GET4or8BYTES( p_box->data.p_mvhd->i_modification_time );
+    MP4_GET4BYTES( p_box->data.p_mvhd->i_timescale );
+    MP4_GET4or8BYTES( p_box->data.p_mvhd->i_duration );
 
-    if( p_box->data.p_mvhd->i_version )
-    {
-        MP4_GET8BYTES( p_box->data.p_mvhd->i_creation_time );
-        MP4_GET8BYTES( p_box->data.p_mvhd->i_modification_time );
-        MP4_GET4BYTES( p_box->data.p_mvhd->i_timescale );
-        MP4_GET8BYTES( p_box->data.p_mvhd->i_duration );
-    }
-    else
-    {
-        MP4_GET4BYTES( p_box->data.p_mvhd->i_creation_time );
-        MP4_GET4BYTES( p_box->data.p_mvhd->i_modification_time );
-        MP4_GET4BYTES( p_box->data.p_mvhd->i_timescale );
-        MP4_GET4BYTES( p_box->data.p_mvhd->i_duration );
-    }
     MP4_GET4BYTES( p_box->data.p_mvhd->i_rate );
     MP4_GET2BYTES( p_box->data.p_mvhd->i_volume );
     MP4_GET2BYTES( p_box->data.p_mvhd->i_reserved1 );
@@ -519,17 +517,10 @@ static int MP4_ReadBox_tfxd(  stream_t *p_stream, MP4_Box_t *p_box )
 
     MP4_Box_data_tfxd_t *p_tfxd_data = p_box->data.p_tfxd;
     MP4_GETVERSIONFLAGS( p_tfxd_data );
+    uint8_t i_version = p_tfxd_data->i_version;
 
-    if( p_tfxd_data->i_version == 0 )
-    {
-        MP4_GET4BYTES( p_tfxd_data->i_fragment_abs_time );
-        MP4_GET4BYTES( p_tfxd_data->i_fragment_duration );
-    }
-    else
-    {
-        MP4_GET8BYTES( p_tfxd_data->i_fragment_abs_time );
-        MP4_GET8BYTES( p_tfxd_data->i_fragment_duration );
-    }
+    MP4_GET4or8BYTES( p_tfxd_data->i_fragment_abs_time );
+    MP4_GET4or8BYTES( p_tfxd_data->i_fragment_duration );
 
 #ifdef MP4_VERBOSE
     msg_Dbg( p_stream, "read box: \"tfxd\" version %d, flags 0x%x, "\
@@ -550,6 +541,7 @@ static int MP4_ReadBox_tfrf(  stream_t *p_stream, MP4_Box_t *p_box )
 
     MP4_Box_data_tfrf_t *p_tfrf_data = p_box->data.p_tfrf;
     MP4_GETVERSIONFLAGS( p_tfrf_data );
+    uint8_t i_version = p_tfrf_data->i_version;
 
     MP4_GET1BYTE( p_tfrf_data->i_fragment_count );
 
@@ -561,16 +553,8 @@ static int MP4_ReadBox_tfrf(  stream_t *p_stream, MP4_Box_t *p_box )
     for( uint8_t i = 0; i < p_tfrf_data->i_fragment_count; i++ )
     {
         TfrfBoxDataFields_t *TfrfBoxDataField = &p_tfrf_data->p_tfrf_data_fields[i];
-        if( p_tfrf_data->i_version == 0 )
-        {
-            MP4_GET4BYTES( TfrfBoxDataField->i_fragment_abs_time );
-            MP4_GET4BYTES( TfrfBoxDataField->i_fragment_duration );
-        }
-        else
-        {
-            MP4_GET8BYTES( TfrfBoxDataField->i_fragment_abs_time );
-            MP4_GET8BYTES( TfrfBoxDataField->i_fragment_duration );
-        }
+        MP4_GET4or8BYTES( TfrfBoxDataField->i_fragment_abs_time );
+        MP4_GET4or8BYTES( TfrfBoxDataField->i_fragment_duration );
     }
 
 #ifdef MP4_VERBOSE
@@ -622,20 +606,13 @@ static int MP4_ReadBox_sidx(  stream_t *p_stream, MP4_Box_t *p_box )
 
     MP4_Box_data_sidx_t *p_sidx_data = p_box->data.p_sidx;
     MP4_GETVERSIONFLAGS( p_sidx_data );
+    uint8_t i_version = p_sidx_data->i_version;
 
     MP4_GET4BYTES( p_sidx_data->i_reference_ID );
     MP4_GET4BYTES( p_sidx_data->i_timescale );
 
-    if( p_sidx_data->i_version == 0 )
-    {
-        MP4_GET4BYTES( p_sidx_data->i_earliest_presentation_time );
-        MP4_GET4BYTES( p_sidx_data->i_first_offset );
-    }
-    else
-    {
-        MP4_GET8BYTES( p_sidx_data->i_earliest_presentation_time );
-        MP4_GET8BYTES( p_sidx_data->i_first_offset );
-    }
+    MP4_GET4or8BYTES( p_sidx_data->i_earliest_presentation_time );
+    MP4_GET4or8BYTES( p_sidx_data->i_first_offset );
 
     uint16_t i_reserved;
     MP4_GET2BYTES( i_reserved );
@@ -806,23 +783,13 @@ static int MP4_ReadBox_tkhd(  stream_t *p_stream, MP4_Box_t *p_box )
     MP4_READBOX_ENTER( MP4_Box_data_tkhd_t );
 
     MP4_GETVERSIONFLAGS( p_box->data.p_tkhd );
+    uint8_t i_version = p_box->data.p_tkhd->i_version;
 
-    if( p_box->data.p_tkhd->i_version )
-    {
-        MP4_GET8BYTES( p_box->data.p_tkhd->i_creation_time );
-        MP4_GET8BYTES( p_box->data.p_tkhd->i_modification_time );
-        MP4_GET4BYTES( p_box->data.p_tkhd->i_track_ID );
-        MP4_GET4BYTES( p_box->data.p_tkhd->i_reserved );
-        MP4_GET8BYTES( p_box->data.p_tkhd->i_duration );
-    }
-    else
-    {
-        MP4_GET4BYTES( p_box->data.p_tkhd->i_creation_time );
-        MP4_GET4BYTES( p_box->data.p_tkhd->i_modification_time );
-        MP4_GET4BYTES( p_box->data.p_tkhd->i_track_ID );
-        MP4_GET4BYTES( p_box->data.p_tkhd->i_reserved );
-        MP4_GET4BYTES( p_box->data.p_tkhd->i_duration );
-    }
+    MP4_GET4or8BYTES( p_box->data.p_tkhd->i_creation_time );
+    MP4_GET4or8BYTES( p_box->data.p_tkhd->i_modification_time );
+    MP4_GET4BYTES( p_box->data.p_tkhd->i_track_ID );
+    MP4_GET4BYTES( p_box->data.p_tkhd->i_reserved );
+    MP4_GET4or8BYTES( p_box->data.p_tkhd->i_duration );
 
     for( unsigned i = 0; i < 2; i++ )
     {
@@ -904,21 +871,13 @@ static int MP4_ReadBox_mdhd( stream_t *p_stream, MP4_Box_t *p_box )
     MP4_READBOX_ENTER( MP4_Box_data_mdhd_t );
 
     MP4_GETVERSIONFLAGS( p_box->data.p_mdhd );
+    uint8_t i_version = p_box->data.p_mdhd->i_version;
+
+    MP4_GET4or8BYTES( p_box->data.p_mdhd->i_creation_time );
+    MP4_GET4or8BYTES( p_box->data.p_mdhd->i_modification_time );
+    MP4_GET4BYTES( p_box->data.p_mdhd->i_timescale );
+    MP4_GET4or8BYTES( p_box->data.p_mdhd->i_duration );
 
-    if( p_box->data.p_mdhd->i_version )
-    {
-        MP4_GET8BYTES( p_box->data.p_mdhd->i_creation_time );
-        MP4_GET8BYTES( p_box->data.p_mdhd->i_modification_time );
-        MP4_GET4BYTES( p_box->data.p_mdhd->i_timescale );
-        MP4_GET8BYTES( p_box->data.p_mdhd->i_duration );
-    }
-    else
-    {
-        MP4_GET4BYTES( p_box->data.p_mdhd->i_creation_time );
-        MP4_GET4BYTES( p_box->data.p_mdhd->i_modification_time );
-        MP4_GET4BYTES( p_box->data.p_mdhd->i_timescale );
-        MP4_GET4BYTES( p_box->data.p_mdhd->i_duration );
-    }
     p_box->data.p_mdhd->i_language_code = i_language = GetWBE( p_peek );
     for( unsigned i = 0; i < 3; i++ )
     {
@@ -2855,10 +2814,9 @@ static int MP4_ReadBox_mehd( stream_t *p_stream, MP4_Box_t *p_box )
     MP4_READBOX_ENTER( MP4_Box_data_mehd_t );
 
     MP4_GETVERSIONFLAGS( p_box->data.p_mehd );
-    if( p_box->data.p_mehd->i_version == 1 )
-        MP4_GET8BYTES( p_box->data.p_mehd->i_fragment_duration );
-    else /* version == 0 */
-        MP4_GET4BYTES( p_box->data.p_mehd->i_fragment_duration );
+    uint8_t i_version = p_box->data.p_mehd->i_version;
+
+    MP4_GET4or8BYTES( p_box->data.p_mehd->i_fragment_duration );
 
 #ifdef MP4_VERBOSE
     msg_Dbg( p_stream,
-- 
1.7.5.4




More information about the vlc-devel mailing list