[vlc-commits] [Git][videolan/vlc][master] demux: mp4: support compact sample size box stz2

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Thu Aug 5 08:02:23 UTC 2021



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
885d2dec by Zhao Zhili at 2021-08-05T07:41:50+00:00
demux: mp4: support compact sample size box stz2

- - - - -


3 changed files:

- modules/demux/mp4/libmp4.c
- modules/demux/mp4/libmp4.h
- modules/demux/mp4/mp4.c


Changes:

=====================================
modules/demux/mp4/libmp4.c
=====================================
@@ -2954,6 +2954,73 @@ static int MP4_ReadBox_stsz( stream_t *p_stream, MP4_Box_t *p_box )
     MP4_READBOX_EXIT( 1 );
 }
 
+static int MP4_ReadBox_stz2( stream_t *p_stream, MP4_Box_t *p_box )
+{
+    uint32_t count;
+    uint8_t field_size;
+
+    MP4_READBOX_ENTER( MP4_Box_data_stsz_t, MP4_FreeBox_stsz );
+
+    MP4_GETVERSIONFLAGS( p_box->data.p_stsz );
+
+    uint32_t reserved;
+    MP4_GET3BYTES( reserved );
+    MP4_GET1BYTE(field_size);
+
+    MP4_GET4BYTES( count );
+    p_box->data.p_stsz->i_sample_count = count;
+
+    if( field_size != 4 && field_size != 8 && field_size != 16 )
+        MP4_READBOX_EXIT( 0 );
+    if( ( (uint64_t)field_size * count + 7 ) / 8 > i_read )
+        MP4_READBOX_EXIT( 0 );
+
+    p_box->data.p_stsz->i_entry_size =
+            vlc_alloc( count, sizeof(uint32_t) );
+    if( unlikely( p_box->data.p_stsz->i_entry_size == NULL ) )
+        MP4_READBOX_EXIT( 0 );
+
+    if( field_size == 16 )
+    {
+        for( uint32_t i = 0; i < count; i++ )
+            MP4_GET2BYTES( p_box->data.p_stsz->i_entry_size[i] );
+    }
+    else if( field_size == 8 )
+    {
+        for( uint32_t i = 0; i < count; i++ )
+            MP4_GET1BYTE( p_box->data.p_stsz->i_entry_size[i] );
+    }
+    else
+    {
+        vlc_assert( field_size == 4 );
+        count &= ~1;
+        for( uint32_t i = 0; i < count; i += 2 )
+        {
+            uint8_t entry;
+            MP4_GET1BYTE( entry );
+            p_box->data.p_stsz->i_entry_size[i] = entry >> 4;
+            p_box->data.p_stsz->i_entry_size[i + 1] = entry & 0x0F;
+        }
+        if( count < p_box->data.p_stsz->i_sample_count )
+        {
+            uint8_t entry;
+            /* ISO-14496-12: if the sizes do not fill an integral number of
+             * bytes, the last byte is padded with zeros.
+             */
+            MP4_GET1BYTE( entry );
+            p_box->data.p_stsz->i_entry_size[count] = entry >> 4;
+        }
+    }
+
+#ifdef MP4_VERBOSE
+    msg_Dbg( p_stream, "read box: \"stz2\" field-size %d sample-count %d",
+             field_size,
+             p_box->data.p_stsz->i_sample_count );
+
+#endif
+    MP4_READBOX_EXIT( 1 );
+}
+
 static void MP4_FreeBox_stsc( MP4_Box_t *p_box )
 {
     free( p_box->data.p_stsc->i_first_chunk );
@@ -4866,6 +4933,7 @@ static const struct
     { ATOM_cslg,    MP4_ReadBox_cslg,         ATOM_stbl },
     { ATOM_stsd,    MP4_ReadBox_stsd,         ATOM_stbl },
     { ATOM_stsz,    MP4_ReadBox_stsz,         ATOM_stbl },
+    { ATOM_stz2,    MP4_ReadBox_stz2,         ATOM_stbl },
     { ATOM_stsc,    MP4_ReadBox_stsc,         ATOM_stbl },
     { ATOM_stco,    MP4_ReadBox_stco_co64,    ATOM_stbl },
     { ATOM_co64,    MP4_ReadBox_stco_co64,    ATOM_stbl },


=====================================
modules/demux/mp4/libmp4.h
=====================================
@@ -902,19 +902,6 @@ typedef struct MP4_Box_data_stsz_s
 
 } MP4_Box_data_stsz_t;
 
-typedef struct MP4_Box_data_stz2_s
-{
-    uint8_t  i_version;
-    uint32_t i_flags;
-
-    uint32_t i_sample_size; /* 24 bits */
-    uint8_t  i_field_size;
-    uint32_t i_sample_count;
-
-    uint32_t *i_entry_size; /* array: unsigned int(i_field_size) entry_size */
-
-} MP4_Box_data_stz2_t;
-
 typedef struct MP4_Box_data_stsc_s
 {
     uint8_t  i_version;
@@ -1772,7 +1759,6 @@ typedef union MP4_Box_data_s
     MP4_Box_data_tssy_t *p_tssy;
 
     MP4_Box_data_stsz_t *p_stsz;
-    MP4_Box_data_stz2_t *p_stz2;
     MP4_Box_data_stsc_t *p_stsc;
     MP4_Box_data_co64_t *p_co64;
     MP4_Box_data_stss_t *p_stss;


=====================================
modules/demux/mp4/mp4.c
=====================================
@@ -2570,14 +2570,14 @@ static int TrackCreateSamplesIndex( demux_t *p_demux,
     /* TODO use also stss and stsh table for seeking */
     /* FIXME use edit table */
 
-    /* Find stsz
-     *  Gives the sample size for each samples. There is also a stz2 table
-     *  (compressed form) that we need to implement TODO */
+    /* Find stsz or stz2
+     *  Gives the sample size for each samples. */
     p_box = MP4_BoxGet( p_demux_track->p_stbl, "stsz" );
+    if( !p_box )
+        p_box = MP4_BoxGet( p_demux_track->p_stbl, "stz2" );
     if( !p_box )
     {
-        /* FIXME and stz2 */
-        msg_Warn( p_demux, "cannot find STSZ box" );
+        msg_Warn( p_demux, "cannot find STSZ or STZ2 box" );
         return VLC_EGENERIC;
     }
     stsz = p_box->data.p_stsz;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/885d2decca2072a7618e8fb5abefbfa1cbcd3358

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/885d2decca2072a7618e8fb5abefbfa1cbcd3358
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list