[vlc-commits] demux: mp4: change track references handling

Francois Cartegnie git at videolan.org
Wed Aug 21 17:32:25 CEST 2019


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Aug 20 18:23:59 2019 +0200| [06abaff187a380a068217a9a9010da84707d03a3] | committer: Francois Cartegnie

demux: mp4: change track references handling

refs can exist without dest being metadata
regression by 95c46854b43db9793a10ec92467c287d6aaaf646

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

 modules/demux/mp4/mp4.c | 37 +++++++++++++++++++++++++++----------
 modules/demux/mp4/mp4.h | 10 +++++++++-
 2 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/modules/demux/mp4/mp4.c b/modules/demux/mp4/mp4.c
index a5afba1a0a..8547bb0c37 100644
--- a/modules/demux/mp4/mp4.c
+++ b/modules/demux/mp4/mp4.c
@@ -249,9 +249,22 @@ static uint32_t stream_ReadU32( stream_t *s, void *p_read, uint32_t i_toread )
     return i_return;
 }
 
-static inline bool MP4_isMetadata(const mp4_track_t *tk)
+static int MP4_reftypeToFlag( vlc_fourcc_t i_reftype )
 {
-    return tk->as_reftype != 0 && tk->as_reftype != ATOM_subt;
+    switch( i_reftype )
+    {
+        case ATOM_chap:
+            return USEAS_CHAPTERS;
+        case VLC_FOURCC('t','m','c','d'):
+            return USEAS_TIMECODE;
+        default:
+            return USEAS_NONE;
+    }
+}
+
+static bool MP4_isMetadata( const mp4_track_t *tk )
+{
+    return tk->i_use_flags & (USEAS_CHAPTERS|USEAS_TIMECODE);
 }
 
 static MP4_Box_t * MP4_GetTrexByTrackID( MP4_Box_t *p_moov, const uint32_t i_id )
@@ -1014,7 +1027,11 @@ static int Open( vlc_object_t * p_this )
             {
                 mp4_track_t *reftk = MP4_GetTrackByTrackID(p_demux, refdata->i_track_ID[j]);
                 if(reftk)
-                    reftk->as_reftype = p_refbox->i_type;
+                {
+                    msg_Dbg( p_demux, "track 0x%x refs track 0x%x for %4.4s", i,
+                             refdata->i_track_ID[j], (const char *) &p_refbox->i_type );
+                    reftk->i_use_flags |= MP4_reftypeToFlag( p_refbox->i_type );
+                }
             }
         }
     }
@@ -1029,7 +1046,7 @@ static int Open( vlc_object_t * p_this )
         MP4_Box_t *p_trak = MP4_BoxGet( 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].as_reftype )
+        if( p_sys->track[i].b_ok && ! MP4_isMetadata(&p_sys->track[i]) )
         {
             const char *psz_cat;
             switch( p_sys->track[i].fmt.i_cat )
@@ -1055,7 +1072,7 @@ static int Open( vlc_object_t * p_this )
                      p_sys->track[i].fmt.psz_language ?
                      p_sys->track[i].fmt.psz_language : "undef" );
         }
-        else if( p_sys->track[i].b_ok && p_sys->track[i].as_reftype == ATOM_chap )
+        else if( p_sys->track[i].b_ok && (p_sys->track[i].i_use_flags & USEAS_CHAPTERS) )
         {
             msg_Dbg( p_demux, "using track[Id 0x%x] for chapter language %s",
                      p_sys->track[i].i_track_ID,
@@ -1064,8 +1081,8 @@ static int Open( vlc_object_t * p_this )
         }
         else
         {
-            msg_Dbg( p_demux, "ignoring track[Id 0x%x]",
-                     p_sys->track[i].i_track_ID );
+            msg_Dbg( p_demux, "ignoring track[Id 0x%x] %d refs %x",
+                     p_sys->track[i].i_track_ID, p_sys->track[i].b_ok, p_sys->track[i].i_use_flags );
         }
     }
 
@@ -1322,7 +1339,7 @@ static int DemuxTrack( demux_t *p_demux, mp4_track_t *tk, uint64_t i_readpos,
     if( !tk->b_ok || tk->i_sample >= tk->i_sample_count )
         return VLC_DEMUXER_EOS;
 
-    if( tk->as_reftype == ATOM_chap )
+    if( tk->i_use_flags & USEAS_CHAPTERS )
         return VLC_DEMUXER_SUCCESS;
 
     uint32_t i_run_seq = MP4_TrackGetRunSeq( tk );
@@ -2412,7 +2429,7 @@ static void LoadChapter( demux_t  *p_demux )
         for( unsigned i = 0; i < p_sys->i_tracks; i++ )
         {
             mp4_track_t *tk = &p_sys->track[i];
-            if(tk->b_ok && tk->as_reftype == ATOM_chap &&
+            if(tk->b_ok && (tk->i_use_flags & USEAS_CHAPTERS) &&
                tk->fmt.i_cat == SPU_ES && tk->fmt.i_codec == VLC_CODEC_TX3G)
             {
                 LoadChapterApple( p_demux, tk );
@@ -3549,7 +3566,7 @@ static void MP4_TrackSetup( demux_t *p_demux, mp4_track_t *p_track,
 
     /* Disable chapter only track */
     if( p_track->fmt.i_cat == UNKNOWN_ES &&
-        p_track->as_reftype == ATOM_chap )
+       (p_track->i_use_flags & USEAS_CHAPTERS) )
         p_track->b_enable = false;
 
     const MP4_Box_t *p_tsel;
diff --git a/modules/demux/mp4/mp4.h b/modules/demux/mp4/mp4.h
index 688d429495..ca56ca3f99 100644
--- a/modules/demux/mp4/mp4.h
+++ b/modules/demux/mp4/mp4.h
@@ -73,6 +73,13 @@ typedef enum RTP_timstamp_synchronization_s
     UNKNOWN_SYNC = 0, UNSYNCHRONIZED = 1, SYNCHRONIZED = 2, RESERVED = 3
 } RTP_timstamp_synchronization_t;
 
+enum
+{
+    USEAS_NONE = 0,
+    USEAS_CHAPTERS = 1 << 0,
+    USEAS_TIMECODE = 1 << 1,
+};
+
  /* Contain all needed information for read all track with vlc */
 typedef struct
 {
@@ -81,7 +88,8 @@ typedef struct
     int b_ok;               /* The track is usable */
     int b_enable;           /* is the trak enable by default */
     bool b_selected;  /* is the trak being played */
-    vlc_fourcc_t as_reftype; /* !=0 when used for chapter only */
+    int i_use_flags;  /* !=0 Set when track is referenced by specific reference types.
+                         You'll need to lookup other tracks tref to know the ref source */
     bool b_forced_spu; /* forced track selection (never done by default/priority) */
     uint32_t i_switch_group;
 



More information about the vlc-commits mailing list