[vlc-commits] demux: mp4: split sync point lookup

Francois Cartegnie git at videolan.org
Fri Mar 25 10:01:18 CET 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Mar 25 07:44:39 2016 +0100| [7f88264a2a2e1d2c97605fee0138e048961c5409] | committer: Francois Cartegnie

demux: mp4: split sync point lookup

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

 modules/demux/mp4/mp4.c |   79 +++++++++++++++++++++++++++--------------------
 1 file changed, 45 insertions(+), 34 deletions(-)

diff --git a/modules/demux/mp4/mp4.c b/modules/demux/mp4/mp4.c
index 88e49cb..bd5beee 100644
--- a/modules/demux/mp4/mp4.c
+++ b/modules/demux/mp4/mp4.c
@@ -2348,6 +2348,35 @@ static int TrackCreateES( demux_t *p_demux, mp4_track_t *p_track,
     return VLC_SUCCESS;
 }
 
+/* *** Try to find nearest sync points *** */
+static int TrackGetNearestSeekPoint( demux_t *p_demux, mp4_track_t *p_track,
+                                     uint32_t i_sample, uint32_t *pi_sync_sample )
+{
+    int i_ret = VLC_EGENERIC;
+
+    const MP4_Box_t *p_stss;
+    if( ( p_stss = MP4_BoxGet( p_track->p_stbl, "stss" ) ) )
+    {
+        const MP4_Box_data_stss_t *p_stss_data = BOXDATA(p_stss);
+        msg_Dbg( p_demux, "track[Id 0x%x] using Sync Sample Box (stss)",
+                 p_track->i_track_ID );
+        for( unsigned i_index = 0; i_index < p_stss_data->i_entry_count; i_index++ )
+        {
+            if( i_index >= p_stss_data->i_entry_count - 1 ||
+                i_sample < p_stss_data->i_sample_number[i_index+1] )
+            {
+                *pi_sync_sample = p_stss_data->i_sample_number[i_index];
+                msg_Dbg( p_demux, "stss gives %d --> %" PRIu32 " (sample number)",
+                         i_sample, *pi_sync_sample );
+                i_ret = VLC_SUCCESS;
+                break;
+            }
+        }
+    }
+
+    return i_ret;
+}
+
 /* given a time it return sample/chunk
  * it also update elst field of the track
  */
@@ -2356,7 +2385,6 @@ static int TrackTimeToSampleChunk( demux_t *p_demux, mp4_track_t *p_track,
                                    uint32_t *pi_sample )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
-    MP4_Box_t   *p_box_stss;
     uint64_t     i_dts;
     unsigned int i_sample;
     unsigned int i_chunk;
@@ -2461,42 +2489,25 @@ static int TrackTimeToSampleChunk( demux_t *p_demux, mp4_track_t *p_track,
 
 
     /* *** Try to find nearest sync points *** */
-    if( ( p_box_stss = MP4_BoxGet( p_track->p_stbl, "stss" ) ) )
+    uint32_t i_sync_sample;
+    if( VLC_SUCCESS ==
+        TrackGetNearestSeekPoint( p_demux, p_track, i_sample, &i_sync_sample ) )
     {
-        MP4_Box_data_stss_t *p_stss = p_box_stss->data.p_stss;
-        msg_Dbg( p_demux, "track[Id 0x%x] using Sync Sample Box (stss)",
-                 p_track->i_track_ID );
-        for( unsigned i_index = 0; i_index < p_stss->i_entry_count; i_index++ )
+        /* Go to chunk */
+        if( i_sync_sample <= i_sample )
         {
-            if( i_index >= p_stss->i_entry_count - 1 ||
-                i_sample < p_stss->i_sample_number[i_index+1] )
-            {
-                unsigned i_sync_sample = p_stss->i_sample_number[i_index];
-                msg_Dbg( p_demux, "stss gives %d --> %d (sample number)",
-                         i_sample, i_sync_sample );
-
-                if( i_sync_sample <= i_sample )
-                {
-                    while( i_chunk > 0 &&
-                           i_sync_sample < p_track->chunk[i_chunk].i_sample_first )
-                        i_chunk--;
-                }
-                else
-                {
-                    while( i_chunk < p_track->i_chunk_count - 1 &&
-                           i_sync_sample >= p_track->chunk[i_chunk].i_sample_first +
-                                            p_track->chunk[i_chunk].i_sample_count )
-                        i_chunk++;
-                }
-                i_sample = i_sync_sample;
-                break;
-            }
+            while( i_chunk > 0 &&
+                   i_sync_sample < p_track->chunk[i_chunk].i_sample_first )
+                i_chunk--;
         }
-    }
-    else
-    {
-        msg_Dbg( p_demux, "track[Id 0x%x] does not provide Sync "
-                 "Sample Box (stss)", p_track->i_track_ID );
+        else
+        {
+            while( i_chunk < p_track->i_chunk_count - 1 &&
+                   i_sync_sample >= p_track->chunk[i_chunk].i_sample_first +
+                                    p_track->chunk[i_chunk].i_sample_count )
+                i_chunk++;
+        }
+        i_sample = i_sync_sample;
     }
 
     *pi_chunk  = i_chunk;



More information about the vlc-commits mailing list