Skip to content

Commit 7267488

Browse files
committed
RED5DEV-2156 playengine: clamp negative late-subscriber adjusted timestamps
When PlayEngine pushes a buffered keyframe (or any prelude event) captured before the live anchor (videoBaseTs / audioBaseTs / publisher timestamp offset), the rebase formula eventTime - baseTs + 2 produces a negative result. The negative int writes to the wire as the equivalent unsigned-32 value, which RTMP clients render as a far-future timestamp (e.g. -97 ms -> 0xFFFFFF9F -> ~24.85 days when bit 31 is stripped, or ~49.7 days when read as full unsigned-32). Clamp negative adjusted timestamps to 1 so buffered events precede the first live frame at ts=2 without leaking into the unsigned-32 upper half. Verified via ffplay end-to-end against an SRT/TS publisher: video start went from 2147483.551s to 0.001s.
1 parent 68acc70 commit 7267488

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

common/src/main/java/org/red5/server/stream/PlayEngine.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,16 @@ private void sendMessage(RTMPMessage messageIn) {
11991199
eventTime -= startTs;
12001200
}
12011201
}
1202+
// Clamp negative adjusted timestamps. Buffered events (decoder configs, keyframes)
1203+
// captured before the live anchor land here with eventTime < 0; place them at ts=1
1204+
// so they precede the first live frame at ts=2 without being interpreted as a
1205+
// far-future unsigned-32 value (e.g. -97 on the wire = 0xFFFFFF9F = ~49.7 days).
1206+
if (eventTime < 0) {
1207+
if (isTrace) {
1208+
log.trace("sendMessage: clamping negative adjusted timestamp {} to 1 (buffered prelude before live anchor)", eventTime);
1209+
}
1210+
eventTime = 1;
1211+
}
12021212
messageOut.getBody().setTimestamp(eventTime);
12031213
if (isTrace) {
12041214
log.trace("sendMessage (updated): streamStartTS={}, length={}, streamOffset={}, timestamp={}", new Object[] { startTs, currentItem.get().getLength(), streamOffset, eventTime });

0 commit comments

Comments
 (0)