diff --git a/doc/bin/cli.md b/doc/bin/cli.md index 5f9f060e739..e8b271e7efe 100644 --- a/doc/bin/cli.md +++ b/doc/bin/cli.md @@ -194,10 +194,11 @@ a track that stalls plays late and catches up by playing faster, rather than holding the other one back. Each role follows the catalog, switching rendition when the publisher retires the one playing. With `--video off`, `--metrics ` writes a JSON line every -250 ms with the playhead, the delay, and every gap and stall the speaker hit, in +250 ms with the playhead, the delay, every gap and stall the speaker hit, and +the media it trimmed to bound its delay or shed by playing faster, in the schema the [audio quality harness](https://github.com/moq-dev/moq/tree/main/test/audio-quality) -reduces to underruns, skips, and silence. A silence the publisher declares, such +reduces to underruns, trims, and silence. A silence the publisher declares, such as a push-to-talk mute, plays as comfort noise at the level of the quietest audio heard before it, and counts as no gap or stall. The metrics total that comfort noise and name the media timestamp each utterance after it resumes from. diff --git a/js/watch/api/index.api.md b/js/watch/api/index.api.md index b3a8b386a72..8c4ec894f75 100644 --- a/js/watch/api/index.api.md +++ b/js/watch/api/index.api.md @@ -84,6 +84,7 @@ export namespace Audio { track: Signals.Signal; }; export interface Stats { + accelerated: Clock.Milli; arrival?: { timestamp: Clock.Milli; wall: Clock.Wall; @@ -94,6 +95,7 @@ export namespace Audio { skips: number; stalled: Clock.Milli; stalls: number; + trimmed: Clock.Milli; underruns: number; } export type Supported = (config: Hang.Catalog.AudioConfig) => Promise; diff --git a/js/watch/src/audio/buffer.test.ts b/js/watch/src/audio/buffer.test.ts index fa8a065764f..fbf3cb5135f 100644 --- a/js/watch/src/audio/buffer.test.ts +++ b/js/watch/src/audio/buffer.test.ts @@ -33,6 +33,8 @@ function open(): { anchored: timestamp !== undefined, underruns: 0, skips: 0, + trimmed: Milli.zero, + accelerated: Milli.zero, silent: false, epoch, }; @@ -441,6 +443,8 @@ function fake(delay: Milli, buffered = false) { anchored: true, underruns: 0, skips: 0, + trimmed: Milli.zero, + accelerated: Milli.zero, silent: false, epoch, }; diff --git a/js/watch/src/audio/buffer.ts b/js/watch/src/audio/buffer.ts index a8b0c69ee8d..9c0b892ed40 100644 --- a/js/watch/src/audio/buffer.ts +++ b/js/watch/src/audio/buffer.ts @@ -281,6 +281,14 @@ export class AudioBuffer { /** How many times the ring skipped ahead, dropping queued audio, cumulative. */ readonly skips: Getter = this.#skips; + readonly #trimmed = new Signal(Milli.zero); + /** Media the ring's skips dropped unplayed, less declared silence, cumulative. */ + readonly trimmed: Getter = this.#trimmed; + + readonly #accelerated = new Signal(Milli.zero); + /** Media the stretch removed by playing faster, cumulative. */ + readonly accelerated: Getter = this.#accelerated; + readonly #silent = new Signal(false); /** Whether playback is at a declared end, reached or announced before any audio, and nothing has played since. */ readonly silent: Getter = this.#silent; @@ -338,6 +346,8 @@ export class AudioBuffer { this.#stalled.set(data.stalled); this.#underruns.set(data.underruns); this.#skips.set(data.skips); + this.#trimmed.set(data.trimmed); + this.#accelerated.set(data.accelerated); this.#silent.set(data.silent); if (data.epoch === this.#epoch) { this.#backpressure.observe(data.anchored ? data.timestamp : undefined, data.stalled); diff --git a/js/watch/src/audio/decoder.test.ts b/js/watch/src/audio/decoder.test.ts index 8a48cfe6954..7d88a18d2c7 100644 --- a/js/watch/src/audio/decoder.test.ts +++ b/js/watch/src/audio/decoder.test.ts @@ -112,6 +112,8 @@ class FakeWorklet { anchored: ring.anchored, underruns: ring.underruns, skips: ring.skips, + trimmed: ring.trimmed, + accelerated: ring.accelerated, silent: ring.silent, epoch: this.#epoch, }; diff --git a/js/watch/src/audio/decoder.ts b/js/watch/src/audio/decoder.ts index fd183a933c7..58c9e26d025 100644 --- a/js/watch/src/audio/decoder.ts +++ b/js/watch/src/audio/decoder.ts @@ -93,6 +93,10 @@ export interface Stats { underruns: number; /** How many times playback skipped ahead, dropping buffered audio rather than playing it faster. */ skips: number; + /** Media those skips dropped unplayed, less declared silence. */ + trimmed: Milli; + /** Media the time stretch removed by playing faster. */ + accelerated: Milli; /** Frames that arrived after their playout time. */ late: number; /** Renditions that failed to decode. */ @@ -106,7 +110,17 @@ export interface Stats { } // The running totals before anything is counted. -const EMPTY: Stats = { bytesReceived: 0, underruns: 0, skips: 0, late: 0, errors: 0, stalls: 0, stalled: Milli.zero }; +const EMPTY: Stats = { + bytesReceived: 0, + underruns: 0, + skips: 0, + trimmed: Milli.zero, + accelerated: Milli.zero, + late: 0, + errors: 0, + stalls: 0, + stalled: Milli.zero, +}; // What a decode attempt reads, and where its counts go. type Attempt = { config: DecoderConfig; failure: Signal; path: Moq.Path.Valid; key: Key }; @@ -427,6 +441,23 @@ export class Decoder { if (added <= 0) return; this.#count(undefined, {}, (stats) => ({ skips: stats.skips + added })); }); + // Each ring's totals start at zero too, so carry each forward by its rise. + let trimmed = Milli.zero; + let accelerated = Milli.zero; + effect.run((inner) => { + const total = inner.get(ring.trimmed); + const added = total - trimmed; + trimmed = total; + if (added > 0) this.#count(undefined, {}, (stats) => ({ trimmed: Milli(stats.trimmed + added) })); + }); + effect.run((inner) => { + const total = inner.get(ring.accelerated); + const added = total - accelerated; + accelerated = total; + if (added > 0) { + this.#count(undefined, {}, (stats) => ({ accelerated: Milli(stats.accelerated + added) })); + } + }); effect.set(this.#out.root, worklet); }); diff --git a/js/watch/src/audio/render-worklet.test.ts b/js/watch/src/audio/render-worklet.test.ts index f50a003f05f..658172e8dad 100644 --- a/js/watch/src/audio/render-worklet.test.ts +++ b/js/watch/src/audio/render-worklet.test.ts @@ -86,6 +86,8 @@ describe("render dispatch", () => { anchored: true, underruns: 0, skips: 0, + trimmed: Milli.zero, + accelerated: Milli.zero, silent: false, }, ]); @@ -115,6 +117,8 @@ describe("render dispatch", () => { anchored: true, underruns: 0, skips: 0, + trimmed: Milli.zero, + accelerated: Milli.zero, silent: false, }, ]); diff --git a/js/watch/src/audio/render-worklet.ts b/js/watch/src/audio/render-worklet.ts index e7c23e255b4..ffcb5421f10 100644 --- a/js/watch/src/audio/render-worklet.ts +++ b/js/watch/src/audio/render-worklet.ts @@ -101,6 +101,8 @@ class Render extends AudioWorkletProcessor { anchored: ring.anchored, underruns: ring.underruns, skips: ring.skips, + trimmed: ring.trimmed, + accelerated: ring.accelerated, silent: ring.silent, epoch: this.#epoch, }; diff --git a/js/watch/src/audio/render.ts b/js/watch/src/audio/render.ts index b3ac4dde878..7760d84bbab 100644 --- a/js/watch/src/audio/render.ts +++ b/js/watch/src/audio/render.ts @@ -64,6 +64,10 @@ export interface State { underruns: number; // How many times the ring skipped ahead, dropping queued audio, cumulative. skips: number; + // Media those skips dropped unplayed, less declared silence, cumulative. + trimmed: Milli; + // Media the stretch removed by playing faster, cumulative. + accelerated: Milli; // Whether playback is at a declared end, reached or announced before any audio, and nothing has played since. silent: boolean; // The epoch of the last reset or park the worklet applied. diff --git a/js/watch/src/audio/replay.ts b/js/watch/src/audio/replay.ts index 6f7ace49450..21b2d60602d 100644 --- a/js/watch/src/audio/replay.ts +++ b/js/watch/src/audio/replay.ts @@ -89,6 +89,10 @@ export interface Quantum { underruns: number; /** The ring's cumulative skips, as the player's stats count them: each jump that dropped queued audio. */ skips: number; + /** The received audio those skips dropped, cumulative, in ms. */ + trimmed: number; + /** The received audio the stretch removed by playing faster, cumulative, in ms. */ + accelerated: number; } /** Samples as the milliseconds `AudioBuffer` posts to the worklet. */ @@ -285,6 +289,8 @@ export async function* replay(trace: Arrival[], options: Options): AsyncGenerato delay, underruns: ring.underruns, skips: ring.skips, + trimmed: ring.trimmed, + accelerated: ring.accelerated, }; } } finally { diff --git a/js/watch/src/audio/ring-buffer.test.ts b/js/watch/src/audio/ring-buffer.test.ts index 4bb25240372..07ca8a3f2bc 100644 --- a/js/watch/src/audio/ring-buffer.test.ts +++ b/js/watch/src/audio/ring-buffer.test.ts @@ -913,6 +913,9 @@ describe("time stretch", () => { settled(peaks, 100); // Every sample written either played or is still buffered, so nothing was skipped. expect(buffer.skips).toBe(0); + expect(buffer.trimmed).toBe(Milli.zero); + // At least the 200 ms it started above the floor, less the period it may rest above it. + expect(buffer.accelerated).toBeGreaterThan(200 - 2.5); expect(Math.round((Milli.fromMicro(buffer.timestamp) * RATE) / 1000) + buffer.length).toBeGreaterThan( written - frames(30), ); @@ -964,11 +967,59 @@ describe("time stretch", () => { expect(buffer.skips).toBe(1); expect(buffer.length).toBe(frames(100)); expect(Milli.fromMicro(buffer.timestamp)).toBeCloseTo(400, 6); + // Everything before the new playhead but the quantum that played. + expect(buffer.trimmed).toBeCloseTo(400 - (QUANTUM * 1000) / RATE, 6); + expect(buffer.accelerated).toBe(Milli.zero); const [output] = read(buffer, QUANTUM, 1); expect(output.length).toBe(QUANTUM); expect(output.every((sample) => sample === 0.5)).toBe(true); }); + it("trims a gap's zeros as media", () => { + const buffer = live(100); + write(buffer, 0 as Milli, frames(100), { value: 0.25 }); + read(buffer, QUANTUM, 1); + // A 100 ms gap, then enough to cross the 480 ms fast threshold and re-anchor at 410 ms. + write(buffer, 200 as Milli, frames(10), { value: 0.5 }); + write(buffer, 210 as Milli, frames(300), { value: 0.5 }); + expect(buffer.skips).toBe(1); + expect(Milli.fromMicro(buffer.timestamp)).toBeCloseTo(410, 6); + expect(buffer.trimmed).toBeCloseTo(410 - (QUANTUM * 1000) / RATE, 6); + }); + + it("trims no declared silence", () => { + const buffer = live(100); + write(buffer, 0 as Milli, frames(100), { value: 0.25 }); + read(buffer, QUANTUM, 1); + // A declared silence over [100, 200) ms, then more than the ring's 1 s capacity, which skips to + // 250 ms through the silence and the incoming chunk's first 50 ms. + buffer.end(Micro(100_000)); + buffer.next(); + write(buffer, 200 as Milli, frames(1050), { value: 0.5 }); + expect(buffer.skips).toBe(1); + expect(Milli.fromMicro(buffer.timestamp)).toBeCloseTo(250, 6); + expect(buffer.trimmed).toBeCloseTo(250 - 100 - (QUANTUM * 1000) / RATE, 6); + }); + + it("trims only what the ring held, never the gap a re-anchor jumps", () => { + const buffer = live(100); + write(buffer, 0 as Milli, frames(100), { value: 0.25 }); + read(buffer, QUANTUM, 1); + // A group past its age budget: the next audio lands 2 s on, past the ring's capacity. + write(buffer, 2000 as Milli, frames(20), { value: 0.5 }); + expect(buffer.skips).toBe(1); + expect(buffer.trimmed).toBeCloseTo(100 - (QUANTUM * 1000) / RATE, 6); + }); + + it("counts nothing when an empty ring re-anchors", () => { + const buffer = live(100); + write(buffer, 0 as Milli, frames(100), { value: 0.25 }); + while (buffer.length > 0) read(buffer, QUANTUM, 1); + write(buffer, 3000 as Milli, frames(20), { value: 0.5 }); + expect(buffer.skips).toBe(0); + expect(buffer.trimmed).toBe(Milli.zero); + }); + it("counts a re-anchor that drops only the staged window as a skip", () => { const buffer = live(100); // Four whole 30 ms windows, so once the playhead passes 90 ms the ring is empty and only the diff --git a/js/watch/src/audio/ring-buffer.ts b/js/watch/src/audio/ring-buffer.ts index 7638b44ae37..5fde0e94fab 100644 --- a/js/watch/src/audio/ring-buffer.ts +++ b/js/watch/src/audio/ring-buffer.ts @@ -1,4 +1,4 @@ -import { Micro, type Milli, Second } from "@moq/clock"; +import { Micro, Milli, Second } from "@moq/clock"; import { ringCapacity } from "./latency"; import { Stretch } from "./stretch"; @@ -14,6 +14,10 @@ export class AudioRingBuffer { #parked = false; #underruns = 0; #skips = 0; + // Samples of media a skip dropped, and that the stretch removed by accelerating, gap zeros + // included and declared silence excluded, as moq-audio counts them. + #trimmed = 0; + #accelerated = 0; // Where the publisher declared its audio ends, as a sample index, until the next reset. #end?: number; @@ -105,6 +109,16 @@ export class AudioRingBuffer { return this.#skips; } + /** Media the ring's skips dropped unplayed, less declared silence, cumulative. */ + get trimmed(): Milli { + return Milli.fromSecond((this.#trimmed / this.rate) as Second); + } + + /** Media the stretch removed by playing faster, cumulative. */ + get accelerated(): Milli { + return Milli.fromSecond((this.#accelerated / this.rate) as Second); + } + /** Whether playback is at a declared end, reached or announced before any audio, and nothing has played since. */ get silent(): boolean { return this.#silent; @@ -227,7 +241,7 @@ export class AudioRingBuffer { const latency = this.#latencySamples; const queued = end - this.#readIndex + this.#stretch.available; if (end - this.#readIndex > this.capacity) { - this.#skip(end - this.capacity); + this.#skip(end - this.capacity, start); } else if (band && pause && pause.start <= this.#readIndex && queued > latency + this.#chunk) { // Skip only the silence past the queued floor, which the staged window counts toward, so the // read index only moves forward and never re-stages PCM the window already holds. @@ -241,7 +255,7 @@ export class AudioRingBuffer { latency + Math.floor(((this.capacity - latency) * 3) / 4), ) ) { - this.#skip(end - latency); + this.#skip(end - latency, start); } // Fill gaps with zeros if there's a discontinuity @@ -328,9 +342,14 @@ export class AudioRingBuffer { if (!this.#anchored || (this.#stalled && this.length <= 0 && this.#ended())) this.#silent = true; } - // Move the read index forward to `index`, dropping any queued audio it passes, staged included. - #skip(index: number): void { - if (index > this.#readIndex && this.length > 0) this.#skips++; + // Move the read index forward to `index`, dropping any queued audio it passes, staged included, + // and the front of the incoming chunk at `start` when `index` lies past it. An empty ring only + // re-anchors over a gap it never held: neither counter moves, as in moq-audio. + #skip(index: number, start: number): void { + if (index > this.#readIndex && this.length > 0) { + this.#skips++; + this.#trimmed += this.#discarded(index, start); + } // The staged window lies behind the new index, so it is dropped with the rest, as moq-audio's // trim discards staged output first. const length = this.length; @@ -343,6 +362,21 @@ export class AudioRingBuffer { this.#prune(); } + // Media a skip to `index` drops: the unplayed share of the staged window, what the ring holds up + // to `index`, and the incoming chunk's front below it, less declared silence. The gap between the + // write index and the chunk at `start` was never held, so it is no trim. + #discarded(index: number, start: number): number { + const stretch = this.#stretch; + const held = Math.min(index, this.#writeIndex); + const front = Math.max(start, this.#writeIndex); + let dropped = held - this.#readIndex + Math.max(0, index - front); + if (stretch.available > 0 && !this.#windowQuiet) dropped += (stretch.available * this.#window) / stretch.length; + for (const pause of this.#pauses) { + dropped -= Math.max(0, Math.min(held, pause.end) - Math.max(this.#readIndex, pause.start)); + } + return dropped; + } + // Forget the declared silences the playhead has passed. #prune(): void { const pauses = this.#pauses; @@ -462,6 +496,7 @@ export class AudioRingBuffer { const stretch = this.#stretch; stretch.process(frames, this.#peak - this.#latencySamples, enabled); this.#peak -= frames - stretch.length; + this.#accelerated += Math.max(0, frames - stretch.length); this.#readIndex += frames; this.#window = frames; this.#windowQuiet = quiet; diff --git a/quest/m1/audio-jitter-target/browser-ceilings.md b/quest/m1/audio-jitter-target/browser-ceilings.md index 411b975b72b..5a12c4ab6b2 100644 --- a/quest/m1/audio-jitter-target/browser-ceilings.md +++ b/quest/m1/audio-jitter-target/browser-ceilings.md @@ -44,6 +44,12 @@ it, as is an `av_lag_ms` p50 above zero, which is audio settling behind the clock. Rewrite the note's browser sentences to the new nights and say the stretch is in them. +[moq-dev/moq#8308](https://github.com/moq-dev/moq/pull/8308) adds the +player's own `trimmed_ms` and `accelerated_ms` to every row. The native +calibration budgets `trimmed_ms_per_min` beside `player_skips_per_min`, as the +maintainer decided there; budgeting it here too keeps the two runtimes graded +alike. + ## Related - [Capped budgets](/quest/m1/audio-jitter-target/capped-budgets.md) - re-measures the AAC browser rows from nightlies too; the same seven nights can serve both diff --git a/quest/m1/audio-jitter-target/native-stretch.md b/quest/m1/audio-jitter-target/native-stretch.md index 78e85a1fc9a..4fdd9cff0e8 100644 --- a/quest/m1/audio-jitter-target/native-stretch.md +++ b/quest/m1/audio-jitter-target/native-stretch.md @@ -55,19 +55,58 @@ capacity watermark and an incoming excess at the fast threshold trim. Remaining verification: - Native `test/audio-quality` rows must meet their measured underrun - ceilings once their targets settle. Keep a failed or void row explicit and fix - any implementation cause before calling this complete. + ceilings once their targets settle. Keep a failed or void row explicit and + fix any implementation cause. - Re-measure the provisional native budgets from seven scheduled nightly - artifacts using `budgets.json`'s rule: worst clean run times 1.25, plus + artifacts that carry `moq play`'s own `trimmed` and `accelerated` + counters, using `budgets.json`'s rule: worst clean run times 1.25, plus its documented native hiccup, rounded to two significant figures. A - developer run is not that calibration. -- Run `just rs bench-playback` on a quiet host with no other agents. It - now sweeps both sink count and callback size with and without stretch, - and the nightly `rust-test` benchmark job (`sh/gh/nightly.sh`) already - runs it. A loaded-host smoke run is not a timing acceptance claim. -- Listen to real speech with 2 ms/s drift and the measured expansions on - a real output device (below). Deterministic PCM and allocation checks do - not establish perceptual acceptance. + developer run is not that calibration. Native rows then budget the + player's own `player_skips_per_min` and `trimmed_ms_per_min` in place of + the analyzer's `skip_aheads_per_min` and `discarded_ms_per_min`, which + count the accelerate too. + +Graded 2026-11-08: the scheduled Nightlies of 2026-11-05 to 11-08 on +`main` (42050683248, 42236107954, 42377867523, 42487375545) are the first +four with this implementation; 11-04's ran at 14:56 UTC, before it merged +at 17:31. Every night has all 12 native rows and none voided. Eleven rows +read zero underruns every night. Opus `step` reads one 22 to 44 ms gap on +three nights, at 29.6 s, when the shaper's one-way delay steps from 5 to +60 ms while the settled target is 60 ms: a late arrival no stretch can +cover without concealment, played clean once the target rises to 100 ms. +The scheduled Nightlies of 11-02 to 11-04, before this implementation, +read up to 23.9 underruns a minute on AAC `wide` and 8.6 on Opus `wide`. + +The stretch adds skip-aheads the harness did not see before: up to 3.3 a +minute and 232 ms discarded on Opus `bursty`, 2.2 and 181 ms on AAC +`near-zero` and `step` on 11-08. Each is the accelerate shedding a lowered +target or a startup overfill at about 8% speed for 1 to 4 s, with no single +sample's media advancing more than 33 ms past real time. The harness counts +any shed of more than 40 ms across nine samples as a skip, which its README +now says. Two rows failed their provisional ceilings that way: Opus +`bursty` on 11-07 (232 > 170 ms discarded, and a 380 ms startup target hold +> 350) and AAC `step` on 11-08 (157.5 > 110). The rest of the job's red is +outside this work: `raw-audio-bench` on 11-06, `qmux-bench` on 11-08, and +browser and replay rows. + +The nightly `rust-test` benchmark job ran `just rs bench-playback` and +passed on all four nights, alone on a GitHub `ubuntu-24.04-arm` runner. The +stretch costs 16 to 43% per callback, stable across nights; its worst cell, +64 sinks at 2048 frames, is 1.02 ms of a 42.7 ms period. +[moq-dev/moq#8308](https://github.com/moq-dev/moq/pull/8308)'s body keeps +every graded native row's metrics. + +Decided 2026-11-09 (maintainer, on +[moq-dev/moq#8308](https://github.com/moq-dev/moq/pull/8308#issuecomment-6730322286)): + +- ✅ `moq play --metrics` reports its own trimmed and accelerated audio, + and the calibration budgets trims alone (rejected: keep budgeting + accelerates as `discarded_ms`). An accelerate is inaudible, so it is not + the discarded audio these rows guard. #8308 adds the counters to both + players, beside the browser's skip count + [moq-dev/moq#8058](https://github.com/moq-dev/moq/pull/8058) added. +- ✅ The nightly runner's `bench-playback` counts as the quiet-host run + (rejected: naming another host). That settles the timing check. Decided 2026-11-04 (maintainer, on [moq-dev/moq#7856](https://github.com/moq-dev/moq/pull/7856)): accept the @@ -111,12 +150,13 @@ bench waits below remain. ## Waiting -- moq-dev/moq: collect seven scheduled native nightly rows for this - implementation, then apply the existing calibration rule. Keep the - current provisional budgets until those artifacts exist. -- moq-dev/moq: run `just rs bench-playback` on a quiet host. On - 2026-11-04 `nixos`, `nixos2`, and `kixtop` all ran agents and `desktop` - refused SSH. +- moq-dev/moq: seven scheduled Nightlies on a `main` that includes + [moq-dev/moq#8308](https://github.com/moq-dev/moq/pull/8308), whose + native rows report `player_skips` and `trimmed_ms`. Find them with `gh run list --workflow + nightly.yml --event schedule`, download each with `gh run download + -n audio-quality-run` within its 7 days, keep its native rows in the + calibration PR's body, and apply the calibration rule once seven exist. + Never dispatch the nightly by hand. ## Related diff --git a/rs/moq-audio/src/playback/mixer.rs b/rs/moq-audio/src/playback/mixer.rs index 8b75b8abd95..295ee8eabc3 100644 --- a/rs/moq-audio/src/playback/mixer.rs +++ b/rs/moq-audio/src/playback/mixer.rs @@ -126,6 +126,12 @@ pub(super) struct Entry { applied: f32, /// [`ring::Consumer::comfort`] as of the last read. comfort: u64, + /// [`ring::Consumer::skips`] as of the last read. + skips: u64, + /// [`ring::Consumer::trimmed`] as of the last read. + trimmed: u64, + /// [`ring::Consumer::accelerated`] as of the last read. + accelerated: u64, } /// Something the audio thread is done with and must not free itself. @@ -256,6 +262,9 @@ impl Mixer { let entry = Entry { id, comfort: cons.comfort(), + skips: cons.skips(), + trimmed: cons.trimmed(), + accelerated: cons.accelerated(), cons, gain, completion, @@ -327,6 +336,8 @@ impl Mixer { let mut tail = 0; // The most comfort noise any sink still being written played. let mut comfort = 0; + // What those sinks discarded, summed. + let (mut skips, mut trimmed, mut accelerated) = (0, 0, 0); for entry in entries.iter_mut() { // Read even at zero volume: this is live audio, so a muted sink @@ -345,6 +356,17 @@ impl Mixer { }; let comforted = entry.cons.comfort(); let filled = comforted - std::mem::replace(&mut entry.comfort, comforted); + let jumps = entry.cons.skips(); + let jumps = jumps - std::mem::replace(&mut entry.skips, jumps); + let cut = entry.cons.trimmed(); + let cut = cut - std::mem::replace(&mut entry.trimmed, cut); + let sped = entry.cons.accelerated(); + let sped = sped - std::mem::replace(&mut entry.accelerated, sped); + if entry.completion.writing() { + skips += jumps; + trimmed += cut as usize; + accelerated += sped as usize; + } match read { Some(read) if entry.completion.writing() => { playing = true; @@ -383,6 +405,7 @@ impl Mixer { (playing, supplied) = (true, tail); } ledger.add(&bus[..samples], channels, supplied, playing, comfort); + ledger.shed(skips, trimmed, accelerated); // Tap the mix on its way out. Overflow means the microphone stopped // draining, which the canceller notices on its own; there is nothing @@ -918,4 +941,29 @@ mod tests { observation.comfort ); } + + /// A queue trimmed back to its latency is reported as discarded audio, + /// distinct from what the stretch sheds. + #[test] + fn a_trim_is_timed_as_discarded_audio() { + let mut harness = Harness::new(Layout::Stereo); + let mut observer = observe::Observer::new(harness.observe.clone()).unwrap(); + let mut out = vec![0.0f32; 512 * STEREO]; + + let (_, mut prod) = harness.add(Arc::new(Gain::new())); + harness.fill(&mut out[..STEREO]); + // Past three quarters of the second of headroom above the 10 ms latency. + push(&mut prod, 0.5, 40_000); + harness.fill(&mut out); + + let observation = observer.read().unwrap(); + // The 10 ms prime and the push, less the buffer read and the latency kept. + let trimmed = 480 + 40_000 - 512 - 480; + assert_eq!( + observation.trimmed, + Duration::from_secs_f64(trimmed as f64 / RATE as f64) + ); + assert_eq!(observation.skips, 1); + assert_eq!(observation.accelerated, Duration::ZERO); + } } diff --git a/rs/moq-audio/src/playback/observe.rs b/rs/moq-audio/src/playback/observe.rs index fe02ecf4578..ffc3e1e832d 100644 --- a/rs/moq-audio/src/playback/observe.rs +++ b/rs/moq-audio/src/playback/observe.rs @@ -71,6 +71,15 @@ pub struct Observation { /// Device time filled with comfort noise for a silence the publisher /// declared, since the first audible quantum. pub comfort: Duration, + /// Times a sink being written had its queue trimmed back to its latency. + pub skips: u64, + /// Written audio discarded unplayed to bring a sink's queue back down to + /// its latency, summed over the sinks being written. A sink's opening + /// silence and comfort noise never count; silence the writer wrote does. + pub trimmed: Duration, + /// Media a sink's time stretch removed by playing faster, summed + /// over the sinks being written. Inaudible by design, unlike a trim. + pub accelerated: Duration, /// Whether nothing is playing: no sink is being written to, or every one /// still waits for its first samples. pub stalled: bool, @@ -96,6 +105,11 @@ pub(super) struct Shared { quiet: AtomicU64, /// [`Observation::comfort`] in nanoseconds. comfort: AtomicU64, + skips: AtomicU64, + /// [`Observation::trimmed`] in nanoseconds. + trimmed: AtomicU64, + /// [`Observation::accelerated`] in nanoseconds. + accelerated: AtomicU64, stalled: AtomicBool, /// The reading [`Observer`]'s generation, or 0 with none: events only queue /// while one reads. Each event carries it, so a send racing one observer's @@ -132,6 +146,9 @@ impl Default for Shared { quanta: AtomicU64::new(0), quiet: AtomicU64::new(0), comfort: AtomicU64::new(0), + skips: AtomicU64::new(0), + trimmed: AtomicU64::new(0), + accelerated: AtomicU64::new(0), stalled: AtomicBool::new(true), observer: AtomicU64::new(0), generation: AtomicU64::new(0), @@ -199,6 +216,9 @@ impl Observer { quanta: shared.quanta.load(Ordering::Relaxed), quiet: shared.quiet.load(Ordering::Relaxed), comfort: Duration::from_nanos(shared.comfort.load(Ordering::Relaxed)), + skips: shared.skips.load(Ordering::Relaxed), + trimmed: Duration::from_nanos(shared.trimmed.load(Ordering::Relaxed)), + accelerated: Duration::from_nanos(shared.accelerated.load(Ordering::Relaxed)), stalled: shared.stalled.load(Ordering::Relaxed), ..Default::default() }; @@ -391,6 +411,21 @@ impl Ledger { self.shared.clock.store(self.nanos(self.frames), Ordering::Relaxed); } + /// Count what the sinks being written discarded: `skips` trims of their + /// queues dropping `trimmed` frames, and `accelerated` frames by stretching. + /// Nothing counts once the measurement is over. + pub(super) fn shed(&self, skips: u64, trimmed: usize, accelerated: usize) { + if self.finished().is_some() { + return; + } + self.shared.skips.fetch_add(skips, Ordering::Relaxed); + for (frames, total) in [(trimmed, &self.shared.trimmed), (accelerated, &self.shared.accelerated)] { + if frames > 0 { + total.fetch_add((frames as f64 * 1e9 / self.rate).round() as u64, Ordering::Relaxed); + } + } + } + /// Classify the quantum just completed. fn quantum(&mut self, channels: usize) { let missing = std::mem::take(&mut self.missing); diff --git a/rs/moq-audio/src/ring.rs b/rs/moq-audio/src/ring.rs index aac9342b4f2..ce324ba4733 100644 --- a/rs/moq-audio/src/ring.rs +++ b/rs/moq-audio/src/ring.rs @@ -158,6 +158,9 @@ pub(crate) fn channel(channels: usize, input_rate: u32, output_rate: u32, config cushioned: 0, comfort: crate::comfort::Comfort::new(output_rate, channels), trim: config.trim, + skips: 0, + trimmed: 0, + accelerated: 0, shared, }; (producer, consumer) @@ -494,6 +497,12 @@ pub(crate) struct Consumer { comfort: crate::comfort::Comfort, /// Trim only after filling three quarters of the current target's headroom. trim: bool, + /// Times [`Read::Trimmed`] was returned, ever. + skips: u64, + /// Received frames [`Read::Trimmed`] discarded, ever. + trimmed: u64, + /// Frames the stretch removed by accelerating, ever. + accelerated: u64, shared: Arc, } @@ -541,7 +550,8 @@ impl Consumer { let trim = latency + (capacity - latency) * 3 / 4; if queued >= trim && queued > latency { let frames = queued - latency; - self.discard(frames); + self.skips += 1; + self.trimmed += self.discard(frames) as u64; return Read::Trimmed { frames }; } } @@ -651,6 +661,7 @@ impl Consumer { debug_assert_eq!(read, frames * channels); self.position = self.position.wrapping_add(frames); stretch.process(frames, buffered, self.shared.target.load(Ordering::Relaxed), enabled); + self.accelerated += frames.saturating_sub(stretch.available()) as u64; // The writer still counts the input while it is being analysed. // Publish only the resulting duration change, then the rendered // frames. Moving PCM into staging never makes it disappear. @@ -665,6 +676,23 @@ impl Consumer { self.comfort.filled() } + /// Times the queue was trimmed back to its latency, ever. + pub(crate) fn skips(&self) -> u64 { + self.skips + } + + /// Pushed frames discarded to trim the queue back to its latency, ever: not + /// the startup silence or a resume's comfort noise, though silence padding + /// a writer pushed itself, or [`Push::Padded`] added, counts. + pub(crate) fn trimmed(&self) -> u64 { + self.trimmed + } + + /// Frames of received audio the stretch removed by accelerating, ever. + pub(crate) fn accelerated(&self) -> u64 { + self.accelerated + } + /// Accept pushes without reading first, as a read would. pub(crate) fn start(&self) { self.shared.read.store(true, Ordering::Relaxed); @@ -680,10 +708,12 @@ impl Consumer { buffered + cushion + self.stretch.as_ref().map_or(0, |stretch| stretch.available()) } - /// Drop up to `frames` queued frames unread. - pub(crate) fn discard(&mut self, frames: usize) { + /// Drop up to `frames` queued frames unread, returning how many of them were + /// pushed rather than the startup silence or a resume's comfort noise. + pub(crate) fn discard(&mut self, frames: usize) -> usize { let staged = self.stretch.as_mut().map_or(0, |stretch| stretch.discard(frames)); self.consumed = self.consumed.wrapping_add(staged); + let mut pushed = if self.staged_prime { 0 } else { staged }; let mut left = frames - staged; while left > 0 { let mut take = left; @@ -698,12 +728,15 @@ impl Consumer { if skipped == 0 { break; } - self.prime = self.prime.saturating_sub(skipped); + let prime = skipped.min(self.prime); + self.prime -= prime; + pushed += skipped - prime; self.position = self.position.wrapping_add(skipped); self.consumed = self.consumed.wrapping_add(skipped); left -= skipped; } self.shared.consumed.store(self.consumed, Ordering::Relaxed); + pushed } } @@ -870,9 +903,33 @@ mod tests { assert_eq!(prod.push(&vec![0.5; 3800 * STEREO]), Push::Ok); assert_eq!(cons.read(&mut out), Read::Trimmed { frames: 3880 - 480 }); + assert_eq!(cons.trimmed(), 3880 - 480); + assert_eq!(cons.skips(), 1); assert_eq!(cons.available(), 480); } + /// A trim that reaches into the startup silence counts only what was pushed. + #[test] + fn a_trim_counts_no_startup_silence() { + let (mut prod, mut cons) = channel( + STEREO, + 48_000, + 48_000, + Config { + latency: Duration::from_millis(10), + capacity: Duration::from_millis(100), + pad: false, + trim: true, + }, + ); + cons.start(); + assert_eq!(prod.push(&vec![0.5; 4000 * STEREO]), Push::Ok); + let mut out = vec![0.0; 128 * STEREO]; + // 352 of the 480 startup frames are left behind the 128 read. + assert_eq!(cons.read(&mut out), Read::Trimmed { frames: 4352 - 480 }); + assert_eq!(cons.trimmed(), 4352 - 480 - 352); + } + /// Construction allocates for the reader's rate and the queue's channels, /// never for a declared input rate. #[test] @@ -1096,6 +1153,8 @@ mod tests { (120..=720).contains(&removed), "accelerate removes one pitch period, removed {removed}" ); + assert_eq!(cons.accelerated(), removed as u64, "the shed is counted"); + assert_eq!(cons.trimmed(), 0, "and is no trim"); assert_eq!( prod.buffered(), Duration::from_secs_f64(cons.available() as f64 / 48_000.0) diff --git a/rs/moq-cli/src/play/args.rs b/rs/moq-cli/src/play/args.rs index e9ed4a74bfb..088b2058a4f 100644 --- a/rs/moq-cli/src/play/args.rs +++ b/rs/moq-cli/src/play/args.rs @@ -84,9 +84,10 @@ pub struct Args { /// Write what the speaker played to this file, one JSON sample per line every 250ms. /// /// Each line has the playhead, the playout target, the render quanta the speaker played - /// and how many were quiet, and the gaps and stalls since the line before, in the metric - /// schema of `test/audio-quality`, whose analyzer reduces it to underruns, skips, and - /// silence. Audio only, so it needs `--video off`. + /// and how many were quiet, the received audio trimmed and accelerated away, and the gaps + /// and stalls since the line before, in the metric schema of `test/audio-quality`, whose + /// analyzer reduces it to underruns, trims, and silence. Audio only, so it needs + /// `--video off`. #[usage(long, value_name = "PATH", value_hint = usage_rs::ValueHint::FilePath, extensions("ndjson"))] pub metrics: Option, } diff --git a/rs/moq-cli/src/play/headless.rs b/rs/moq-cli/src/play/headless.rs index c682269335f..628f5112f71 100644 --- a/rs/moq-cli/src/play/headless.rs +++ b/rs/moq-cli/src/play/headless.rs @@ -91,6 +91,11 @@ pub(crate) async fn run( metrics.utterance(timestamp); } } + Some(Event::Trimmed { audio, skip }) => { + if let Some(metrics) = &mut metrics { + metrics.trimmed(audio, skip); + } + } None => break Err(anyhow::anyhow!("audio playback event channel closed")), }, result = &mut media, if !completed => { diff --git a/rs/moq-cli/src/play/media.rs b/rs/moq-cli/src/play/media.rs index 526f5cdf3f4..f422a1b78dd 100644 --- a/rs/moq-cli/src/play/media.rs +++ b/rs/moq-cli/src/play/media.rs @@ -684,6 +684,8 @@ async fn play_audio( let mut declare = false; // The frame being written starts the utterance after a declared silence. let mut utterance = false; + // The last frame written was trimmed, so a trim of this one continues that skip. + let mut trimming = false; loop { let (event, delay, crossing, arrived_at) = loop { if let Some(event) = received.lock().unwrap().pop_front() { @@ -852,6 +854,15 @@ async fn play_audio( } let skip = fit.skip as usize * stride; let written = sink.write(&frame.data[skip.min(frame.data.len())..])?; + let trimmed = fit.skip + written.dropped_sample_frames as u64; + if trimmed > 0 { + output.send(Event::Trimmed { + audio: Duration::from_secs_f64(trimmed as f64 / sample_rate as f64), + skip: !std::mem::replace(&mut trimming, true), + }); + } else { + trimming = false; + } // A dropped write leaves the utterance to start on the next frame the sink accepts. if utterance && written.accepted_sample_frames > 0 { utterance = false; @@ -2018,7 +2029,7 @@ mod tests { match event { Event::Failed(err) => panic!("playback failed: {err}"), Event::Ended | Event::Finished => panic!("the player stopped following the path"), - Event::Wake | Event::Utterance(_) => {} + Event::Wake | Event::Utterance(_) | Event::Trimmed { .. } => {} } } assert!(!player.is_finished(), "the player stopped following the path"); diff --git a/rs/moq-cli/src/play/metrics.rs b/rs/moq-cli/src/play/metrics.rs index fbf439ba80c..e5325d74b5a 100644 --- a/rs/moq-cli/src/play/metrics.rs +++ b/rs/moq-cli/src/play/metrics.rs @@ -50,6 +50,10 @@ struct Sample { quiet: Option, #[serde(skip_serializing_if = "Option::is_none")] comfort: Option, + player_skips: u64, + trimmed: f64, + #[serde(skip_serializing_if = "Option::is_none")] + accelerated: Option, #[serde(skip_serializing_if = "Vec::is_empty")] gaps: Vec, #[serde(skip_serializing_if = "Vec::is_empty")] @@ -92,6 +96,9 @@ struct Totals { quanta: u64, quiet: u64, comfort: Duration, + skips: u64, + trimmed: Duration, + accelerated: Duration, } impl Totals { @@ -101,6 +108,21 @@ impl Totals { quanta: observation.quanta, quiet: observation.quiet, comfort: observation.comfort, + skips: observation.skips, + trimmed: observation.trimmed, + accelerated: observation.accelerated, + } + } + + fn add(self, other: Self) -> Self { + Self { + clock: self.clock + other.clock, + quanta: self.quanta + other.quanta, + quiet: self.quiet + other.quiet, + comfort: self.comfort + other.comfort, + skips: self.skips + other.skips, + trimmed: self.trimmed + other.trimmed, + accelerated: self.accelerated + other.accelerated, } } } @@ -116,6 +138,10 @@ pub(super) struct Metrics { base: Totals, /// Utterances since the last sample. utterances: Vec, + /// Received audio the player discarded before it reached a speaker's queue, + /// and the skips that did it. + trimmed: Duration, + skips: u64, start: Instant, interval: kio::clock::Interval, } @@ -139,6 +165,8 @@ impl Metrics { current: None, base: Totals::default(), utterances: Vec::new(), + trimmed: Duration::ZERO, + skips: 0, start: Instant::now(), interval, }; @@ -159,6 +187,13 @@ impl Metrics { }); } + /// Count received audio the player discarded rather than handed to the + /// speaker, and whether that started a skip. + pub(super) fn trimmed(&mut self, audio: Duration, skip: bool) { + self.trimmed += audio; + self.skips += skip as u64; + } + /// End the measurement: close any gap still open and write one last sample. pub(super) async fn finish(mut self) -> anyhow::Result<()> { // A speaker reopened since the last sample is the one playing now: adopt it @@ -187,13 +222,7 @@ impl Metrics { if let Some((mut observer, base)) = self.current.take() { let last = observer.read().context("speaker metrics")?; collect(&last, base, &mut gaps, &mut stalls); - let totals = Totals::of(&last); - self.base = Totals { - clock: base.clock + totals.clock, - quanta: base.quanta + totals.quanta, - quiet: base.quiet + totals.quiet, - comfort: base.comfort + totals.comfort, - }; + self.base = base.add(Totals::of(&last)); } self.current = Some((next, self.base)); } @@ -206,20 +235,26 @@ impl Metrics { } None => None, }; + let totals = observation + .as_ref() + .map_or(self.base, |(o, base)| base.add(Totals::of(o))); // Read straight after the device clock, so the two pair up. let now = Instant::now(); let (playhead, delay) = (self.playhead.at(now), self.presentation.delay()); let sample = Sample { at: ms(now.duration_since(self.start)), - render: observation.as_ref().map(|(o, base)| ms(base.clock + o.clock)), + render: observation.as_ref().map(|_| ms(totals.clock)), timestamp: playhead.map(ms), stalled: observation.as_ref().map(|(o, _)| o.stalled), delay: Some(ms(delay)), output_latency: observation.as_ref().and_then(|(o, _)| o.latency).map(ms), - quanta: observation.as_ref().map(|(o, base)| base.quanta + o.quanta), - quiet: observation.as_ref().map(|(o, base)| base.quiet + o.quiet), - comfort: observation.as_ref().map(|(o, base)| ms(base.comfort + o.comfort)), + quanta: observation.as_ref().map(|_| totals.quanta), + quiet: observation.as_ref().map(|_| totals.quiet), + comfort: observation.as_ref().map(|_| ms(totals.comfort)), + player_skips: self.skips + totals.skips, + trimmed: ms(self.trimmed + totals.trimmed), + accelerated: observation.as_ref().map(|_| ms(totals.accelerated)), gaps, stalls, utterances: std::mem::take(&mut self.utterances), diff --git a/rs/moq-cli/src/play/window.rs b/rs/moq-cli/src/play/window.rs index 4618656d82a..a87905a7ec7 100644 --- a/rs/moq-cli/src/play/window.rs +++ b/rs/moq-cli/src/play/window.rs @@ -43,6 +43,13 @@ pub(super) enum Event { Failed(String), /// Audio resumed after a declared silence, starting at this media timestamp. Utterance(Duration), + /// Received audio the player discarded rather than played to bound its + /// delay: skipped at the fast threshold, or refused by a full sink. `skip` + /// marks the first frame of a spell, one jump however many frames it spans. + Trimmed { + audio: Duration, + skip: bool, + }, } /// Run native playback on the calling thread until the window closes. @@ -285,7 +292,7 @@ impl ApplicationHandler for App { } } Event::Failed(err) => self.fail(event_loop, err), - Event::Utterance(_) => {} + Event::Utterance(_) | Event::Trimmed { .. } => {} } } diff --git a/test/audio-quality/README.md b/test/audio-quality/README.md index 3e347e172cb..57a8072ad54 100644 --- a/test/audio-quality/README.md +++ b/test/audio-quality/README.md @@ -290,16 +290,27 @@ player's own count, which its stats panel shows, is read alongside: run-dry as stalled time, so `underruns` leaves those out and this counts them. Unset natively. - `player_skips`: `audio.out.stats.skips`, each jump that dropped buffered audio rather than playing it faster. `skip_aheads` below infers the same events from the playhead, and also reads a time - stretch that sustains 40 ms of acceleration as one, so this is the exact count. Unset natively. + stretch that sustains 40 ms of acceleration as one, so this is the exact count. Natively, each + trim of the ring, and each run of consecutive frames `moq play` skipped at the stretch's fast + threshold or a full ring refused. - `underruns`: quanta the ring filled only partly, or not at all, while playing. - `short_quanta`: the underruns that were partly filled: the ring ran dry part-way through. - `underrun_episodes`: maximal runs of consecutive underruns, one audible gap each. - `underrun_ms`: the missing audio, summed, and the longest episode as `max`. - `skip_aheads`: re-anchors that discarded buffered audio, seen as a forward step of more than 40 ms in the lag between the viewer clock and the playhead (judged on the median of four samples either - side, after removing the media clock's drift). + side, after removing the media clock's drift). A time stretch that accelerates onto a lower target + by more than 40 ms across those nine samples counts too, though it re-anchors nothing: `moq play` + accelerates about 8%, so shedding more than about 40 ms reads as one skip or more. - `discarded_ms`: the media those skip-aheads jumped over. Audio dropped before it reached the ring moves no playhead, so it is not counted. +- `trimmed_ms`: `audio.out.stats.trimmed`, the media those `player_skips` dropped unplayed, + including the zeros filling a network gap; neither player counts its opening silence, declared + silence, or comfort noise. Unlike `discarded_ms`, it never counts an accelerate. Media the + subscription skipped before decoding, a group past its age budget, is a gap in the timeline, not + a trim, in either player. +- `accelerated_ms`: `audio.out.stats.accelerated`, the media the time stretch removed by + playing faster. Inaudible by design, so it is reported rather than budgeted. - `stalled`: the share of the window the ring spent stalled, refilling rather than playing. A gap that starts within 60 ms of a stall is that stall, and is not an underrun. - `silence`: the share of rendered quanta under -60 dBFS at the output, whatever the cause. diff --git a/test/audio-quality/clients/js/grade.ts b/test/audio-quality/clients/js/grade.ts index da5fcde903d..60ff373fb1d 100644 --- a/test/audio-quality/clients/js/grade.ts +++ b/test/audio-quality/clients/js/grade.ts @@ -76,6 +76,8 @@ const COLUMNS: [string, string][] = [ ["gap ms/min", "underrun_ms_per_min"], ["skip-aheads/min", "skip_aheads_per_min"], ["discarded ms/min", "discarded_ms_per_min"], + ["trimmed ms/min", "trimmed_ms_per_min"], + ["accelerated ms/min", "accelerated_ms_per_min"], ["stalled", "stalled_share"], ["silence", "silence_share"], ["A/V lag p50", "av_lag_ms_p50"], diff --git a/test/audio-quality/clients/js/replay.ts b/test/audio-quality/clients/js/replay.ts index 16cf26cd019..4f6e0ef8280 100644 --- a/test/audio-quality/clients/js/replay.ts +++ b/test/audio-quality/clients/js/replay.ts @@ -93,6 +93,8 @@ interface Reading { delay: number; underruns: number; skips: number; + trimmed: number; + accelerated: number; } for (const { row, trace } of rows) { @@ -125,6 +127,8 @@ for (const { row, trace } of rows) { delay: quantum.delay, playerUnderruns: quantum.underruns, playerSkips: quantum.skips, + trimmed: quantum.trimmed, + accelerated: quantum.accelerated, quanta: ledger.counts.quanta, quiet: ledger.counts.quiet, gaps: gaps.length > 0 ? gaps : undefined, @@ -156,6 +160,8 @@ for (const { row, trace } of rows) { delay: quantum.delay, underruns: quantum.underruns, skips: quantum.skips, + trimmed: quantum.trimmed, + accelerated: quantum.accelerated, }; if (quantum.at >= next) { diff --git a/test/audio-quality/clients/js/src/analyze.ts b/test/audio-quality/clients/js/src/analyze.ts index 6d97a51aa71..a527cf99511 100644 --- a/test/audio-quality/clients/js/src/analyze.ts +++ b/test/audio-quality/clients/js/src/analyze.ts @@ -209,6 +209,8 @@ export function analyze(input: Input): Summary { }; const playerUnderruns = rise((s) => s.playerUnderruns); const playerSkips = rise((s) => s.playerSkips); + const trimmed = rise((s) => s.trimmed); + const accelerated = rise((s) => s.accelerated); // ── the playhead ──────────────────────────────────────────────────────── // The lag drifts when the media timeline does not run at wall rate, a property of the source @@ -269,6 +271,10 @@ export function analyze(input: Input): Summary { skip_aheads_per_min: perMin(skips.count), discarded_ms_total: round(skips.ms), discarded_ms_per_min: perMin(skips.ms), + trimmed_ms_total: round(trimmed), + trimmed_ms_per_min: trimmed === null ? null : perMin(trimmed), + accelerated_ms_total: round(accelerated), + accelerated_ms_per_min: accelerated === null ? null : perMin(accelerated), stalled_share: round(stalledShare, 3), silence_share: round(silence, 3), av_lag_ms_p50: round(percentile(behind, 50)), diff --git a/test/audio-quality/clients/js/src/probe.ts b/test/audio-quality/clients/js/src/probe.ts index 500c909381d..722313abf61 100644 --- a/test/audio-quality/clients/js/src/probe.ts +++ b/test/audio-quality/clients/js/src/probe.ts @@ -130,6 +130,8 @@ export function probe(watch: MoqWatch, capture = false): Probe { delay: sync.out.delay.peek(), playerUnderruns: audio.out.stats.peek()?.underruns, playerSkips: audio.out.stats.peek()?.skips, + trimmed: audio.out.stats.peek()?.trimmed, + accelerated: audio.out.stats.peek()?.accelerated, rtt: watch.connection.probe.peek()?.rtt, jitter: audio.source.out.config.peek()?.jitter, renditionDelay: audio.source.out.config.peek()?.delay, diff --git a/test/audio-quality/clients/js/src/schema.ts b/test/audio-quality/clients/js/src/schema.ts index 83fa67dd1e7..fece2bea085 100644 --- a/test/audio-quality/clients/js/src/schema.ts +++ b/test/audio-quality/clients/js/src/schema.ts @@ -125,6 +125,19 @@ export const METRICS = { description: "Media time the skip-aheads jumped over without playing. Audio dropped before it reached the ring moves no playhead and is not counted.", }, + trimmed_ms: { + unit: "ms", + clock: "media", + aggregations: ["total", "per_min"], + description: + "The player's own count of media its skips dropped unplayed. Unlike `discarded_ms`, a time stretch's accelerate is not in it.", + }, + accelerated_ms: { + unit: "ms", + clock: "media", + aggregations: ["total", "per_min"], + description: "The player's own count of media its time stretch removed by playing faster.", + }, stalled: { unit: "share", clock: "viewer", @@ -408,9 +421,14 @@ export type Sample = { playerUnderruns?: number; /** * `audio.out.stats.skips`, cumulative: the player's own count of jumps that dropped buffered audio - * rather than playing it faster. Unset natively. + * rather than playing it faster. Natively, each trim of the ring, skip at the stretch's fast + * threshold, or write a full ring refused. */ playerSkips?: number; + /** `audio.out.stats.trimmed`, cumulative: the media those skips dropped unplayed. */ + trimmed?: Ms; + /** `audio.out.stats.accelerated`, cumulative: media the time stretch removed by playing faster. */ + accelerated?: Ms; /** The current connection PROBE round trip. */ rtt?: Ms; /** The selected rendition's advertised jitter at this sample. */