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
2 changes: 1 addition & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/watch/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@moq/watch",
"type": "module",
"version": "0.6.4",
"version": "0.6.5",
"jsr": false,
"description": "Watch Media over QUIC broadcasts",
"license": "(MIT OR Apache-2.0)",
Expand Down
20 changes: 20 additions & 0 deletions js/watch/src/audio/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,15 @@ export class Decoder {
};
decoder.configure(decoderConfig);

// The newest frame sent to the decoder since it was last reset.
let newest: Time.Micro | undefined;
for (;;) {
const next = await nextMedia(consumer);
if (!next) break;
if (this.#onNext(next)) {
decoder.reset();
decoder.configure(decoderConfig);
newest = undefined;
}
if (next.end !== undefined) {
continue;
Expand All @@ -367,6 +370,13 @@ export class Decoder {
bytesReceived: (stats?.bytesReceived ?? 0) + frame.payload.byteLength,
}));

// Decode in timestamp order. A subscription's head groups arrive after the live edge served
// alongside them, and the ring, anchored at the first decoded frame, cannot place audio
// before it. Chrome's AudioDecoder would also stamp every later output from its first
// input, shifting the rest of the track by the reorder and overflowing a buffered ring.
if (newest !== undefined && (frame.timestamp as Time.Micro) < newest) continue;
newest = frame.timestamp as Time.Micro;

// Backpressure: in buffered mode this holds the encoded frame until the playhead nears
// it, keeping the lookahead above the floor as Opus instead of decoded PCM. No-op live.
await this.#ring?.wait(frame.timestamp as Time.Micro, effect.abort);
Expand Down Expand Up @@ -436,6 +446,8 @@ export class Decoder {
};
decoder.configure(decoderConfig);

// The newest frame sent to the decoder since it was last reset.
let newest: Time.Micro | undefined;
for (;;) {
const next = await nextMedia(consumer);
if (!next) break;
Expand All @@ -444,6 +456,7 @@ export class Decoder {
if (this.#onNext(next)) {
decoder.reset();
decoder.configure(decoderConfig);
newest = undefined;
}

const { frame } = next;
Expand All @@ -456,6 +469,13 @@ export class Decoder {
bytesReceived: (stats?.bytesReceived ?? 0) + frame.payload.byteLength,
}));

// Decode in timestamp order. A subscription's head groups arrive after the live edge served
// alongside them, and the ring, anchored at the first decoded frame, cannot place audio
// before it. Chrome's AudioDecoder would also stamp every later output from its first
// input, shifting the rest of the track by the reorder and overflowing a buffered ring.
if (newest !== undefined && frame.timestamp < newest) continue;
newest = frame.timestamp;

// Backpressure: in buffered mode this holds the encoded frame until the playhead nears
// it, keeping the lookahead above the floor as Opus instead of decoded PCM. No-op live.
await this.#ring?.wait(frame.timestamp, effect.abort);
Expand Down
Loading