Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions js/publish/src/video/processor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ test("falls back to arrival time when the source clock is stuck", async () => {

// Without the fallback all three would land on the same instant, and the encoder would see a
// stream of frames that never advances. Arrivals are 10ms apart, so the deltas are exact.
expect(Number.isInteger(first.value?.timestamp)).toBe(true);
expect((second.value?.timestamp ?? 0) - (first.value?.timestamp ?? 0)).toBe(10_000);
expect((third.value?.timestamp ?? 0) - (second.value?.timestamp ?? 0)).toBe(10_000);

Expand Down
11 changes: 9 additions & 2 deletions js/publish/src/video/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ class Epoch {

// A stuck source leaves arrival time as the only clock we have, which is what the <video>
// fallback uses anyway.
const timestamp = this.#stuck ? arrived : frame.timestamp - this.#base + this.#zero + (arrived - instant);
// Whole microseconds, like the integer a VideoFrame stores: the float error in the clock
// arithmetic would otherwise land a frame a hair under its mark, which a browser truncates a
// whole microsecond early.
const timestamp = Math.round(
this.#stuck ? arrived : frame.timestamp - this.#base + this.#zero + (arrived - instant),
);

const stamped = new VideoFrame(frame, { timestamp });
frame.close();
Expand Down Expand Up @@ -280,7 +285,9 @@ function videoProcessor(track: StreamTrack): ReadableStream<VideoFrame> {
const at = Instant.ZERO.saturatingAdd(
Duration.millis(Math.max(metadata.captureTime ?? now, 0)),
);
controller.enqueue(new VideoFrame(video, { timestamp: MediaClock.capture(at).asMicros() }));
controller.enqueue(
new VideoFrame(video, { timestamp: Math.round(MediaClock.capture(at).asMicros()) }),
);
resolve();
});
});
Expand Down
13 changes: 0 additions & 13 deletions quest/m0/test-flakes-3/publish-stuck-clock-delta.md

This file was deleted.