[vlc-commits] mp4: Extract attachments upon first request

Hugo Beauzée-Luyssen git at videolan.org
Thu Nov 19 11:00:19 CET 2020


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Tue Nov  3 14:33:30 2020 +0100| [0e9db4f7e603e88488f414b7ef44ba8c323f4df0] | committer: Hugo Beauzée-Luyssen

mp4: Extract attachments upon first request

Instead of each time DEMUX_GET_ATTACHMENT gets invoked

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0e9db4f7e603e88488f414b7ef44ba8c323f4df0
---

 modules/demux/mp4/attachments.c |  5 +++--
 modules/demux/mp4/attachments.h |  2 +-
 modules/demux/mp4/mp4.c         | 20 ++++++++++++++++++--
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/modules/demux/mp4/attachments.c b/modules/demux/mp4/attachments.c
index 20fa4ea512..2e00c0468e 100644
--- a/modules/demux/mp4/attachments.c
+++ b/modules/demux/mp4/attachments.c
@@ -233,11 +233,11 @@ int MP4_GetCoverMetaURI( const MP4_Box_t *p_root,
     return VLC_SUCCESS;
 }
 
-int MP4_GetAttachments( const MP4_Box_t *p_root, input_attachment_t ***ppp_attach )
+size_t MP4_GetAttachments( const MP4_Box_t *p_root, input_attachment_t ***ppp_attach )
 {
     const MP4_Box_t *p_metaroot = NULL;
     const char *psz_metarootpath;
-    unsigned i_count = 0;
+    size_t i_count = 0;
     input_attachment_t **pp_attach = NULL;
     *ppp_attach = NULL;
 
@@ -371,6 +371,7 @@ int MP4_GetAttachments( const MP4_Box_t *p_root, input_attachment_t ***ppp_attac
     if ( i_count == 0 )
     {
         free( pp_attach );
+        **ppp_attach = NULL;
         return 0;
     }
 
diff --git a/modules/demux/mp4/attachments.h b/modules/demux/mp4/attachments.h
index ee0eb771a7..fe8eaf1b7f 100644
--- a/modules/demux/mp4/attachments.h
+++ b/modules/demux/mp4/attachments.h
@@ -21,7 +21,7 @@
 #ifndef VLC_MP4_ATTACHMENTS_H_
 #define VLC_MP4_ATTACHMENTS_H_
 
-int MP4_GetAttachments( const MP4_Box_t *, input_attachment_t *** );
+size_t MP4_GetAttachments( const MP4_Box_t *, input_attachment_t *** );
 const MP4_Box_t *MP4_GetMetaRoot( const MP4_Box_t *, const char ** );
 int MP4_GetCoverMetaURI( const MP4_Box_t *,  const MP4_Box_t *,
                          const char *, vlc_meta_t * );
diff --git a/modules/demux/mp4/mp4.c b/modules/demux/mp4/mp4.c
index f0b55cc2b1..30cff828c1 100644
--- a/modules/demux/mp4/mp4.c
+++ b/modules/demux/mp4/mp4.c
@@ -145,6 +145,9 @@ typedef struct
     } hacks;
 
     mp4_fragments_index_t *p_fragsindex;
+
+    ssize_t i_attachments;
+    input_attachment_t **pp_attachments;
 } demux_sys_t;
 
 #define DEMUX_INCREMENT VLC_TICK_FROM_MS(250) /* How far the pcr will go, each round */
@@ -809,6 +812,7 @@ static int Open( vlc_object_t * p_this )
     p_demux->pf_control = Control;
 
     p_sys->context.i_lastseqnumber = UINT32_MAX;
+    p_sys->i_attachments = -1;
 
     p_demux->p_sys = p_sys;
 
@@ -2053,9 +2057,17 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             input_attachment_t ***ppp_attach = va_arg( args, input_attachment_t*** );
             int *pi_int = va_arg( args, int * );
 
-            *pi_int = MP4_GetAttachments( p_sys->p_root, ppp_attach );
-            for( int i=0; i<*pi_int; i++ )
+            if( p_sys->i_attachments == -1 )
+                p_sys->i_attachments = MP4_GetAttachments( p_sys->p_root, &p_sys->pp_attachments );
+            *ppp_attach = calloc( p_sys->i_attachments, sizeof(**ppp_attach ) );
+            if( !*ppp_attach )
+                return VLC_ENOMEM;
+            for ( size_t i = 0; i < p_sys->i_attachments; ++i )
+            {
+                (*ppp_attach)[i] = vlc_input_attachment_Hold( p_sys->pp_attachments[i] );
                 msg_Dbg( p_demux, "adding attachment %s", (*ppp_attach)[i]->psz_name );
+            }
+            *pi_int = p_sys->i_attachments;
 
             return VLC_SUCCESS;
         }
@@ -2178,6 +2190,10 @@ static void Close ( vlc_object_t * p_this )
         MP4_TrackClean( p_demux->out, &p_sys->track[i_track] );
     free( p_sys->track );
 
+    for ( size_t i = 0; i < p_sys->i_attachments; ++i )
+        vlc_input_attachment_Release( p_sys->pp_attachments[i] );
+    free( p_sys->pp_attachments );
+
     free( p_sys );
 }
 



More information about the vlc-commits mailing list