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
24 changes: 24 additions & 0 deletions js/watch/src/audio/terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,27 @@ test("a fresh encoder after a declared end takes no pre-roll from the stopped on
expect(terminal.preroll()).toEqual([]);
expect(terminal.span(opus(2_000_000)).frames).toBe(0);
});

test("a gap after a declared end reaches the fresh encoder's first frame unprimed", () => {
const terminal = new Terminal();
terminal.clear(0, 80_000);
terminal.update(frame(0n, 0));
terminal.decoded(packet(0), Duration.micros(20_000));
terminal.update(end(1n, 20_000));
// Before lite-07 the run the publisher skipped across the silence arrives as a drop.
terminal.update(gap);
expect(terminal.update(frame(2n, 1_000_000))).toBe(true);
expect(terminal.preroll()).toEqual([]);
expect(terminal.span(opus(1_000_000)).frames).toBe(960);
});

test("a join during a pause plays the fresh encoder's first frame whole, past a gap or not", () => {
for (const gapped of [false, true]) {
const terminal = new Terminal();
terminal.clear(0, 80_000);
terminal.update(end(1n, 20_000));
if (gapped) terminal.update(gap);
expect(terminal.update(frame(2n, 1_000_000))).toBe(true);
expect(terminal.span(opus(1_000_000)).frames).toBe(960);
}
});
5 changes: 4 additions & 1 deletion js/watch/src/audio/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ export class Terminal {
this.#end = undefined;
this.#endGroup = undefined;
this.#before = undefined;
// A fresh encoder's first packets need no frames of the stopped one ahead of them.
// A fresh encoder's first packets need no frames of the stopped one ahead of them, and no
// warmup a join or a gap left pending: a wire before lite-07 names the run the publisher
// skipped across its silence a drop, so after every pause a gap reaches this frame too.
this.#prime = false;
this.#forget();
this.#resetEpoch();
}
Expand Down
33 changes: 0 additions & 33 deletions quest/m0/nightly/push-to-talk-native.md

This file was deleted.

41 changes: 34 additions & 7 deletions rs/moq-audio/src/decode/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,15 @@ impl Consumer {
self.boundary = Some(Duration::try_from(timestamp)?);
self.started = true;
// Groups lost past a declared end were the fresh encoder's, so the packet
// after them still comes from it.
// after them still comes from it, and decodes as its first, unprimed: a wire
// before lite-07 names the run the publisher skipped across its silence a
// drop, so after every pause this gap is that silence, not lost media.
let fresh = self.end.is_some();
self.restart()?;
self.warmup_pending = !self.warmup.is_zero();
if fresh {
self.fresh_encoder();
}
self.warmup_pending = !self.warmup.is_zero();
self.ready.push_back(Read::Gap { timestamp, duration });
continue;
}
Expand Down Expand Up @@ -798,10 +800,12 @@ impl Consumer {
}

/// Expect a fresh encoder's packets: its pre-skip is trimmed again, and the stopped
/// encoder's history primes none of its warmup.
/// encoder's history primes none of its warmup. Its first packet needs no warmup either, so
/// one a join or a gap left pending is dropped.
fn fresh_encoder(&mut self) {
self.decoder.reapply_delay();
self.primed = Duration::ZERO;
self.warmup_pending = false;
}

/// Reset resampling state at a hole, returning whatever the resampler was still
Expand Down Expand Up @@ -1200,6 +1204,9 @@ mod tests {
Lost,
/// A timestamp jump across contiguous groups.
Undeclared,
/// A declared end, then a seek past the starts after it, as a wire before lite-07 delivers
/// the run a publisher skipped across a pause.
DeclaredGap,
}

/// Decodes `first` packets, then six more a second later, past a `cut` in the timeline.
Expand All @@ -1222,6 +1229,10 @@ mod tests {
Break::Declared => producer.discontinuity().unwrap(),
Break::Lost => producer.seek(1_000_000).unwrap(),
Break::Undeclared => {}
Break::DeclaredGap => {
producer.discontinuity().unwrap();
producer.seek(1_000_000).unwrap();
}
}
}
for packet in 0..if epoch == 0 { first } else { 6 } {
Expand Down Expand Up @@ -1527,6 +1538,21 @@ mod tests {
assert_eq!(frames, 8 * 960);
}

/// A join during a pause reaches a fresh encoder's first packet, which needs no warmup, past a
/// gap or not.
#[tokio::test(start_paused = true)]
async fn a_join_during_a_pause_trims_no_warmup() {
for cut in [Break::Declared, Break::DeclaredGap] {
let (stamps, frames) = warmup_output(cut, 0).await;
assert_eq!(
stamps,
[1_000_000, 1_020_000, 1_040_000, 1_060_000, 1_080_000, 1_100_000],
"{cut:?}"
);
assert_eq!(frames, 6 * 960, "{cut:?}");
}
}

/// The codec's history primes it across a gap, so only the warmup it falls short of is trimmed.
#[tokio::test(start_paused = true)]
async fn a_gap_trims_the_warmup_the_history_leaves() {
Expand Down Expand Up @@ -2700,12 +2726,13 @@ mod tests {
assert_eq!(after_loss(true, None).await[0], (1_000_000, 960 - 312));
}

/// The stopped encoder's history primes none of the fresh encoder's warmup, so a loss of
/// its first groups trims the whole warmup after them.
/// A gap after a declared end reaches the fresh encoder's first packet, which plays from its
/// own stamp rather than a warmup later: before lite-07 the run skipped across every pause
/// arrives as a drop, so priming there would clip the start of each utterance.
#[tokio::test(start_paused = true)]
async fn a_loss_after_a_declared_end_trims_the_whole_warmup() {
async fn a_gap_after_a_declared_end_trims_no_warmup() {
let warmup = Some(Duration::from_millis(10));
assert_eq!(after_loss(true, warmup).await[0].0, 1_010_000);
assert_eq!(after_loss(true, warmup).await[0], (1_000_000, 960 - 312));
}

/// Decodes two Opus packets, then, past lost groups and a declared end if `declared`, one
Expand Down