[vlc-commits] MKV: Fix seeking without cues for clusters without I frames

Denis Charmet git at videolan.org
Fri Apr 13 17:20:39 CEST 2012


vlc/vlc-2.0 | branch: master | Denis Charmet <typx at dinauz.org> | Thu Apr 12 02:08:30 2012 +0200| [538988166e87de47619b4cc80521d98b9359c921] | committer: 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: Jean-Baptiste Kempf <jb at videolan.org>
(cherry picked from commit 9561207ffd6e431d26dfde2c6b8353b146d9a77b)

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/demux/mkv/matroska_segment.cpp       |   96 +++++++++++++++-----------
 modules/demux/mkv/matroska_segment.hpp       |    2 +-
 modules/demux/mkv/matroska_segment_parse.cpp |    5 +-
 3 files changed, 59 insertions(+), 44 deletions(-)

diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp
index 86cd07f..f99235f 100644
--- a/modules/demux/mkv/matroska_segment.cpp
+++ b/modules/demux/mkv/matroska_segment.cpp
@@ -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_last = NULL;
     int i_cat;
+    bool b_has_key = false;
 
     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_
                     ( i_index > 0 &&
                       p_indexes[i_index - 1].i_position < (int64_t)cluster->GetElementPosition() ) )
                 {
-                    ParseCluster();
+                    ParseCluster(false);
                     IndexAppendCluster( cluster );
                 }
                 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_
     }
 #endif
 
+    int i_idx = 0;
     if ( i_index > 0 )
     {
-        int i_idx = 0;
 
         for( ; i_idx < i_index; i_idx++ )
             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_
     es_out_Control( sys.demuxer.out, ES_OUT_SET_NEXT_DISPLAY_TIME, i_date );
 
     /* now parse until key frame */
-    const int es[3] = { VIDEO_ES, AUDIO_ES, SPU_ES };
-    i_cat = es[0];
-    for( int i = 0; i < 2; i_cat = es[++i] )
+    const int es_types[3] = { VIDEO_ES, AUDIO_ES, SPU_ES };
+    i_cat = es_types[0];
+    for( int i = 0; i < 2; i_cat = es_types[++i] )
     {
         for( i_track = 0; i_track < tracks.size(); i_track++ )
         {
@@ -811,49 +812,63 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_
     if( unlikely( !p_first ) )
         return; 
 
-    while( i_pts < i_date )
+    for(;;)
     {
-        bool b_key_picture;
-        bool b_discardable_picture;
-        if( BlockGet( block, simpleblock, &b_key_picture, &b_discardable_picture, &i_block_duration ) )
-        {
-            msg_Warn( &sys.demuxer, "cannot get block EOF?" );
-
-            return;
-        }
-
-        /* check if block's track is in our list */
-        for( i_track = 0; i_track < tracks.size(); i_track++ )
+        while( i_pts < i_date )
         {
-            if( (simpleblock && tracks[i_track]->i_number == simpleblock->TrackNum()) ||
-                (block && tracks[i_track]->i_number == block->TrackNum()) )
-                break;
-        }
+            bool b_key_picture;
+            bool b_discardable_picture;
+            if( BlockGet( block, simpleblock, &b_key_picture, &b_discardable_picture, &i_block_duration ) )
+            {
+                msg_Warn( &sys.demuxer, "cannot get block EOF?" );
+                return;
+            }
 
-        if( simpleblock )
-            i_pts = sys.i_chapter_time + simpleblock->GlobalTimecode() / (mtime_t) 1000;
-        else
-            i_pts = sys.i_chapter_time + block->GlobalTimecode() / (mtime_t) 1000;
-        if( i_track < tracks.size() )
-        {
-            if( tracks[i_track]->fmt.i_cat == i_cat && b_key_picture )
+            /* check if block's track is in our list */
+            for( i_track = 0; i_track < tracks.size(); i_track++ )
             {
-                /* get the seekpoint */
-                spoint * sp;
-                for( sp =  p_first; sp; sp = sp->p_next )
-                    if( sp->i_track == i_track )
-                        break;
+                if( (simpleblock && tracks[i_track]->i_number == simpleblock->TrackNum()) ||
+                    (block && tracks[i_track]->i_number == block->TrackNum()) )
+                    break;
+            }
 
-                sp->i_date = i_pts;
-                if( simpleblock )
-                    sp->i_seek_pos = simpleblock->GetElementPosition();
-                else
-                    sp->i_seek_pos = i_block_pos;
-                sp->i_cluster_pos = i_cluster_pos;
+            if( simpleblock )
+                i_pts = sys.i_chapter_time + simpleblock->GlobalTimecode() / (mtime_t) 1000;
+            else
+                i_pts = sys.i_chapter_time + block->GlobalTimecode() / (mtime_t) 1000;
+            if( i_track < tracks.size() )
+            {
+                if( tracks[i_track]->fmt.i_cat == i_cat && b_key_picture )
+                {
+                    /* get the seekpoint */
+                    spoint * sp;
+                    for( sp =  p_first; sp; sp = sp->p_next )
+                        if( sp->i_track == i_track )
+                            break;
+
+                    sp->i_date = i_pts;
+                    if( simpleblock )
+                        sp->i_seek_pos = simpleblock->GetElementPosition();
+                    else
+                        sp->i_seek_pos = i_block_pos;
+                    sp->i_cluster_pos = i_cluster_pos;
+                    b_has_key = true;
+                }
             }
+
+            delete block;
         }
+        if( b_has_key || !i_idx )
+            break;
 
-        delete block;
+        /* 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 */
@@ -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 );
     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 */
     if ( !cluster )
     {
diff --git a/modules/demux/mkv/matroska_segment.hpp b/modules/demux/mkv/matroska_segment.hpp
index 1c210c6..673458e 100644
--- a/modules/demux/mkv/matroska_segment.hpp
+++ b/modules/demux/mkv/matroska_segment.hpp
@@ -124,7 +124,7 @@ private:
     void ParseTracks( KaxTracks *tracks );
     void ParseChapterAtom( int i_level, KaxChapterAtom *ca, chapter_item_c & chapters );
     void ParseTrackEntry( KaxTrackEntry *m );
-    void ParseCluster( );
+    void ParseCluster( bool b_update_start_time = true );
     void ParseSimpleTags( KaxTagSimple *tag );
     void IndexAppendCluster( KaxCluster *cluster );
 };
diff --git a/modules/demux/mkv/matroska_segment_parse.cpp b/modules/demux/mkv/matroska_segment_parse.cpp
index 4676b24..1cac799 100644
--- a/modules/demux/mkv/matroska_segment_parse.cpp
+++ b/modules/demux/mkv/matroska_segment_parse.cpp
@@ -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;
     EbmlMaster  *m;
@@ -1117,6 +1117,7 @@ void matroska_segment_c::ParseCluster( )
         }
     }
 
-    i_start_time = cluster->GlobalTimecode() / 1000;
+    if( b_update_start_time )
+        i_start_time = cluster->GlobalTimecode() / 1000;
 }
 



More information about the vlc-commits mailing list