Repository navigation
quest(audio-jitter-target): Audio jitter target #3952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aa82996
quest: open the audio-jitter-target line
kixelated a227ea3
Merge remote-tracking branch 'origin/main' into HEAD
kixelated 386aa12
feat(audio): a measured jitter buffer for native playback (#3967)
kixelated 32b0c47
feat(watch): size the auto delay from the measured arrival estimator …
kixelated 157996f
fix(watch): subscribe auto audio at the estimator's ceiling, replay t…
kixelated File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { describe, expect, it } from "bun:test"; | ||
| import { readdirSync, readFileSync } from "node:fs"; | ||
| import { dirname, join } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import type { Time } from "@moq/net"; | ||
| import { Jitter } from "./jitter"; | ||
|
|
||
| // The conformance corpus beside doc/concept/audio-jitter.md, read directly so this is graded | ||
| // against the document rather than against another implementation. | ||
| const CORPUS = join(dirname(fileURLToPath(import.meta.url)), "../../../../doc/concept/audio-jitter"); | ||
|
|
||
| interface Case { | ||
| name: string; | ||
| frame: number; | ||
| advertised?: number; | ||
| delay?: number; | ||
| arrival: number[]; | ||
| media: number[]; | ||
| target: [number, number][]; | ||
| } | ||
|
|
||
| const cases: Case[] = readdirSync(CORPUS) | ||
| .filter((file) => file.endsWith(".json")) | ||
| .map((file) => JSON.parse(readFileSync(join(CORPUS, file), "utf8"))); | ||
|
|
||
| // The composition the document specifies on top of the measured term. `@moq/watch` owns it in | ||
| // production (`audio/latency.ts`); it is repeated here so the whole target series is checked. | ||
| function target(jitter: Jitter, c: Case): number { | ||
| if (c.delay !== undefined) return c.delay; | ||
| return Math.max(jitter.measured, c.advertised ?? 0) + c.frame; | ||
| } | ||
|
|
||
| describe("audio jitter conformance", () => { | ||
| it("reads the whole corpus", () => { | ||
| expect(cases.map((c) => c.name).sort()).toEqual([ | ||
| "advertised", | ||
| "buildup", | ||
| "fixed", | ||
| "flush", | ||
| "idle", | ||
| "paced", | ||
| "reorder", | ||
| "spike", | ||
| "tunein", | ||
| ]); | ||
| }); | ||
|
|
||
| for (const c of cases) { | ||
| it(c.name, () => { | ||
| const jitter = new Jitter(); | ||
| const expected = new Map(c.target); | ||
| let current: number | undefined; | ||
| for (let i = 0; i < c.arrival.length; i++) { | ||
| jitter.observe(c.arrival[i] as Time.Milli, c.media[i] as Time.Milli); | ||
| const value = target(jitter, c); | ||
| const listed = expected.get(i); | ||
| if (listed !== undefined) { | ||
| expect(value).toBeCloseTo(listed, 6); | ||
| } else if (current !== undefined) { | ||
| // Unlisted frames hold the previous target. | ||
| expect(value).toBeCloseTo(current, 6); | ||
| } | ||
| current = value; | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| describe("Jitter", () => { | ||
| it("starts at the prior's 95th percentile", () => { | ||
| expect(new Jitter().measured).toBe(100 as Time.Milli); | ||
| }); | ||
|
|
||
| it("is not moved by a stale frame ahead of the live edge", () => { | ||
| // The #3517 regression: one frame from a stale group, then the live edge 14.5s of media later, | ||
| // then evenly paced audio with no real jitter. The jump must not read as a delay or a frame. | ||
| const jitter = new Jitter(); | ||
| jitter.observe(0 as Time.Milli, 0 as Time.Milli); | ||
| for (let i = 0; i < 500; i++) { | ||
| jitter.observe((10 + i * 20) as Time.Milli, (14_500 + i * 20) as Time.Milli); | ||
| } | ||
| expect(jitter.measured).toBe(20 as Time.Milli); | ||
| }); | ||
|
|
||
| it("does not follow the absolute delay", () => { | ||
| // Only the spread of arrivals matters, not how far away the sender is. | ||
| const near = new Jitter(); | ||
| const far = new Jitter(); | ||
| for (let i = 0; i < 500; i++) { | ||
| near.observe((10 + i * 20) as Time.Milli, (i * 20) as Time.Milli); | ||
| far.observe((2000 + i * 20) as Time.Milli, (i * 20) as Time.Milli); | ||
| } | ||
| expect(far.measured).toBe(near.measured); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a marker or latency skip starts an epoch whose timestamps rewind, every subsequent frame is still passed to this
Jitter, but its previous epoch's#newestremains intact and rejects those frames as reordered until they exceed the old high-water mark. The browser's auto target can therefore remain stale for hours, either preserving excess latency or repeatedly underrunning instead of adapting. Fresh evidence beyond the native finding is this separate browser observation path and the absence of any jitter reset when#markPlayhead()increments the discontinuity. (Written by GPT-5.6 Sol)Useful? React with 👍 / 👎.