[vlc-devel] [PATCH] MKV: split time values between container ones and VLC ones (shifted)

Steve Lhomme robUx4 at videolabs.io
Fri Mar 13 16:45:29 CET 2015


mkv_time_t is a time/offset coming from the Matroska stream

ts_time_t is a time reported to VLC which can be VLC_INVALID_TS and
otherwise is shifted by VLC_TS_0

Do the (un)shift when appropriate.
mtime_t should not be used anymore in the demuxer to avoid confusion.
---
 modules/demux/mkv/chapters.hpp               |  2 +-
 modules/demux/mkv/demux.hpp                  | 14 ++++----
 modules/demux/mkv/matroska_segment.cpp       | 50 ++++++++++++++--------------
 modules/demux/mkv/matroska_segment.hpp       |  8 ++---
 modules/demux/mkv/matroska_segment_parse.cpp |  7 ++--
 modules/demux/mkv/mkv.cpp                    | 30 +++++++++--------
 modules/demux/mkv/mkv.hpp                    | 20 ++++++-----
 modules/demux/mkv/util.cpp                   |  2 +-
 modules/demux/mkv/util.hpp                   |  2 +-
 modules/demux/mkv/virtual_segment.cpp        | 31 ++++++++---------
 modules/demux/mkv/virtual_segment.hpp        | 18 +++++-----
 11 files changed, 95 insertions(+), 89 deletions(-)

diff --git a/modules/demux/mkv/chapters.hpp b/modules/demux/mkv/chapters.hpp
index 8d0e592..43ff509 100644
--- a/modules/demux/mkv/chapters.hpp
+++ b/modules/demux/mkv/chapters.hpp
@@ -72,7 +72,7 @@ public:
     bool                        ParentOf( const chapter_item_c & item ) const;
     int16                       GetTitleNumber( ) const;
 
-    int64_t                     i_start_time, i_end_time;
+    mkv_time_t                  i_start_time, i_end_time;
     std::vector<chapter_item_c*> sub_chapters;
     KaxChapterSegmentUID        *p_segment_uid;
     KaxChapterSegmentEditionUID *p_segment_edition_uid;
diff --git a/modules/demux/mkv/demux.hpp b/modules/demux/mkv/demux.hpp
index f6b910b..1574a64 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)
@@ -351,10 +351,10 @@ public:
     /* current data */
     demux_t                 & demuxer;
 
-    mtime_t                 i_pts;
-    mtime_t                 i_pcr;
-    mtime_t                 i_start_pts;
-    mtime_t                 i_chapter_time;
+    ts_time_t               i_pts;
+    ts_time_t               i_pcr;
+    ts_time_t               i_start_pts;
+    mkv_time_t              i_chapter_time;
 
     vlc_meta_t              *meta;
 
diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp
index acfc321..9690e26 100644
--- a/modules/demux/mkv/matroska_segment.cpp
+++ b/modules/demux/mkv/matroska_segment.cpp
@@ -154,7 +154,7 @@ void matroska_segment_c::LoadCues( KaxCues *cues )
                         b_invalid_cue = true;
                         break;
                     }
-                    idx.i_time = uint64( ctime ) * i_timescale / (mtime_t)1000;
+                    idx.i_time = uint64( ctime ) * i_timescale / (mkv_time_t)1000;
                 }
                 else if( MKV_IS_ID( el, KaxCueTrackPositions ) )
                 {
@@ -598,7 +598,7 @@ void matroska_segment_c::IndexAppendCluster( KaxCluster *cluster )
     idx.i_track       = -1;
     idx.i_block_number= -1;
     idx.i_position    = cluster->GetElementPosition();
-    idx.i_time        = cluster->GlobalTimecode()/ (mtime_t) 1000;
+    idx.i_time        = cluster->GlobalTimecode()/ (mkv_time_t) 1000;
     idx.b_key         = true;
 
     i_index++;
@@ -868,25 +868,25 @@ bool matroska_segment_c::LoadSeekHeadItem( const EbmlCallbacks & ClassInfos, int
 
 struct spoint
 {
-    spoint(unsigned int tk, mtime_t date, int64_t pos, int64_t cpos):
+    spoint(unsigned int tk, mkv_time_t date, int64_t pos, int64_t cpos):
         i_track(tk),i_date(date), i_seek_pos(pos),
         i_cluster_pos(cpos), p_next(NULL){}
     unsigned int     i_track;
-    mtime_t i_date;
-    int64_t i_seek_pos;
-    int64_t i_cluster_pos;
-    spoint * p_next;
+    mkv_time_t       i_date;
+    int64_t          i_seek_pos;
+    int64_t          i_cluster_pos;
+    spoint           *p_next;
 };
 
-void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_global_position )
+void matroska_segment_c::Seek( mkv_time_t i_date, mkv_time_t i_time_offset, int64_t i_global_position )
 {
     KaxBlock    *block;
     KaxSimpleBlock *simpleblock;
     int64_t     i_block_duration;
     size_t      i_track;
     int64_t     i_seek_position = i_start_pos;
-    int64_t     i_seek_time = i_start_time;
-    mtime_t     i_pts = 0;
+    mkv_time_t  i_seek_time = i_start_time;
+    mkv_time_t  i_pts = 0;
     spoint *p_first = NULL;
     spoint *p_last = NULL;
     int i_cat;
@@ -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,12 +972,12 @@ 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 };
     i_cat = es_types[0];
-    mtime_t i_seek_preroll = 0;
+    mkv_time_t i_seek_preroll = 0;
     for( int i = 0; i < 2; i_cat = es_types[++i] )
     {
         for( i_track = 0; i_track < tracks.size(); i_track++ )
@@ -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;
     }
@@ -1056,9 +1056,9 @@ void matroska_segment_c::Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_
             }
 
             if( simpleblock )
-                i_pts = sys.i_chapter_time + simpleblock->GlobalTimecode() / (mtime_t) 1000;
+                i_pts = sys.i_chapter_time + simpleblock->GlobalTimecode() / (mkv_time_t) 1000;
             else
-                i_pts = sys.i_chapter_time + block->GlobalTimecode() / (mtime_t) 1000;
+                i_pts = sys.i_chapter_time + block->GlobalTimecode() / (mkv_time_t) 1000;
             if( i_track < tracks.size() )
             {
                 if( tracks[i_track]->fmt.i_cat == i_cat && b_key_picture )
@@ -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 );
 
@@ -1294,7 +1294,7 @@ void matroska_segment_c::EnsureDuration()
             }
         }
 
-        i_duration = ( i_last_timecode - cluster->GlobalTimecode() ) / (mtime_t)1000000;
+        i_duration = ( i_last_timecode - cluster->GlobalTimecode() ) / (mkv_time_t)1000000;
         msg_Dbg( &sys.demuxer, " extracted Duration=%" PRId64, i_duration );
 
         delete ep;
@@ -1304,7 +1304,7 @@ void matroska_segment_c::EnsureDuration()
     es.I_O().setFilePointer( i_current_position, seek_beginning );
 }
 
-bool matroska_segment_c::Select( mtime_t i_start_time )
+bool matroska_segment_c::Select( mkv_time_t i_start_time )
 {
     /* add all es */
     msg_Dbg( &sys.demuxer, "found %d es", (int)tracks.size() );
@@ -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 );
 
@@ -1427,9 +1427,9 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
             if( i_index > 0 && idx.i_time == -1 )
             {
                 if ( pp_simpleblock != NULL )
-                    idx.i_time        = pp_simpleblock->GlobalTimecode() / (mtime_t)1000;
+                    idx.i_time        = pp_simpleblock->GlobalTimecode() / (mkv_time_t)1000;
                 else
-                    idx.i_time        = (*pp_block).GlobalTimecode() / (mtime_t)1000;
+                    idx.i_time        = (*pp_block).GlobalTimecode() / (mkv_time_t)1000;
                 idx.b_key         = *pb_key_picture;
             }
 #undef idx
diff --git a/modules/demux/mkv/matroska_segment.hpp b/modules/demux/mkv/matroska_segment.hpp
index e29d8dd..b19668f 100644
--- a/modules/demux/mkv/matroska_segment.hpp
+++ b/modules/demux/mkv/matroska_segment.hpp
@@ -82,8 +82,8 @@ public:
     uint64_t                i_timescale;
 
     /* duration of the segment */
-    mtime_t                 i_duration;
-    mtime_t                 i_start_time;
+    mkv_time_t              i_duration;
+    mkv_time_t              i_start_time;
 
     /* all tracks */
     std::vector<mkv_track_t*> tracks;
@@ -136,13 +136,13 @@ public:
     bool Preload();
     bool PreloadFamily( const matroska_segment_c & segment );
     void InformationCreate();
-    void Seek( mtime_t i_date, mtime_t i_time_offset, int64_t i_global_position );
+    void Seek( mkv_time_t i_date, mkv_time_t i_time_offset, int64_t i_global_position );
     int BlockGet( KaxBlock * &, KaxSimpleBlock * &, bool *, bool *, int64_t *);
 
     int BlockFindTrackIndex( size_t *pi_track,
                              const KaxBlock *, const KaxSimpleBlock * );
 
-    bool Select( mtime_t i_start_time );
+    bool Select( mkv_time_t i_start_time );
     void UnSelect();
 
     static bool CompareSegmentUIDs( const matroska_segment_c * item_a, const matroska_segment_c * item_b );
diff --git a/modules/demux/mkv/matroska_segment_parse.cpp b/modules/demux/mkv/matroska_segment_parse.cpp
index 9b82d4c..fd07530 100644
--- a/modules/demux/mkv/matroska_segment_parse.cpp
+++ b/modules/demux/mkv/matroska_segment_parse.cpp
@@ -336,9 +336,8 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
         {
             KaxTrackDefaultDuration &defd = *(KaxTrackDefaultDuration*)l;
 
-            tk->i_default_duration = uint64(defd);
+            tk->i_default_duration = uint64(defd) / (mkv_time_t)1000;
             msg_Dbg( &sys.demuxer, "|   |   |   + Track Default Duration=%" PRId64, tk->i_default_duration );
-            tk->i_default_duration /= 1000;
         }
         else  if( MKV_IS_ID( l, KaxTrackTimecodeScale ) )
         {
@@ -848,7 +847,7 @@ void matroska_segment_c::ParseInfo( KaxInfo *info )
         {
             KaxDuration &dur = *(KaxDuration*)l;
 
-            i_duration = mtime_t( double( dur ) );
+            i_duration = mkv_time_t( double( dur ) );
 
             msg_Dbg( &sys.demuxer, "|   |   + Duration=%" PRId64,
                      i_duration );
@@ -958,7 +957,7 @@ void matroska_segment_c::ParseInfo( KaxInfo *info )
     }
 
     double f_dur = double(i_duration) * double(i_timescale) / 1000000.0;
-    i_duration = mtime_t(f_dur);
+    i_duration = mkv_time_t(f_dur);
     if( !i_duration ) i_duration = -1;
 }
 
diff --git a/modules/demux/mkv/mkv.cpp b/modules/demux/mkv/mkv.cpp
index 5e183b9..4824c23 100644
--- a/modules/demux/mkv/mkv.cpp
+++ b/modules/demux/mkv/mkv.cpp
@@ -81,7 +81,7 @@ struct demux_sys_t;
 
 static int  Demux  ( demux_t * );
 static int  Control( demux_t *, int, va_list );
-static void Seek   ( demux_t *, mtime_t i_date, double f_percent, virtual_chapter_c *p_chapter );
+static void Seek   ( demux_t *, mkv_time_t i_date, double f_percent, virtual_chapter_c *p_chapter );
 
 /*****************************************************************************
  * Open: initializes matroska demux structures
@@ -332,7 +332,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
         case DEMUX_GET_POSITION:
             pf = (double*)va_arg( args, double * );
             if ( p_sys->f_duration > 0.0 )
-                *pf = (double)(p_sys->i_pts >= p_sys->i_start_pts ? p_sys->i_pts : p_sys->i_start_pts ) / (1000.0 * p_sys->f_duration);
+                *pf = (double)((p_sys->i_pts >= p_sys->i_start_pts ? p_sys->i_pts : p_sys->i_start_pts ) - VLC_TS_0) /
+                    (1000.0 * p_sys->f_duration);
             return VLC_SUCCESS;
 
         case DEMUX_SET_POSITION:
@@ -346,7 +347,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 
         case DEMUX_GET_TIME:
             pi64 = (int64_t*)va_arg( args, int64_t * );
-            *pi64 = p_sys->i_pts;
+            *pi64 = p_sys->i_pts - VLC_TS_0;
             return VLC_SUCCESS;
 
         case DEMUX_GET_TITLE_INFO:
@@ -424,7 +425,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 }
 
 /* Seek */
-static void Seek( demux_t *p_demux, mtime_t i_date, double f_percent, virtual_chapter_c *p_chapter )
+static void Seek( demux_t *p_demux, mkv_time_t i_date, double f_percent, virtual_chapter_c *p_chapter )
 {
     demux_sys_t        *p_sys = p_demux->p_sys;
     virtual_segment_c  *p_vsegment = p_sys->p_current_segment;
@@ -485,7 +486,7 @@ static void Seek( demux_t *p_demux, mtime_t i_date, double f_percent, virtual_ch
 
 /* Needed by matroska_segment::Seek() and Seek */
 void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock,
-                  mtime_t i_pts, mtime_t i_duration, bool b_key_picture,
+                  ts_time_t i_pts, mkv_time_t i_duration, bool b_key_picture,
                   bool b_discardable_picture )
 {
     demux_sys_t        *p_sys = p_demux->p_sys;
@@ -603,7 +604,7 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
             handle_real_audio(p_demux, tk, p_block, i_pts);
             block_Release(p_block);
             i_pts = ( tk->i_default_duration )?
-                i_pts + ( mtime_t )tk->i_default_duration:
+                i_pts + tk->i_default_duration:
                 VLC_TS_INVALID;
             continue;
          }
@@ -622,7 +623,7 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
             break;
 
          case VLC_CODEC_OPUS:
-            mtime_t i_length = i_duration * tk-> f_timecodescale *
+            mkv_time_t i_length = i_duration * tk-> f_timecodescale *
                     (double) p_segment->i_timescale / 1000.0;
             if ( i_length < 0 ) i_length = 0;
             p_block->i_nb_samples = i_length * tk->fmt.audio.i_rate
@@ -671,8 +672,10 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
                 // condition when the DTS is correct (keyframe or B frame == NOT P frame)
                 if ( b_key_picture || b_discardable_picture )
                     p_block->i_dts = p_block->i_pts;
+                else if ( tk->i_last_dts == VLC_TS_INVALID )
+                    p_block->i_dts = i_pts;
                 else
-                    p_block->i_dts = min( i_pts, tk->i_last_dts + ( mtime_t )tk->i_default_duration );
+                    p_block->i_dts = min( i_pts, tk->i_last_dts + tk->i_default_duration );
             }
         }
         if( p_block->i_dts > VLC_TS_INVALID &&
@@ -700,7 +703,7 @@ msg_Dbg( p_demux, "block (track=%d) i_dts: %"PRId64" / i_pts: %"PRId64, tk->i_nu
 
         /* use time stamp only for first block */
         i_pts = ( tk->i_default_duration )?
-                 i_pts + ( mtime_t )tk->i_default_duration:
+                 i_pts + tk->i_default_duration:
                  VLC_TS_INVALID;
     }
 }
@@ -755,7 +758,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 +774,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 = (ts_time_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 = (ts_time_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++)
@@ -783,7 +787,7 @@ static int Demux( demux_t *p_demux)
 
         if( i_pcr > p_sys->i_pcr + 300000 )
         {
-            es_out_Control( p_demux->out, ES_OUT_SET_PCR, VLC_TS_0 + p_sys->i_pcr );
+            es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_pcr );
             p_sys->i_pcr = i_pcr;
         }
 
diff --git a/modules/demux/mkv/mkv.hpp b/modules/demux/mkv/mkv.hpp
index 4e2963e..83cb3a8 100644
--- a/modules/demux/mkv/mkv.hpp
+++ b/modules/demux/mkv/mkv.hpp
@@ -120,12 +120,14 @@ enum
 
 #define MKV_IS_ID( el, C ) ( el != NULL && typeid( *el ) == typeid( C ) )
 
+typedef mtime_t ts_time_t;   // VLC time shifted by VLC_TS_0
+typedef int64   mkv_time_t;  // time as written in the stream in microseconds
 
 using namespace LIBMATROSKA_NAMESPACE;
 using namespace std;
 
 void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock,
-                  mtime_t i_pts, mtime_t i_duration, bool b_key_picture,
+                  ts_time_t i_pts, mkv_time_t i_duration, bool b_key_picture,
                   bool b_discardable_picture );
 
 class attachment_c
@@ -200,9 +202,9 @@ struct mkv_track_t
     bool         b_pts_only;
 
     bool         b_no_duration;
-    uint64_t     i_default_duration;
+    mkv_time_t   i_default_duration;
     float        f_timecodescale;
-    mtime_t      i_last_dts;
+    ts_time_t    i_last_dts;
 
     /* video */
     es_format_t fmt;
@@ -239,18 +241,18 @@ struct mkv_track_t
     KaxContentCompSettings *p_compression_data;
 
     /* Matroska 4 new elements used by Opus */
-    mtime_t i_seek_preroll;
-    mtime_t i_codec_delay;
+    mkv_time_t i_seek_preroll;
+    mkv_time_t i_codec_delay;
 
 };
 
 struct mkv_index_t
 {
-    int     i_track;
-    int     i_block_number;
+    int        i_track;
+    int        i_block_number;
 
-    int64_t i_position;
-    int64_t i_time;
+    int64_t    i_position;
+    mkv_time_t i_time;
 
     bool       b_key;
 };
diff --git a/modules/demux/mkv/util.cpp b/modules/demux/mkv/util.cpp
index 8f84d94..21102ad 100644
--- a/modules/demux/mkv/util.cpp
+++ b/modules/demux/mkv/util.cpp
@@ -168,7 +168,7 @@ block_t *MemToBlock( uint8_t *p_mem, size_t i_mem, size_t offset)
 }
 
 
-void handle_real_audio(demux_t * p_demux, mkv_track_t * p_tk, block_t * p_blk, mtime_t i_pts)
+void handle_real_audio(demux_t * p_demux, mkv_track_t * p_tk, block_t * p_blk, ts_time_t i_pts)
 {
     uint8_t * p_frame = p_blk->p_buffer;
     Cook_PrivateTrackData * p_sys = (Cook_PrivateTrackData *) p_tk->p_sys;
diff --git a/modules/demux/mkv/util.hpp b/modules/demux/mkv/util.hpp
index c181ad2..a062372 100644
--- a/modules/demux/mkv/util.hpp
+++ b/modules/demux/mkv/util.hpp
@@ -31,7 +31,7 @@ block_t *block_zlib_decompress( vlc_object_t *p_this, block_t *p_in_block );
 #endif
 
 block_t *MemToBlock( uint8_t *p_mem, size_t i_mem, size_t offset);
-void handle_real_audio(demux_t * p_demux, mkv_track_t * p_tk, block_t * p_blk, mtime_t i_pts);
+void handle_real_audio(demux_t * p_demux, mkv_track_t * p_tk, block_t * p_blk, ts_time_t i_pts);
 
 
 struct real_audio_private
diff --git a/modules/demux/mkv/virtual_segment.cpp b/modules/demux/mkv/virtual_segment.cpp
index ffd83fa..4b90cc7 100644
--- a/modules/demux/mkv/virtual_segment.cpp
+++ b/modules/demux/mkv/virtual_segment.cpp
@@ -41,7 +41,7 @@ matroska_segment_c * getSegmentbyUID( KaxSegmentUID * p_uid, std::vector<matrosk
 virtual_chapter_c * virtual_chapter_c::CreateVirtualChapter( chapter_item_c * p_chap,
                                                              matroska_segment_c * p_main_segment,
                                                              std::vector<matroska_segment_c*> * segments,
-                                                             int64_t * usertime_offset, bool b_ordered)
+                                                             mkv_time_t * usertime_offset, bool b_ordered)
 {
     matroska_segment_c * p_segment = p_main_segment;
 
@@ -51,8 +51,8 @@ virtual_chapter_c * virtual_chapter_c::CreateVirtualChapter( chapter_item_c * p_
         return new virtual_chapter_c( p_segment, NULL, 0, p_segment->i_duration*1000 );
     }
 
-    int64_t start = ( b_ordered )? *usertime_offset : p_chap->i_start_time;
-    int64_t stop = ( b_ordered )? ( *usertime_offset + p_chap->i_end_time - p_chap->i_start_time ) : p_chap->i_end_time;
+    mkv_time_t start = ( b_ordered )? *usertime_offset : p_chap->i_start_time;
+    mkv_time_t stop = ( b_ordered )? ( *usertime_offset + p_chap->i_end_time - p_chap->i_start_time ) : p_chap->i_end_time;
 
     if( p_chap->p_segment_uid &&
        ( !( p_segment = getSegmentbyUID( (KaxSegmentUID*) p_chap->p_segment_uid,segments ) ) || !b_ordered ) )
@@ -72,7 +72,7 @@ virtual_chapter_c * virtual_chapter_c::CreateVirtualChapter( chapter_item_c * p_
     if( !p_vchap )
         return NULL;
 
-    int64_t tmp = *usertime_offset;
+    mkv_time_t tmp = *usertime_offset;
 
     for( size_t i = 0; i < p_chap->sub_chapters.size(); i++ )
     {
@@ -108,7 +108,7 @@ virtual_edition_c::virtual_edition_c( chapter_edition_c * p_edit, std::vector<ma
     p_edition = p_edit;
     b_ordered = false;
 
-    int64_t usertime_offset = 0;
+    mkv_time_t usertime_offset = 0;
 
     /* ordered chapters */
     if( p_edition && p_edition->b_ordered )
@@ -131,7 +131,7 @@ virtual_edition_c::virtual_edition_c( chapter_edition_c * p_edit, std::vector<ma
     {
         matroska_segment_c * p_cur = p_main_segment;
         virtual_chapter_c * p_vchap = NULL;
-        int64_t tmp = 0;
+        mkv_time_t tmp = 0;
 
         /* check for prev linked segments */
         /* FIXME to avoid infinite recursion we limit to 10 prev should be better as parameter */
@@ -222,7 +222,7 @@ virtual_edition_c::~virtual_edition_c()
 
 void virtual_edition_c::retimeSubChapters( virtual_chapter_c * p_vchap )
 {
-    int64_t stop_time = p_vchap->i_virtual_stop_time;
+    mkv_time_t stop_time = p_vchap->i_virtual_stop_time;
     for( size_t i = p_vchap->sub_chapters.size(); i-- > 0; )
     {
         virtual_chapter_c * p_vsubchap = p_vchap->sub_chapters[i];
@@ -372,7 +372,7 @@ virtual_chapter_c * virtual_chapter_c::BrowseCodecPrivate( unsigned int codec_id
     return NULL;
 }
 
-virtual_chapter_c* virtual_chapter_c::getSubChapterbyTimecode( int64_t time )
+virtual_chapter_c* virtual_chapter_c::getSubChapterbyTimecode( mkv_time_t time )
 {
     for( size_t i = 0; i < sub_chapters.size(); i++ )
     {
@@ -383,7 +383,7 @@ virtual_chapter_c* virtual_chapter_c::getSubChapterbyTimecode( int64_t time )
     return this;
 }
 
-virtual_chapter_c* virtual_edition_c::getChapterbyTimecode( int64_t time )
+virtual_chapter_c* virtual_edition_c::getChapterbyTimecode( mkv_time_t time )
 {
     for( size_t i = 0; i < chapters.size(); i++ )
     {
@@ -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;
@@ -462,7 +463,7 @@ bool virtual_chapter_c::EnterAndLeave( virtual_chapter_c *p_item, bool b_enter )
     return p_chapter->EnterAndLeave( p_item->p_chapter, b_enter );
 }
 
-void virtual_segment_c::Seek( demux_t & demuxer, mtime_t i_date,
+void virtual_segment_c::Seek( demux_t & demuxer, mkv_time_t i_date,
                               virtual_chapter_c *p_chapter, int64_t i_global_position )
 {
     demux_sys_t *p_sys = demuxer.p_sys;
@@ -475,7 +476,7 @@ void virtual_segment_c::Seek( demux_t & demuxer, mtime_t i_date,
 
     if ( p_chapter != NULL )
     {
-        mtime_t i_time_offset = p_chapter->i_virtual_start_time - ( ( p_chapter->p_chapter )? p_chapter->p_chapter->i_start_time : 0 );
+        mkv_time_t i_time_offset = p_chapter->i_virtual_start_time - ( ( p_chapter->p_chapter )? p_chapter->p_chapter->i_start_time : 0 );
         p_sys->i_chapter_time = i_time_offset - p_chapter->p_segment->i_start_time;
         if ( p_chapter->p_chapter && p_chapter->i_seekpoint_num > 0 )
         {
@@ -620,7 +621,7 @@ void virtual_chapter_c::print()
 }
 #endif
 
-void virtual_segment_c::ChangeSegment( matroska_segment_c * p_old, matroska_segment_c * p_new, mtime_t i_start_time )
+void virtual_segment_c::ChangeSegment( matroska_segment_c * p_old, matroska_segment_c * p_new, mkv_time_t i_start_time )
 {
     size_t i, j;
     char *sub_lang = NULL, *aud_lang = NULL;
diff --git a/modules/demux/mkv/virtual_segment.hpp b/modules/demux/mkv/virtual_segment.hpp
index 5e9249b..da5e739 100644
--- a/modules/demux/mkv/virtual_segment.hpp
+++ b/modules/demux/mkv/virtual_segment.hpp
@@ -36,7 +36,7 @@
 class virtual_chapter_c
 {
 public:
-    virtual_chapter_c( matroska_segment_c *p_seg, chapter_item_c *p_chap, int64_t start, int64_t stop ):
+    virtual_chapter_c( matroska_segment_c *p_seg, chapter_item_c *p_chap, mkv_time_t start, mkv_time_t stop ):
         p_segment(p_seg), p_chapter(p_chap),
         i_virtual_start_time(start), i_virtual_stop_time(stop)
     {}
@@ -45,9 +45,9 @@ public:
     static virtual_chapter_c * CreateVirtualChapter( chapter_item_c * p_chap,
                                                      matroska_segment_c * p_main_segment,
                                                      std::vector<matroska_segment_c*> * segments,
-                                                     int64_t * usertime_offset, bool b_ordered );
+                                                     mkv_time_t * usertime_offset, bool b_ordered );
 
-    virtual_chapter_c* getSubChapterbyTimecode( int64_t time );
+    virtual_chapter_c* getSubChapterbyTimecode( mkv_time_t time );
     bool EnterAndLeave( virtual_chapter_c *p_item, bool b_enter = true );
     virtual_chapter_c * FindChapter( int64_t i_find_uid );
     int PublishChapters( input_title_t & title, int & i_user_chapters, int i_level );
@@ -68,8 +68,8 @@ public:
 
     matroska_segment_c  *p_segment;
     chapter_item_c      *p_chapter;
-    int64_t             i_virtual_start_time;
-    int64_t             i_virtual_stop_time;
+    mkv_time_t          i_virtual_start_time;
+    mkv_time_t          i_virtual_stop_time;
     int                 i_seekpoint_num;
     std::vector<virtual_chapter_c *> sub_chapters;
 #ifdef MKV_DEBUG
@@ -84,7 +84,7 @@ public:
     ~virtual_edition_c();
     std::vector<virtual_chapter_c*> chapters;
 
-    virtual_chapter_c* getChapterbyTimecode( int64_t time );
+    virtual_chapter_c* getChapterbyTimecode( mkv_time_t time );
     std::string GetMainName();
     int PublishChapters( input_title_t & title, int & i_user_chapters, int i_level );
     virtual_chapter_c * BrowseCodecPrivate( unsigned int codec_id,
@@ -94,7 +94,7 @@ public:
                                              const void *p_cookie, size_t i_cookie_size );
 
     bool                b_ordered;
-    int64_t             i_duration;
+    mkv_time_t          i_duration;
     chapter_edition_c   *p_edition;
     int                 i_seekpoint_num;
 
@@ -155,10 +155,10 @@ public:
     virtual_chapter_c * FindChapter( int64_t i_find_uid );
 
     bool UpdateCurrentToChapter( demux_t & demux );
-    void Seek( demux_t & demuxer, mtime_t i_date,
+    void Seek( demux_t & demuxer, mkv_time_t i_date,
                virtual_chapter_c *p_chapter, int64_t i_global_position );
 private:
-    void ChangeSegment( matroska_segment_c * p_old, matroska_segment_c * p_new, mtime_t i_start_time );
+    void ChangeSegment( matroska_segment_c * p_old, matroska_segment_c * p_new, mkv_time_t i_start_time );
 };
 
 #endif
-- 
2.3.2




More information about the vlc-devel mailing list