Commit 53898816 authored by Denis Charmet's avatar Denis Charmet Committed by Jean-Baptiste Kempf

MKV: Fix seeking without cues for clusters without I frames

If no frame was found in the cluster rewind to previous seekpoint
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
(cherry picked from commit 9561207ffd6e431d26dfde2c6b8353b146d9a77b)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 6cd3b780
...@@ -691,6 +691,7 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_ ...@@ -691,6 +691,7 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_
spoint *p_first = NULL; spoint *p_first = NULL;
spoint *p_last = NULL; spoint *p_last = NULL;
int i_cat; int i_cat;
bool b_has_key = false;
if( i_global_position >= 0 ) if( i_global_position >= 0 )
{ {
...@@ -717,7 +718,7 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_ ...@@ -717,7 +718,7 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_
( i_index > 0 && ( i_index > 0 &&
p_indexes[i_index - 1].i_position < (int64_t)cluster->GetElementPosition() ) ) p_indexes[i_index - 1].i_position < (int64_t)cluster->GetElementPosition() ) )
{ {
ParseCluster(); ParseCluster(false);
IndexAppendCluster( cluster ); IndexAppendCluster( cluster );
} }
if( es.I_O().getFilePointer() >= (unsigned) i_global_position ) if( es.I_O().getFilePointer() >= (unsigned) i_global_position )
...@@ -744,9 +745,9 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_ ...@@ -744,9 +745,9 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_
} }
#endif #endif
int i_idx = 0;
if ( i_index > 0 ) if ( i_index > 0 )
{ {
int i_idx = 0;
for( ; i_idx < i_index; i_idx++ ) for( ; i_idx < i_index; i_idx++ )
if( p_indexes[i_idx].i_time + i_time_offset > i_date ) if( p_indexes[i_idx].i_time + i_time_offset > i_date )
...@@ -773,9 +774,9 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_ ...@@ -773,9 +774,9 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_
es_out_Control( sys.demuxer.out, ES_OUT_SET_NEXT_DISPLAY_TIME, i_date ); es_out_Control( sys.demuxer.out, ES_OUT_SET_NEXT_DISPLAY_TIME, i_date );
/* now parse until key frame */ /* now parse until key frame */
const int es[3] = { VIDEO_ES, AUDIO_ES, SPU_ES }; const int es_types[3] = { VIDEO_ES, AUDIO_ES, SPU_ES };
i_cat = es[0]; i_cat = es_types[0];
for( int i = 0; i < 2; i_cat = es[++i] ) for( int i = 0; i < 2; i_cat = es_types[++i] )
{ {
for( i_track = 0; i_track < tracks.size(); i_track++ ) for( i_track = 0; i_track < tracks.size(); i_track++ )
{ {
...@@ -811,6 +812,8 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_ ...@@ -811,6 +812,8 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_
if( unlikely( !p_first ) ) if( unlikely( !p_first ) )
return; return;
for(;;)
{
while( i_pts < i_date ) while( i_pts < i_date )
{ {
bool b_key_picture; bool b_key_picture;
...@@ -818,7 +821,6 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_ ...@@ -818,7 +821,6 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_
if( BlockGet( block, simpleblock, &b_key_picture, &b_discardable_picture, &i_block_duration ) ) if( BlockGet( block, simpleblock, &b_key_picture, &b_discardable_picture, &i_block_duration ) )
{ {
msg_Warn( &sys.demuxer, "cannot get block EOF?" ); msg_Warn( &sys.demuxer, "cannot get block EOF?" );
return; return;
} }
...@@ -850,11 +852,24 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_ ...@@ -850,11 +852,24 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_
else else
sp->i_seek_pos = i_block_pos; sp->i_seek_pos = i_block_pos;
sp->i_cluster_pos = i_cluster_pos; sp->i_cluster_pos = i_cluster_pos;
b_has_key = true;
} }
} }
delete block; delete block;
} }
if( b_has_key || !i_idx )
break;
/* No key picture was found in the cluster seek to previous seekpoint */
i_date = i_time_offset + p_indexes[i_idx].i_time;
i_idx--;
i_pts = 0;
es.I_O().setFilePointer( p_indexes[i_idx].i_position );
delete ep;
ep = new EbmlParser( &es, segment, &sys.demuxer );
cluster = NULL;
}
/* rewind to the last I img */ /* rewind to the last I img */
spoint * p_min; spoint * p_min;
...@@ -866,7 +881,6 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_ ...@@ -866,7 +881,6 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_
es_out_Control( sys.demuxer.out, ES_OUT_SET_PCR, VLC_TS_0 + sys.i_pcr ); es_out_Control( sys.demuxer.out, ES_OUT_SET_PCR, VLC_TS_0 + sys.i_pcr );
cluster = (KaxCluster *) ep->UnGet( p_min->i_seek_pos, p_min->i_cluster_pos ); cluster = (KaxCluster *) ep->UnGet( p_min->i_seek_pos, p_min->i_cluster_pos );
/* hack use BlockGet to get the cluster then goto the wanted block */ /* hack use BlockGet to get the cluster then goto the wanted block */
if ( !cluster ) if ( !cluster )
{ {
......
...@@ -124,7 +124,7 @@ private: ...@@ -124,7 +124,7 @@ private:
void ParseTracks( KaxTracks *tracks ); void ParseTracks( KaxTracks *tracks );
void ParseChapterAtom( int i_level, KaxChapterAtom *ca, chapter_item_c & chapters ); void ParseChapterAtom( int i_level, KaxChapterAtom *ca, chapter_item_c & chapters );
void ParseTrackEntry( KaxTrackEntry *m ); void ParseTrackEntry( KaxTrackEntry *m );
void ParseCluster( ); void ParseCluster( bool b_update_start_time = true );
void ParseSimpleTags( KaxTagSimple *tag ); void ParseSimpleTags( KaxTagSimple *tag );
void IndexAppendCluster( KaxCluster *cluster ); void IndexAppendCluster( KaxCluster *cluster );
}; };
......
...@@ -1094,7 +1094,7 @@ void matroska_segment_c::ParseChapters( KaxChapters *chapters ) ...@@ -1094,7 +1094,7 @@ void matroska_segment_c::ParseChapters( KaxChapters *chapters )
} }
} }
void matroska_segment_c::ParseCluster( ) void matroska_segment_c::ParseCluster( bool b_update_start_time )
{ {
EbmlElement *el; EbmlElement *el;
EbmlMaster *m; EbmlMaster *m;
...@@ -1117,6 +1117,7 @@ void matroska_segment_c::ParseCluster( ) ...@@ -1117,6 +1117,7 @@ void matroska_segment_c::ParseCluster( )
} }
} }
if( b_update_start_time )
i_start_time = cluster->GlobalTimecode() / 1000; i_start_time = cluster->GlobalTimecode() / 1000;
} }
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