Skip to content

Commit 8f691a0

Browse files
themactepCopilot
andcommitted
fix: ensure strictly monotonic PTS within SPS/PPS/IDR triplets
SPS, PPS and IDR NAL units in a single GetStream() call all share the same imp_ts (taken from the last pack in the group). In IMPDeviceSource this caused all three to compute the same delta_us and therefore receive identical fPresentationTime values, producing duplicate RTP timestamps that mpv reports as 'Invalid video timestamp: X -> X'. Change the backward-jitter clamp from strict less-than to less-than-or- equal and advance delta_us by 12 µs (one 90 kHz tick) per repeated timestamp. This gives each NAL in the triplet a unique, still strictly monotonic PTS without altering the perceived frame rate or reanchoring the wall-clock base. Also remove the temporary per-frame GetStream debug logging added during root-cause investigation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 92eee4a commit 8f691a0

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/IMPDeviceSource.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,14 @@ template <typename FrameType, typename Stream> void IMPDeviceSource<FrameType, S
110110
gettimeofday(&videoBaseTime, NULL);
111111
videoFirstImpTs = nal.imp_ts;
112112
delta_us = 0;
113-
} else if (videoLastDelta >= 0 && delta_us < videoLastDelta) {
114-
// Clamp small backward jitter (<500ms) to keep PTS monotonically
115-
// non-decreasing without re-anchoring the wall-clock base.
116-
delta_us = videoLastDelta;
113+
} else if (videoLastDelta >= 0 && delta_us <= videoLastDelta) {
114+
// Clamp small backward jitter (<500ms) to keep PTS strictly
115+
// monotonically increasing. The <= also handles the SPS/PPS/IDR
116+
// triplet where all three NALs share the same imp_ts (delta_us ==
117+
// videoLastDelta): each gets nudged forward by one 90 kHz tick
118+
// (≈11 µs) so the RTP sender never emits two packets with the
119+
// same timestamp.
120+
delta_us = videoLastDelta + 12;
117121
}
118122
videoLastDelta = delta_us;
119123
fPresentationTime.tv_sec = videoBaseTime.tv_sec + static_cast<time_t>(delta_us / 1000000LL);

0 commit comments

Comments
 (0)