Commit 5c15aa3d authored by Francois Cartegnie's avatar Francois Cartegnie

demux: ogg: don't use arbitrary granule as lower search bound

Should fix seeking case on time 0
parent 51cff6ef
...@@ -1154,7 +1154,7 @@ static int64_t OggBisectSearchByTime( demux_t *p_demux, logical_stream_t *p_stre ...@@ -1154,7 +1154,7 @@ static int64_t OggBisectSearchByTime( demux_t *p_demux, logical_stream_t *p_stre
int64_t i_pos; int64_t i_pos;
int64_t i_timestamp; int64_t i_timestamp;
int64_t i_granule; 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 }; current = { -1, -1, -1 };
demux_sys_t *p_sys = p_demux->p_sys; 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 ...@@ -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_segsize = ( i_end_pos - i_start_pos + 1 ) >> 1;
i_start_pos += i_segsize; 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 ) if ( p_stream->b_oggds )
{ {
...@@ -1253,7 +1254,7 @@ static int64_t OggBisectSearchByTime( demux_t *p_demux, logical_stream_t *p_stre ...@@ -1253,7 +1254,7 @@ static int64_t OggBisectSearchByTime( demux_t *p_demux, logical_stream_t *p_stre
i_keyframegranule >> p_stream->i_granule_shift, i_keyframegranule >> p_stream->i_granule_shift,
bestlower.i_granule, bestlower.i_granule,
i_pos_upper, 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 ) ) ); 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 ...@@ -1275,16 +1276,16 @@ int Oggseek_BlindSeektoAbsoluteTime( demux_t *p_demux, logical_stream_t *p_strea
int64_t i_time, bool b_fastseek ) int64_t i_time, bool b_fastseek )
{ {
demux_sys_t *p_sys = p_demux->p_sys; demux_sys_t *p_sys = p_demux->p_sys;
int64_t i_pos = -1; int64_t i_lowerpos = -1;
int64_t i_unusedpos = -1; int64_t i_upperpos = -1;
bool b_found = false; bool b_found = false;
/* Search in skeleton */ /* Search in skeleton */
Ogg_GetBoundsUsingSkeletonIndex( p_stream, i_time, &i_pos, &i_unusedpos ); Ogg_GetBoundsUsingSkeletonIndex( p_stream, i_time, &i_lowerpos, &i_upperpos );
if ( i_pos != -1 ) b_found = true; if ( i_lowerpos != -1 ) b_found = true;
/* And also search in our own index */ /* 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; b_found = true;
} }
...@@ -1295,29 +1296,29 @@ int Oggseek_BlindSeektoAbsoluteTime( demux_t *p_demux, logical_stream_t *p_strea ...@@ -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 */ /* But only if there's no keyframe/preload requirements */
/* FIXME: add function to get preload time by codec, ex: opus */ /* 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; b_found = true;
} }
/* or search */ /* or search */
if ( !b_found && b_fastseek ) if ( !b_found && b_fastseek )
{ {
i_pos = OggBisectSearchByTime( p_demux, p_stream, i_time, i_lowerpos = OggBisectSearchByTime( p_demux, p_stream, i_time,
p_stream->i_data_start, p_sys->i_total_length ); p_stream->i_data_start, p_sys->i_total_length );
b_found = ( i_pos != -1 ); b_found = ( i_lowerpos != -1 );
} }
if ( !b_found ) return -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; return -1;
/* And really do seek */ /* 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 ); seek_byte( p_demux, p_sys->i_input_position );
ogg_stream_reset( &p_stream->os ); ogg_stream_reset( &p_stream->os );
return i_pos; return i_lowerpos;
} }
int Oggseek_BlindSeektoPosition( demux_t *p_demux, logical_stream_t *p_stream, int Oggseek_BlindSeektoPosition( demux_t *p_demux, logical_stream_t *p_stream,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment