[vlc-commits] [Git][videolan/vlc][master] 6 commits: demux: mp4: avoid passing unused extra parameter to MP4_BoxGet()

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Feb 19 11:36:39 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
11723c09 by Steve Lhomme at 2025-02-19T10:53:21+00:00
demux: mp4: avoid passing unused extra parameter to MP4_BoxGet()

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

- - - - -
aef04a7b by Steve Lhomme at 2025-02-19T10:53:21+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().

- - - - -
8cf9d34a by Steve Lhomme at 2025-02-19T10:53:21+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.

- - - - -
593ffc89 by Steve Lhomme at 2025-02-19T10:53:21+00:00
demux: mp4: use the MP4_BoxGet string formatting

Rather than a local string.

- - - - -
bd5c9bc1 by Steve Lhomme at 2025-02-19T10:53:21+00:00
demux: mp4: use %u with using MP4_BoxGet varargs

- - - - -
21aaf77b by Steve Lhomme at 2025-02-19T10:53:21+00:00
demux: libmp4: put VLC_FORMAT in the MP4_BoxXXX declaration

So the compiler can check the callers.

- - - - -


6 changed files:

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


Changes:

=====================================
modules/demux/mp4/attachments.c
=====================================
@@ -314,12 +314,9 @@ size_t MP4_GetAttachments( const MP4_Box_t *p_root, input_attachment_t ***ppp_at
             char *psz_location;
             if ( asprintf( &psz_location, "pnot[%u]", i_index - 1 ) > -1 )
             {
-                char rgz_path[14];
-                snprintf( rgz_path, 14,
-                         "/%4.4s[%u]",
+                const MP4_Box_t *p_pict = MP4_BoxGetVa( p_root, "/%4.4s[%u]",
                          (const char *) &p_pnot->data.p_pnot->i_type,
                          p_pnot->data.p_pnot->i_index - 1 );
-                const MP4_Box_t *p_pict = MP4_BoxGet( p_root, rgz_path );
                 if( p_pict )
                 {
                     input_attachment_t *p_attach =


=====================================
modules/demux/mp4/essetup.c
=====================================
@@ -773,7 +773,7 @@ int SetupVideoES( demux_t *p_demux, const mp4_track_t *p_track, const MP4_Box_t
         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_fmt->video.i_width = BOXDATA(p_strf)->bmiHeader.biWidth;
@@ -954,7 +954,7 @@ int SetupAudioES( demux_t *p_demux, const mp4_track_t *p_track,
         }
         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 */
             {
@@ -979,7 +979,7 @@ int SetupAudioES( demux_t *p_demux, const mp4_track_t *p_track,
             p_fmt->audio.i_channels = 0;
             p_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_fmt->i_bitrate = BOXDATA(p_dec3)->i_data_rate * 1000;
@@ -995,7 +995,7 @@ int SetupAudioES( demux_t *p_demux, const mp4_track_t *p_track,
             p_fmt->audio.i_channels = 0;
             p_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/heif.c
=====================================
@@ -357,7 +357,7 @@ static int SetPictureProperties( demux_t *p_demux, uint32_t i_item_id,
             if( !BOXDATA(p_ipma)->p_entries[i].p_assocs[j].i_property_index )
                 continue;
 
-            const MP4_Box_t *p_prop = MP4_BoxGet( p_sys->p_root, "meta/iprp/ipco/[%u]",
+            const MP4_Box_t *p_prop = MP4_BoxGetVa( p_sys->p_root, "meta/iprp/ipco/[%u]",
                 BOXDATA(p_ipma)->p_entries[i].p_assocs[j].i_property_index - 1 );
             if( !p_prop )
                 continue;


=====================================
modules/demux/mp4/libmp4.c
=====================================
@@ -5657,7 +5657,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] )
@@ -5705,11 +5705,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 )
@@ -5718,18 +5716,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;
@@ -5740,7 +5729,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;
         }
@@ -5826,11 +5814,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
  *****************************************************************************
@@ -5840,8 +5853,7 @@ error_box:
  * ex: /moov/trak[12]
  *     ../mdia
  *****************************************************************************/
-VLC_FORMAT(2, 3)
-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;
@@ -5853,6 +5865,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
  *****************************************************************************
@@ -5862,8 +5883,7 @@ MP4_Box_t *MP4_BoxGet( const MP4_Box_t *p_box, const char *psz_fmt, ... )
  * ex: /moov/trak[12]
  *     ../mdia
  *****************************************************************************/
-VLC_FORMAT(2, 3)
-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;
@@ -5887,3 +5907,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
=====================================
@@ -1967,7 +1967,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]
@@ -1975,10 +1975,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]
@@ -1986,7 +1996,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
=====================================
@@ -715,7 +715,7 @@ static int CreateTracks( demux_t *p_demux, unsigned i_tracks )
     for( unsigned i=0; i<i_tracks; i++ )
     {
         MP4_TrackInit( &p_sys->track[i],
-                       MP4_BoxGet( p_sys->p_root, "/moov/trak[%d]", i ) );
+                       MP4_BoxGetVa( p_sys->p_root, "/moov/trak[%u]", i ) );
     }
 
     return VLC_SUCCESS;
@@ -1152,7 +1152,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;
 
@@ -1267,7 +1267,7 @@ 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 );
 
         /* Enabled check as explained above */
         MP4_Box_t *p_tkhd = MP4_BoxGet( p_trak, "tkhd" );
@@ -1306,7 +1306,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++ )
     {
-        const MP4_Box_t *p_trakbox = MP4_BoxGet( p_sys->p_root, "/moov/trak[%u]", i );
+        const MP4_Box_t *p_trakbox = MP4_BoxGetVa( p_sys->p_root, "/moov/trak[%u]", i );
         MP4_TrackSetup( p_demux, &p_sys->track[i], p_trakbox, true, !b_enabled_es );
         mp4_track_t *p_track = &p_sys->track[i];
 
@@ -3227,7 +3227,7 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
         return VLC_EGENERIC;
     }
 
-    const MP4_Box_t *p_sample = MP4_BoxGet( p_track->p_stsd, "[%d]",
+    const MP4_Box_t *p_sample = MP4_BoxGetVa( p_track->p_stsd, "[%d]",
                                             i_sample_description_index - 1 );
     if( !p_sample ||
         ( !p_sample->data.p_payload && p_track->fmt.i_cat != SPU_ES ) )
@@ -3651,7 +3651,7 @@ static int TrackUpdateFormat( demux_t *p_demux, mp4_track_t *p_track,
         msg_Warn( p_demux, "recreate ES for track[Id 0x%x]",
                   p_track->i_track_ID );
 
-        const MP4_Box_t *p_newsample = MP4_BoxGet( p_track->p_stsd, "[%d]",
+        const MP4_Box_t *p_newsample = MP4_BoxGetVa( p_track->p_stsd, "[%d]",
                                                    p_track->chunk[i_chunk].i_sample_description_index - 1 );
         if( p_newsample == NULL )
         {



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/82e5f6cc167b689daf0204961d584e25302be0e0...21aaf77b87ccfb2fedbd5199c71b96fed051e910

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/82e5f6cc167b689daf0204961d584e25302be0e0...21aaf77b87ccfb2fedbd5199c71b96fed051e910
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