[vlc-commits] demux: libmp4: add child extraction helper
Francois Cartegnie
git at videolan.org
Tue Mar 29 19:58:50 CEST 2016
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Mar 29 09:47:17 2016 +0200| [2bcf949bea43669055e33fedbcfa3193c1b43704] | committer: Francois Cartegnie
demux: libmp4: add child extraction helper
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2bcf949bea43669055e33fedbcfa3193c1b43704
---
modules/demux/mp4/libmp4.c | 17 +++++++++++++++++
modules/demux/mp4/libmp4.h | 2 ++
modules/demux/mp4/mp4.c | 34 ++++++++--------------------------
3 files changed, 27 insertions(+), 26 deletions(-)
diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 3762892..382b7a7 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -110,6 +110,23 @@ static void MP4_BoxAddChild( MP4_Box_t *p_parent, MP4_Box_t *p_childbox )
p_childbox->p_father = p_parent;
}
+MP4_Box_t * MP4_BoxExtract( MP4_Box_t **pp_chain, uint32_t i_type )
+{
+ MP4_Box_t *p_box = *pp_chain;
+ while( p_box )
+ {
+ if( p_box->i_type == i_type )
+ {
+ *pp_chain = p_box->p_next;
+ p_box->p_next = NULL;
+ return p_box;
+ }
+ pp_chain = &p_box->p_next;
+ p_box = p_box->p_next;
+ }
+ return NULL;
+}
+
/* Don't use stream_Seek directly */
#undef stream_Seek
#define stream_Seek(a,b) __NO__
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index d08859e..7c30159 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -1725,6 +1725,8 @@ MP4_Box_t *MP4_BoxGet( const MP4_Box_t *p_box, const char *psz_fmt, ... );
*****************************************************************************/
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 );
+
/* Internal functions exposed for MKV demux */
int MP4_PeekBoxHeader( stream_t *p_stream, MP4_Box_t *p_box );
int MP4_ReadBoxContainerChildren( stream_t *p_stream, MP4_Box_t *p_container,
diff --git a/modules/demux/mp4/mp4.c b/modules/demux/mp4/mp4.c
index 25c60c9..9081d6d 100644
--- a/modules/demux/mp4/mp4.c
+++ b/modules/demux/mp4/mp4.c
@@ -4819,21 +4819,21 @@ static int DemuxAsLeaf( demux_t *p_demux )
if(!p_vroot)
return VLC_DEMUXER_SUCCESS;
- MP4_Box_t *p_fragbox = MP4_BoxGet( p_vroot, "moof" );
- if( !p_fragbox )
+ MP4_Box_t *p_mooxbox = MP4_BoxExtract( &p_vroot->p_first, ATOM_moof );
+ if( !p_mooxbox )
{
- p_fragbox = MP4_BoxGet( p_vroot, "moov" );
RestartAllTracks( p_demux, p_vroot );
+ p_mooxbox = MP4_BoxExtract( &p_vroot->p_first, ATOM_moov );
}
- if(!p_fragbox)
+ if(!p_mooxbox)
{
MP4_BoxFree( p_vroot );
msg_Info(p_demux, "no moof or moov in current chunk");
return VLC_DEMUXER_SUCCESS;
}
- MP4_Box_t *p_mfhd = MP4_BoxGet( p_fragbox, "mfhd" );
+ MP4_Box_t *p_mfhd = MP4_BoxGet( p_mooxbox, "mfhd" );
if( p_mfhd && BOXDATA(p_mfhd) )
{
/* Detect and Handle Passive Seek */
@@ -4859,30 +4859,12 @@ static int DemuxAsLeaf( demux_t *p_demux )
p_sys->context.i_lastseqnumber = BOXDATA(p_mfhd)->i_sequence_number;
}
- /* detach */
- while( p_vroot->p_first )
- {
- if( p_vroot->p_first == p_fragbox )
- {
- p_vroot->p_first = p_fragbox->p_next;
- }
- else
- {
- MP4_Box_t *p_cur = p_vroot->p_first;
- p_vroot->p_first = p_cur->p_next;
- p_cur->p_next = NULL;
- msg_Dbg(p_demux, "ignoring box %4.4s", (char*)&p_cur->i_type);
- MP4_BoxFree( p_cur );
- }
- }
- p_fragbox->p_next = NULL;
-
/* create fragment */
- AddFragment( p_demux, p_fragbox );
+ AddFragment( p_demux, p_mooxbox );
/* Append to root */
- p_sys->p_root->p_last->p_next = p_fragbox;
- p_sys->p_root->p_last = p_fragbox;
+ p_sys->p_root->p_last->p_next = p_mooxbox;
+ p_sys->p_root->p_last = p_mooxbox;
MP4_BoxFree( p_vroot );
}
else
More information about the vlc-commits
mailing list