]> git.sesse.net Git - vlc/commitdiff
demux: ogg: don't use arbitrary granule as lower search bound
authorFrancois Cartegnie <fcvlcdev@free.fr>
Wed, 16 Oct 2013 10:35:15 +0000 (12:35 +0200)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Tue, 22 Oct 2013 07:38:22 +0000 (16:38 +0900)
Should fix seeking case on time 0

modules/demux/oggseek.c

index d304f1a7c0636dbf4e97da21efdc2bb245f24253..0f69d71f26d1b76ab6499bcac86cf7154cba12a6 100644 (file)
@@ -1154,7 +1154,7 @@ static int64_t OggBisectSearchByTime( demux_t *p_demux, logical_stream_t *p_stre
         int64_t i_pos;
         int64_t i_timestamp;
         int64_t i_granule;
-    } bestlower = { p_stream->i_data_start, 0, p_stream->i_keyframe_offset },
+    } bestlower = { p_stream->i_data_start, -1, -1 },
       current = { -1, -1, -1 };
 
     demux_sys_t *p_sys  = p_demux->p_sys;
@@ -1233,8 +1233,9 @@ static int64_t OggBisectSearchByTime( demux_t *p_demux, logical_stream_t *p_stre
         i_segsize = ( i_end_pos - i_start_pos + 1 ) >> 1;
         i_start_pos += i_segsize;
 
-    } while ( i_segsize > 64 && current.i_granule != -1 );
+    } while ( i_segsize > 64 );
 
+    if ( bestlower.i_granule == -1 ) return -1;
 
     if ( p_stream->b_oggds )
     {
@@ -1253,7 +1254,7 @@ static int64_t OggBisectSearchByTime( demux_t *p_demux, logical_stream_t *p_stre
                            i_keyframegranule >> p_stream->i_granule_shift,
                            bestlower.i_granule,
                            i_pos_upper,
-                           Oggseek_GranuleToAbsTimestamp( p_stream, i_keyframegranule, true ) ) );
+                           Oggseek_GranuleToAbsTimestamp( p_stream, i_keyframegranule, false ) ) );
 
         OggDebug( msg_Dbg( p_demux, "Seeking back to %"PRId64, __MAX ( bestlower.i_pos - OGGSEEK_BYTES_TO_READ, p_stream->i_data_start ) ) );
 
@@ -1275,16 +1276,16 @@ int Oggseek_BlindSeektoAbsoluteTime( demux_t *p_demux, logical_stream_t *p_strea
                                      int64_t i_time, bool b_fastseek )
 {
     demux_sys_t *p_sys  = p_demux->p_sys;
-    int64_t i_pos = -1;
-    int64_t i_unusedpos = -1;
+    int64_t i_lowerpos = -1;
+    int64_t i_upperpos = -1;
     bool b_found = false;
 
     /* Search in skeleton */
-    Ogg_GetBoundsUsingSkeletonIndex( p_stream, i_time, &i_pos, &i_unusedpos );
-    if ( i_pos != -1 ) b_found = true;
+    Ogg_GetBoundsUsingSkeletonIndex( p_stream, i_time, &i_lowerpos, &i_upperpos );
+    if ( i_lowerpos != -1 ) b_found = true;
 
     /* And also search in our own index */
-    if ( !b_found && OggSeekIndexFind( p_stream, i_time, &i_pos, &i_unusedpos ) )
+    if ( !b_found && OggSeekIndexFind( p_stream, i_time, &i_lowerpos, &i_upperpos ) )
     {
         b_found = true;
     }
@@ -1295,29 +1296,29 @@ int Oggseek_BlindSeektoAbsoluteTime( demux_t *p_demux, logical_stream_t *p_strea
     {
         /* But only if there's no keyframe/preload requirements */
         /* FIXME: add function to get preload time by codec, ex: opus */
-        i_pos = i_time * p_sys->i_bitrate / INT64_C(8000000);
+        i_lowerpos = i_time * p_sys->i_bitrate / INT64_C(8000000);
         b_found = true;
     }
 
     /* or search */
     if ( !b_found && b_fastseek )
     {
-        i_pos = OggBisectSearchByTime( p_demux, p_stream, i_time,
-                                                p_stream->i_data_start, p_sys->i_total_length );
-        b_found = ( i_pos != -1 );
+        i_lowerpos = OggBisectSearchByTime( p_demux, p_stream, i_time,
+                                            p_stream->i_data_start, p_sys->i_total_length );
+        b_found = ( i_lowerpos != -1 );
     }
 
     if ( !b_found ) return -1;
 
-    if ( i_pos < p_stream->i_data_start || i_unusedpos > p_sys->i_total_length )
+    if ( i_lowerpos < p_stream->i_data_start || i_upperpos > p_sys->i_total_length )
         return -1;
 
     /* And really do seek */
-    p_sys->i_input_position = i_pos;
+    p_sys->i_input_position = i_lowerpos;
     seek_byte( p_demux, p_sys->i_input_position );
     ogg_stream_reset( &p_stream->os );
 
-    return i_pos;
+    return i_lowerpos;
 }
 
 int Oggseek_BlindSeektoPosition( demux_t *p_demux, logical_stream_t *p_stream,