[vlc-commits] demux: mp4: use sidx index for seeking

Francois Cartegnie git at videolan.org
Wed May 3 14:54:33 CEST 2017


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue May  2 15:49:50 2017 +0200| [ee976cf4bb8685c887eeb781ca60ad884b473bd8] | committer: Francois Cartegnie

demux: mp4: use sidx index for seeking

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

 modules/demux/mp4/mp4.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/modules/demux/mp4/mp4.c b/modules/demux/mp4/mp4.c
index 9388263cb1..8636fea9f9 100644
--- a/modules/demux/mp4/mp4.c
+++ b/modules/demux/mp4/mp4.c
@@ -165,6 +165,8 @@ static bool GetMoofDataRange( MP4_Box_t *p_moov, MP4_Box_t *p_moof,
 static int  ProbeFragments( demux_t *p_demux, bool b_force, bool *pb_fragmented );
 static int  ProbeIndex( demux_t *p_demux );
 
+static int LeafGetMoofBySidxIndex( demux_t *p_demux, mtime_t i_target_time,
+                                   uint64_t *pi_moof_pos, mtime_t *pi_sampletime );
 static int LeafGetMoofByTfraIndex( demux_t *p_demux, const mtime_t i_target_time, unsigned i_track_ID,
                                    uint64_t *pi_moof_pos, mtime_t *pi_sampletime );
 static int LeafGetTrackAndChunkByMOOVPos( demux_t *p_demux, uint64_t *pi_pos,
@@ -1540,6 +1542,10 @@ static int LeafSeekToTime( demux_t *p_demux, mtime_t i_nztime )
         {
             msg_Dbg( p_demux, "seeking to sync point %" PRId64, i_sync_time );
         }
+        else if( LeafGetMoofBySidxIndex( p_demux, i_nztime, &i64, &i_sync_time ) == VLC_SUCCESS )
+        {
+            msg_Dbg( p_demux, "seeking to sidx moof pos %" PRId64 " %" PRId64, i64, i_sync_time );
+        }
         else if( !p_sys->b_fragments_probed && !p_sys->b_fastseekable )
         {
             const char *psz_msg = _(
@@ -4615,6 +4621,35 @@ static int LeafMapTrafTrunContextes( demux_t *p_demux, MP4_Box_t *p_moof )
     return VLC_SUCCESS;
 }
 
+static int LeafGetMoofBySidxIndex( demux_t *p_demux, mtime_t i_target_time,
+                                   uint64_t *pi_moof_pos, mtime_t *pi_sampletime )
+{
+    const MP4_Box_t *p_sidx = MP4_BoxGet( p_demux->p_sys->p_root, "sidx" );
+    const MP4_Box_data_sidx_t *p_data;
+    if( !p_sidx || !((p_data = BOXDATA(p_sidx))) || !p_data->i_timescale )
+        return VLC_EGENERIC;
+
+    i_target_time = MP4_rescale( i_target_time, CLOCK_FREQ, p_data->i_timescale );
+
+    /* sidx refers to offsets from end of sidx pos in the file + first offset */
+    uint64_t i_pos = p_data->i_first_offset + p_sidx->i_pos + p_sidx->i_size;
+    stime_t i_time = 0;
+    for( uint16_t i=0; i<p_data->i_reference_count; i++ )
+    {
+        if( i_time + p_data->p_items[i].i_subsegment_duration > i_target_time )
+        {
+            *pi_sampletime = MP4_rescale( i_time, p_data->i_timescale,
+                                          p_demux->p_sys->i_timescale );
+            *pi_moof_pos = i_pos;
+            return VLC_SUCCESS;
+        }
+        i_pos += p_data->p_items[i].i_referenced_size;
+        i_time += p_data->p_items[i].i_subsegment_duration;
+    }
+
+    return VLC_EGENERIC;
+}
+
 static int LeafGetMoofByTfraIndex( demux_t *p_demux, const mtime_t i_target_time, unsigned i_track_ID,
                                    uint64_t *pi_moof_pos, mtime_t *pi_sampletime )
 {



More information about the vlc-commits mailing list