[vlc-commits] [Git][videolan/vlc][3.0.x] demux: mkv: shift the timestamps based on the biggest CodecDelay

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Dec 2 16:27:21 UTC 2021



Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC


Commits:
576630ee by Steve Lhomme at 2021-12-02T16:05:31+00:00
demux: mkv: shift the timestamps based on the biggest CodecDelay

The CodecDelay needs to be substracted from the PTS of all frames of that
track. That may result in negative DTS, PTS and PCR which is not well handled.
So we just shift all timestamps based on the biggest CodecDelay so all
timestamps are always positive.

This is in line with how libavformat reports the timestamps on frames from a
track with a CodecDelay.

This is done per segment as other segments may use a different CodecDelay
per track.

Fixes #25129

(cherry picked from commit 450363175621f1b6893a8cc833508b5129bfd938) (edited)
edited:
- 3.0 uses mtime_t instead of vlc_tick_t

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -


3 changed files:

- modules/demux/mkv/matroska_segment.hpp
- modules/demux/mkv/matroska_segment_parse.cpp
- modules/demux/mkv/mkv.cpp


Changes:

=====================================
modules/demux/mkv/matroska_segment.hpp
=====================================
@@ -96,6 +96,7 @@ public:
     /* all tracks */
     tracks_map_t tracks;
     SegmentSeeker::track_ids_t priority_tracks;
+    mtime_t                  pcr_shift = 0;
 
     /* from seekhead */
     int                     i_seekhead_count;


=====================================
modules/demux/mkv/matroska_segment_parse.cpp
=====================================
@@ -965,6 +965,12 @@ void matroska_segment_c::ParseTracks( KaxTracks *tracks )
     };
 
     TrackHandlers::Dispatcher().iterate( tracks->begin(), tracks->end(), &payload );
+
+    auto t = matroska_segment_c::tracks.begin();
+    for (t; t != matroska_segment_c::tracks.end(); ++t)
+    {
+        pcr_shift = std::max(pcr_shift, t->second->i_codec_delay);
+    }
 }
 
 /*****************************************************************************


=====================================
modules/demux/mkv/mkv.cpp
=====================================
@@ -512,7 +512,8 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
         return;
     }
 
-    i_pts -= track.i_codec_delay;
+    if (i_pts != VLC_TS_INVALID)
+        i_pts += p_segment->pcr_shift - track.i_codec_delay;
 
     if ( track.fmt.i_cat != DATA_ES )
     {



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/576630ee395d25d506e01a9a21de4475381644ec

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/576630ee395d25d506e01a9a21de4475381644ec
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list