]> git.sesse.net Git - vlc/commitdiff
MKV: fix mixup between VLC timestamps and Matroska timestamps
authorSteve Lhomme <robUx4@videolabs.io>
Mon, 16 Mar 2015 08:07:22 +0000 (09:07 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Mon, 16 Mar 2015 09:11:30 +0000 (10:11 +0100)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/demux/mkv/demux.hpp
modules/demux/mkv/matroska_segment.cpp
modules/demux/mkv/mkv.cpp
modules/demux/mkv/virtual_segment.cpp

index f6b910bfffbd6b58ac0d2d8ea6e3e2cdb3e1044f..eaefa957fac975acb50c5fc5c267f9563d0e97a7 100644 (file)
@@ -331,9 +331,9 @@ struct demux_sys_t
 public:
     demux_sys_t( demux_t & demux )
         :demuxer(demux)
-        ,i_pts(0)
-        ,i_pcr(0)
-        ,i_start_pts(0)
+        ,i_pts(VLC_TS_INVALID)
+        ,i_pcr(VLC_TS_INVALID)
+        ,i_start_pts(VLC_TS_0)
         ,i_chapter_time(0)
         ,meta(NULL)
         ,i_current_title(0)
index acfc321883bf3f8964fee996a3bf4411baf075a3..c2802e1eaba9ddf6e8a38f22059b22f0aed35782 100644 (file)
@@ -942,9 +942,9 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_
         ep = new EbmlParser( &es, segment, &sys.demuxer,
                              var_InheritBool( &sys.demuxer, "mkv-use-dummy" ) );
         cluster = NULL;
-        sys.i_start_pts = 0;
-        sys.i_pts = 0;
-        sys.i_pcr = 0;
+        sys.i_start_pts = VLC_TS_0;
+        sys.i_pts = VLC_TS_INVALID;
+        sys.i_pcr = VLC_TS_0;
         return;
     }
 
@@ -972,7 +972,7 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_
                          var_InheritBool( &sys.demuxer, "mkv-use-dummy" ) );
     cluster = NULL;
 
-    sys.i_start_pts = i_date;
+    sys.i_start_pts = i_date + VLC_TS_0;
 
     /* now parse until key frame */
     const int es_types[3] = { VIDEO_ES, AUDIO_ES, SPU_ES };
@@ -1024,7 +1024,7 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_
     /*Neither video nor audio track... no seek further*/
     if( unlikely( !p_first ) )
     {
-        es_out_Control( sys.demuxer.out, ES_OUT_SET_PCR, i_date );
+        es_out_Control( sys.demuxer.out, ES_OUT_SET_PCR, i_date + VLC_TS_0 );
         es_out_Control( sys.demuxer.out, ES_OUT_SET_NEXT_DISPLAY_TIME, i_date );
         return;
     }
@@ -1101,8 +1101,8 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_
         if( p_last->i_date < p_min->i_date )
             p_min = p_last;
 
-    sys.i_pcr = sys.i_pts = p_min->i_date;
-    es_out_Control( sys.demuxer.out, ES_OUT_SET_PCR, VLC_TS_0 + sys.i_pcr );
+    sys.i_pcr = sys.i_pts = p_min->i_date + VLC_TS_0;
+    es_out_Control( sys.demuxer.out, ES_OUT_SET_PCR, sys.i_pcr );
     es_out_Control( sys.demuxer.out, ES_OUT_SET_NEXT_DISPLAY_TIME, i_date );
     cluster = (KaxCluster *) ep->UnGet( p_min->i_seek_pos, p_min->i_cluster_pos );
 
@@ -1338,7 +1338,7 @@ bool matroska_segment_c::Select( mtime_t i_start_time )
     }
     es_out_Control( sys.demuxer.out, ES_OUT_SET_NEXT_DISPLAY_TIME, i_start_time );
 
-    sys.i_start_pts = i_start_time;
+    sys.i_start_pts = i_start_time + VLC_TS_0;
     // reset the stream reading to the first cluster of the segment used
     es.I_O().setFilePointer( i_start_pos );
 
index 02693933479a77abaa7655a4d7eb25b74669dd61..dfb59d9b018bef946b8a078f2b8c3bd716acf49d 100644 (file)
@@ -757,7 +757,7 @@ static int Demux( demux_t *p_demux)
                 {
                     /* TODO handle successive chapters with the same user_start_time/user_end_time
                     */
-                    p_sys->i_pts = p_chap->i_virtual_stop_time;
+                    p_sys->i_pts = p_chap->i_virtual_stop_time + VLC_TS_0;
                     p_sys->i_pts++; // trick to avoid staying on segments with no duration and no content
 
                     i_return = 1;
@@ -773,9 +773,10 @@ static int Demux( demux_t *p_demux)
         }
 
         if( simpleblock != NULL )
-            p_sys->i_pts = p_sys->i_chapter_time + ( (mtime_t)simpleblock->GlobalTimecode() / INT64_C(1000) );
+            p_sys->i_pts = (mtime_t)simpleblock->GlobalTimecode() / INT64_C(1000);
         else
-            p_sys->i_pts = p_sys->i_chapter_time + ( (mtime_t)block->GlobalTimecode() / INT64_C(1000) );
+            p_sys->i_pts = (mtime_t)block->GlobalTimecode() / INT64_C(1000);
+        p_sys->i_pts += p_sys->i_chapter_time + VLC_TS_0;
 
         mtime_t i_pcr = VLC_TS_INVALID;
         for( size_t i = 0; i < p_segment->tracks.size(); i++)
index ffd83fad04dff41c67ff04ad5d1e3e19c5527121..6b5e556653a781b720c1ee81addfb84d9301a373 100644 (file)
@@ -399,12 +399,13 @@ virtual_chapter_c* virtual_edition_c::getChapterbyTimecode( int64_t time )
 bool virtual_segment_c::UpdateCurrentToChapter( demux_t & demux )
 {
     demux_sys_t & sys = *demux.p_sys;
-    virtual_chapter_c *p_cur_chapter;
+    virtual_chapter_c *p_cur_chapter = NULL;
     virtual_edition_c * p_cur_edition = editions[ i_current_edition ];
 
     bool b_has_seeked = false;
 
-    p_cur_chapter = p_cur_edition->getChapterbyTimecode( sys.i_pts );
+    if ( sys.i_pts != VLC_TS_INVALID )
+        p_cur_chapter = p_cur_edition->getChapterbyTimecode( sys.i_pts - VLC_TS_0 );
 
     /* we have moved to a new chapter */
     if ( p_cur_chapter != NULL && p_current_chapter != p_cur_chapter )
@@ -426,7 +427,7 @@ bool virtual_segment_c::UpdateCurrentToChapter( demux_t & demux )
                         return true;
                     }
                 }
-                sys.i_start_pts = p_cur_chapter->i_virtual_start_time;;
+                sys.i_start_pts = p_cur_chapter->i_virtual_start_time + VLC_TS_0;
             }
 
             p_current_chapter = p_cur_chapter;