[vlc-commits] [Git][videolan/vlc][3.0.x] 6 commits: mp4: add format attribute

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Feb 22 14:31:37 UTC 2025



Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC


Commits:
fe23f329 by Rémi Denis-Courmont at 2025-02-22T13:49:20+00:00
mp4: add format attribute

(cherry picked from commit 1a3017ef2dcbc7a3a9cc08299ceec88696f535d1)

- - - - -
696da7b3 by Steve Lhomme at 2025-02-22T13:49:20+00:00
demux: mp4: avoid passing unused extra parameter to MP4_BoxGet()

The format string doesn't contain any string to replace.

(cherry picked from commit 11723c0906d010aed04f311d51408735508fd9a7) (edited)
edited:
- 3.0 needs a similar fix in "tref/chap" handling as 6fd1fbf7582df806079a863773694f3a13ed22ab
  is not backported.

- - - - -
0e178b89 by Steve Lhomme at 2025-02-22T13:49:20+00:00
demux: libmp4: split the code that gets the path and the MP4 box

MP4_BoxGet_Path must always be called with a usable path that won't
be free'd by MP4_BoxGet_Path().

(cherry picked from commit aef04a7b425fb004286b5e3c18ca55ee7b84876e)

- - - - -
cd31c1bf by Steve Lhomme at 2025-02-22T13:49:20+00:00
demux: libmp4: add simplified MP4_BoxGet/MP4_BoxCount

Without varargs which is most of the call we use.
And it won't parse and allocate a new string each time.

(cherry picked from commit 8cf9d34a64d70a6b70aee4ac08f5977e9c2a6173) (edited)
edited:
- 3.0 doesn't have heif.c
- 3.0 has some varargs calls in different places

- - - - -
75b68ec0 by Steve Lhomme at 2025-02-22T13:49:20+00:00
demux: mp4: use %u with using MP4_BoxGet varargs

(cherry picked from commit bd5c9bc1fc23ff566c03e5e61b7be3085acb85ed) (edited)
edited:
- only one location needs a fix on 3.0

- - - - -
672d60bd by Steve Lhomme at 2025-02-22T13:49:20+00:00
demux: libmp4: put VLC_FORMAT in the MP4_BoxXXX declaration

So the compiler can check the callers.

(cherry picked from commit 21aaf77b87ccfb2fedbd5199c71b96fed051e910)

- - - - -


4 changed files:

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


Changes:

=====================================
modules/demux/mp4/essetup.c
=====================================
@@ -693,7 +693,7 @@ int SetupVideoES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
         case ATOM_H264:
         case VLC_FOURCC('W','V','C','1'):
         {
-            MP4_Box_t *p_strf = MP4_BoxGet(  p_sample, "strf", 0 );
+            MP4_Box_t *p_strf = MP4_BoxGet(  p_sample, "strf" );
             if ( p_strf && BOXDATA(p_strf) )
             {
                 p_track->fmt.video.i_width = BOXDATA(p_strf)->bmiHeader.biWidth;
@@ -931,7 +931,7 @@ int SetupAudioES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
         }
         case ATOM_fLaC:
         {
-            const MP4_Box_t *p_dfLa = MP4_BoxGet(  p_sample, "dfLa", 0 );
+            const MP4_Box_t *p_dfLa = MP4_BoxGet(  p_sample, "dfLa" );
             if( p_dfLa && p_dfLa->data.p_binary->i_blob > 4 &&
                 GetDWBE(p_dfLa->data.p_binary->p_blob) == 0 ) /* fullbox header, avoids creating dedicated parser */
             {
@@ -956,7 +956,7 @@ int SetupAudioES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
             p_track->fmt.audio.i_channels = 0;
             p_track->fmt.audio.i_bitspersample = 0;
 
-            const MP4_Box_t *p_dec3 = MP4_BoxGet(  p_sample, "dec3", 0 );
+            const MP4_Box_t *p_dec3 = MP4_BoxGet(  p_sample, "dec3" );
             if( p_dec3 && BOXDATA(p_dec3) )
             {
                 p_track->fmt.i_bitrate = BOXDATA(p_dec3)->i_data_rate * 1000;
@@ -972,7 +972,7 @@ int SetupAudioES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
             p_track->fmt.audio.i_channels = 0;
             p_track->fmt.audio.i_bitspersample = 0;
 
-            MP4_Box_t *p_dac3 = MP4_BoxGet(  p_sample, "dac3", 0 );
+            MP4_Box_t *p_dac3 = MP4_BoxGet(  p_sample, "dac3" );
             if( p_dac3 && BOXDATA(p_dac3) )
             {
                 static const int pi_bitrate[] = {


=====================================
modules/demux/mp4/libmp4.c
=====================================
@@ -5176,7 +5176,7 @@ void MP4_BoxDumpStructure( stream_t *s, const MP4_Box_t *p_box )
  **
  *****************************************************************************
  *****************************************************************************/
-static bool get_token( char **ppsz_path, char **ppsz_token, int *pi_number )
+static bool get_token( const char **ppsz_path, char **ppsz_token, int *pi_number )
 {
     size_t i_len ;
     if( !*ppsz_path[0] )
@@ -5224,11 +5224,9 @@ static bool get_token( char **ppsz_path, char **ppsz_token, int *pi_number )
     return true;
 }
 
-static void MP4_BoxGet_Internal( const MP4_Box_t **pp_result, const MP4_Box_t *p_box,
-                                 const char *psz_fmt, va_list args)
+static void MP4_BoxGet_Path( const MP4_Box_t **pp_result, const MP4_Box_t *p_box,
+                             const char *psz_path)
 {
-    char *psz_dup;
-    char *psz_path;
     char *psz_token = NULL;
 
     if( !p_box )
@@ -5237,18 +5235,9 @@ static void MP4_BoxGet_Internal( const MP4_Box_t **pp_result, const MP4_Box_t *p
         return;
     }
 
-    if( vasprintf( &psz_path, psz_fmt, args ) == -1 )
-        psz_path = NULL;
-
-    if( !psz_path || !psz_path[0] )
-    {
-        free( psz_path );
-        *pp_result = NULL;
-        return;
-    }
+    assert( psz_path && psz_path[0] );
 
 //    fprintf( stderr, "path:'%s'\n", psz_path );
-    psz_dup = psz_path; /* keep this pointer, as it need to be unallocated */
     for( ; ; )
     {
         int i_number;
@@ -5259,7 +5248,6 @@ static void MP4_BoxGet_Internal( const MP4_Box_t **pp_result, const MP4_Box_t *p
 //                 psz_path,psz_token,i_number );
         if( !psz_token )
         {
-            free( psz_dup );
             *pp_result = p_box;
             return;
         }
@@ -5345,11 +5333,36 @@ static void MP4_BoxGet_Internal( const MP4_Box_t **pp_result, const MP4_Box_t *p
 
 error_box:
     free( psz_token );
-    free( psz_dup );
     *pp_result = NULL;
     return;
 }
 
+static void MP4_BoxGet_Internal( const MP4_Box_t **pp_result, const MP4_Box_t *p_box,
+                                 const char *psz_fmt, va_list args)
+{
+    char *psz_path;
+
+    if( !p_box )
+    {
+        *pp_result = NULL;
+        return;
+    }
+
+    if( vasprintf( &psz_path, psz_fmt, args ) == -1 )
+        psz_path = NULL;
+
+    if( !psz_path || !psz_path[0] )
+    {
+        free( psz_path );
+        *pp_result = NULL;
+        return;
+    }
+
+    MP4_BoxGet_Path( pp_result, p_box, psz_path );
+
+    free( psz_path );
+}
+
 /*****************************************************************************
  * MP4_BoxGet: find a box given a path relative to p_box
  *****************************************************************************
@@ -5359,7 +5372,7 @@ error_box:
  * ex: /moov/trak[12]
  *     ../mdia
  *****************************************************************************/
-MP4_Box_t *MP4_BoxGet( const MP4_Box_t *p_box, const char *psz_fmt, ... )
+MP4_Box_t *MP4_BoxGetVa( const MP4_Box_t *p_box, const char *psz_fmt, ... )
 {
     va_list args;
     const MP4_Box_t *p_result;
@@ -5371,6 +5384,15 @@ MP4_Box_t *MP4_BoxGet( const MP4_Box_t *p_box, const char *psz_fmt, ... )
     return( (MP4_Box_t *) p_result );
 }
 
+MP4_Box_t *MP4_BoxGet( const MP4_Box_t *p_box, const char *psz_fmt )
+{
+    const MP4_Box_t *p_result;
+
+    MP4_BoxGet_Path( &p_result, p_box, psz_fmt );
+
+    return( (MP4_Box_t *) p_result );
+}
+
 /*****************************************************************************
  * MP4_BoxCount: count box given a path relative to p_box
  *****************************************************************************
@@ -5380,7 +5402,7 @@ MP4_Box_t *MP4_BoxGet( const MP4_Box_t *p_box, const char *psz_fmt, ... )
  * ex: /moov/trak[12]
  *     ../mdia
  *****************************************************************************/
-unsigned MP4_BoxCount( const MP4_Box_t *p_box, const char *psz_fmt, ... )
+unsigned MP4_BoxCountVa( const MP4_Box_t *p_box, const char *psz_fmt, ... )
 {
     va_list args;
     unsigned i_count;
@@ -5404,3 +5426,25 @@ unsigned MP4_BoxCount( const MP4_Box_t *p_box, const char *psz_fmt, ... )
     }
     return( i_count );
 }
+
+unsigned MP4_BoxCount( const MP4_Box_t *p_box, const char *psz_fmt )
+{
+    unsigned i_count;
+    const MP4_Box_t *p_result, *p_next;
+
+    MP4_BoxGet_Path( &p_result, p_box, psz_fmt );
+    if( !p_result )
+    {
+        return( 0 );
+    }
+
+    i_count = 1;
+    for( p_next = p_result->p_next; p_next != NULL; p_next = p_next->p_next)
+    {
+        if( p_next->i_type == p_result->i_type)
+        {
+            i_count++;
+        }
+    }
+    return( i_count );
+}


=====================================
modules/demux/mp4/libmp4.h
=====================================
@@ -1928,7 +1928,7 @@ void MP4_BoxFree( MP4_Box_t *p_box );
 void MP4_BoxDumpStructure( stream_t *p_input, const MP4_Box_t *p_box );
 
 /*****************************************************************************
- * MP4_BoxGet: find a box given a path relative to p_box
+ * MP4_BoxGetVa: find a box given a path relative to p_box
  *****************************************************************************
  * Path Format: . .. / as usual
  *              [number] to specifie box number ex: trak[12]
@@ -1936,10 +1936,20 @@ void MP4_BoxDumpStructure( stream_t *p_input, const MP4_Box_t *p_box );
  * ex: /moov/trak[12]
  *     ../mdia
  *****************************************************************************/
-MP4_Box_t *MP4_BoxGet( const MP4_Box_t *p_box, const char *psz_fmt, ... );
+MP4_Box_t *MP4_BoxGetVa( const MP4_Box_t *p_box, const char *psz_fmt, ... ) VLC_FORMAT(2, 3);
 
 /*****************************************************************************
- * MP4_BoxCount: find number of box given a path relative to p_box
+ * MP4_BoxGet: find a box given a path relative to p_box
+ *****************************************************************************
+ * Path Format: . .. / as usual
+ *
+ * ex: /moov/mvex
+ *     ../mdia
+ *****************************************************************************/
+MP4_Box_t *MP4_BoxGet( const MP4_Box_t *p_box, const char *psz_fmt) ;
+
+/*****************************************************************************
+ * MP4_BoxCountVa: find number of box given a path relative to p_box
  *****************************************************************************
  * Path Format: . .. / as usual
  *              [number] to specifie box number ex: trak[12]
@@ -1947,7 +1957,17 @@ MP4_Box_t *MP4_BoxGet( const MP4_Box_t *p_box, const char *psz_fmt, ... );
  * ex: /moov/trak
  *     ../mdia
  *****************************************************************************/
-unsigned MP4_BoxCount( const MP4_Box_t *p_box, const char *psz_fmt, ... );
+unsigned MP4_BoxCountVa( const MP4_Box_t *p_box, const char *psz_fmt, ... ) VLC_FORMAT(2, 3);
+
+/*****************************************************************************
+ * MP4_BoxCount: find number of box given a path relative to p_box
+ *****************************************************************************
+ * Path Format: . .. / as usual
+ *
+ * ex: /moov/mvex
+ *     ../mdia
+ *****************************************************************************/
+unsigned MP4_BoxCount( const MP4_Box_t *p_box, const char *psz_fmt );
 
 MP4_Box_t * MP4_BoxExtract( MP4_Box_t **pp_chain, uint32_t i_type );
 


=====================================
modules/demux/mp4/mp4.c
=====================================
@@ -903,7 +903,7 @@ static int Open( vlc_object_t * p_this )
 
         for( i = 0; i < i_count; i++ )
         {
-            MP4_Box_t *p_rdrf = MP4_BoxGet( p_rmra, "rmda[%d]/rdrf", i );
+            MP4_Box_t *p_rdrf = MP4_BoxGetVa( p_rmra, "rmda[%d]/rdrf", i );
             char      *psz_ref;
             uint32_t  i_ref_type;
 
@@ -1010,14 +1010,14 @@ static int Open( vlc_object_t * p_this )
     b_enabled_es = false;
     for( unsigned i = 0; i < p_sys->i_tracks; i++ )
     {
-        MP4_Box_t *p_trak = MP4_BoxGet( p_sys->p_root, "/moov/trak[%d]", i );
+        MP4_Box_t *p_trak = MP4_BoxGetVa( p_sys->p_root, "/moov/trak[%u]", i );
 
 
         MP4_Box_t *p_tkhd = MP4_BoxGet( p_trak, "tkhd" );
         if( p_tkhd && BOXDATA(p_tkhd) && (BOXDATA(p_tkhd)->i_flags&MP4_TRACK_ENABLED) )
             b_enabled_es = true;
 
-        MP4_Box_t *p_chap = MP4_BoxGet( p_trak, "tref/chap", i );
+        MP4_Box_t *p_chap = MP4_BoxGet( p_trak, "tref/chap" );
         if( p_chap && p_chap->data.p_tref_generic &&
             p_chap->data.p_tref_generic->i_entry_count > 0 && !p_sys->p_tref_chap )
             p_sys->p_tref_chap = p_chap;
@@ -1030,7 +1030,7 @@ static int Open( vlc_object_t * p_this )
     /* now process each track and extract all useful information */
     for( unsigned i = 0; i < p_sys->i_tracks; i++ )
     {
-        MP4_Box_t *p_trak = MP4_BoxGet( p_sys->p_root, "/moov/trak[%u]", i );
+        MP4_Box_t *p_trak = MP4_BoxGetVa( p_sys->p_root, "/moov/trak[%u]", i );
         MP4_TrackSetup( p_demux, &p_sys->track[i], p_trak, true, !b_enabled_es );
 
         if( p_sys->track[i].b_ok && !p_sys->track[i].b_chapters_source )
@@ -2933,7 +2933,7 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
         return VLC_EGENERIC;
     }
 
-    MP4_Box_t *p_sample = MP4_BoxGet(  p_track->p_stsd, "[%d]",
+    MP4_Box_t *p_sample = MP4_BoxGetVa(  p_track->p_stsd, "[%d]",
                             i_sample_description_index - 1 );
 
     if( !p_sample ||



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5c0f49410deab34af4f37a1327aeb51d9ac007a7...672d60bdc4694be97d195e8c15a14917ec53e1a5

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5c0f49410deab34af4f37a1327aeb51d9ac007a7...672d60bdc4694be97d195e8c15a14917ec53e1a5
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list