[vlc-devel] [PATCH] MKV: fix mixup between VLC timestamps and Matroska timestamps

Steve Lhomme robUx4 at videolabs.io
Mon Mar 16 09:07:22 CET 2015


---
 modules/demux/mkv/demux.hpp            |  6 +++---
 modules/demux/mkv/matroska_segment.cpp | 16 ++++++++--------
 modules/demux/mkv/mkv.cpp              |  7 ++++---
 modules/demux/mkv/virtual_segment.cpp  |  7 ++++---
 4 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/modules/demux/mkv/demux.hpp b/modules/demux/mkv/demux.hpp
index f6b910b..eaefa95 100644
--- a/modules/demux/mkv/demux.hpp
+++ b/modules/demux/mkv/demux.hpp
@@ -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)
diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp
index acfc321..c2802e1 100644
--- a/modules/demux/mkv/matroska_segment.cpp
+++ b/modules/demux/mkv/matroska_segment.cpp
@@ -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 );
 
diff --git a/modules/demux/mkv/mkv.cpp b/modules/demux/mkv/mkv.cpp
index 5e183b9..c7f6a44 100644
--- a/modules/demux/mkv/mkv.cpp
+++ b/modules/demux/mkv/mkv.cpp
@@ -755,7 +755,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;
@@ -771,9 +771,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++)
diff --git a/modules/demux/mkv/virtual_segment.cpp b/modules/demux/mkv/virtual_segment.cpp
index ffd83fa..6b5e556 100644
--- a/modules/demux/mkv/virtual_segment.cpp
+++ b/modules/demux/mkv/virtual_segment.cpp
@@ -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;
-- 
2.3.2




More information about the vlc-devel mailing list