Browse Source

mp4: Extract attachments upon first request

Instead of each time DEMUX_GET_ATTACHMENT gets invoked
pull/118/head
Hugo Beauzée-Luyssen 6 years ago
parent
commit
0e9db4f7e6
  1. 5
      modules/demux/mp4/attachments.c
  2. 2
      modules/demux/mp4/attachments.h
  3. 20
      modules/demux/mp4/mp4.c

5
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;
}

2
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 * );

20
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 );
}

Loading…
Cancel
Save