Repository navigation
fix(watch): hold a buffered subscription's audio head and decode it in order #6549
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
bb1ba84
fix(watch): hold a buffered subscription's audio head and decode it i…
kixelated 823ea57
fix(watch): hold the audio head past a zero floor, and bound it by th…
kixelated f59e54f
fix(watch): reset for a new codec epoch before judging audio order, a…
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
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,79 @@ | ||
| import { describe, expect, it } from "bun:test"; | ||
| import { Order } from "./order"; | ||
|
|
||
| type Read = { group: number; frame: { timestamp: number } }; | ||
| const read = (group: number, timestamp: number): Read => ({ group, frame: { timestamp } }); | ||
| const timestamps = (reads: Read[]) => reads.map(({ frame }) => frame.timestamp); | ||
|
|
||
| describe("Order", () => { | ||
| it("releases a held head sorted once a newer group arrives", () => { | ||
| const order = new Order<Read>(() => ({ floor: 100, maxDelay: 1000 })); | ||
| for (const t of [40, 20, 0]) expect(order.push(read(t / 20, t))).toEqual([]); | ||
| expect(timestamps(order.push(read(3, 60)))).toEqual([0, 20, 40, 60]); | ||
| expect(timestamps(order.push(read(4, 80)))).toEqual([80]); | ||
| }); | ||
|
|
||
| // A publisher may keep a long run of audio in one group, which never brings a newer one. | ||
| it("releases a head once its first group runs past the floor", () => { | ||
| const order = new Order<Read>(() => ({ floor: 100, maxDelay: 1000 })); | ||
| expect(order.push(read(5, 0))).toEqual([]); | ||
| expect(order.push(read(4, -20))).toEqual([]); | ||
| expect(order.push(read(5, 100))).toEqual([]); | ||
| expect(timestamps(order.push(read(5, 120)))).toEqual([-20, 0, 100, 120]); | ||
| }); | ||
|
|
||
| // With no floor, playback starts on the first frame, but the head still has to arrive first. | ||
| it("holds the head past its first frame with a zero floor", () => { | ||
| const order = new Order<Read>(() => ({ floor: 0, maxDelay: 1000 })); | ||
| expect(order.push(read(1, 20))).toEqual([]); | ||
| expect(order.push(read(0, 0))).toEqual([]); | ||
| expect(timestamps(order.push(read(1, 40)))).toEqual([0, 20, 40]); | ||
| }); | ||
|
|
||
| // Nothing older than the subscription's max delay is served, so a longer head is complete. | ||
| it("releases a head once it spans the max delay", () => { | ||
| const order = new Order<Read>(() => ({ floor: 100, maxDelay: 60 })); | ||
| for (const t of [60, 40, 20]) expect(order.push(read(t / 20, t))).toEqual([]); | ||
| expect(timestamps(order.push(read(0, 0)))).toEqual([0, 20, 40, 60]); | ||
| }); | ||
|
|
||
| it("releases the head as it stands on a flush", () => { | ||
| const order = new Order<Read>(() => ({ floor: 100, maxDelay: 1000 })); | ||
| order.push(read(1, 20)); | ||
| order.push(read(0, 0)); | ||
| expect(timestamps(order.flush())).toEqual([0, 20]); | ||
| expect(order.flush()).toEqual([]); | ||
| }); | ||
|
|
||
| it("admits a frame only if it is no older than one already admitted", () => { | ||
| const order = new Order<Read>(() => ({ floor: 100, maxDelay: 1000 })); | ||
| order.push(read(1, 20)); | ||
| const released = order.push(read(2, 40)); | ||
| expect(released.every((r) => order.admit(r))).toBe(true); | ||
| expect(order.push(read(0, 0))).toEqual([read(0, 0)]); | ||
| expect(order.admit(read(0, 0))).toBe(false); | ||
|
|
||
| // A reset decoder restamps from its next input, so older frames are welcome again. | ||
| order.reset(); | ||
| expect(order.admit(read(0, 0))).toBe(true); | ||
| }); | ||
|
|
||
| // A rise in the delay while the head arrives must not release it at the old floor. | ||
| it("reads its bounds as the head arrives", () => { | ||
| let floor = 20; | ||
| const order = new Order<Read>(() => ({ floor, maxDelay: 1000 })); | ||
| expect(order.push(read(5, 0))).toEqual([]); | ||
| floor = 100; | ||
| expect(order.push(read(5, 40))).toEqual([]); | ||
| expect(order.push(read(4, -20))).toEqual([]); | ||
| expect(timestamps(order.push(read(5, 120)))).toEqual([-20, 0, 40, 120]); | ||
| }); | ||
|
|
||
| it("holds nothing live", () => { | ||
| const order = new Order<Read>(undefined); | ||
| expect(timestamps(order.push(read(1, 20)))).toEqual([20]); | ||
| expect(order.admit(read(1, 20))).toBe(true); | ||
| expect(timestamps(order.push(read(0, 0)))).toEqual([0]); | ||
| expect(order.admit(read(0, 0))).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
If the numeric or auto delay rises while the subscription head is still being collected, these one-time
peek()values remain at their initial settings even though the existing subscription, consumer, and ring all react to the new delay. A same-group frame can therefore satisfy the stale, smaller floor and release the head; older groups subsequently admitted by the enlargedmaxDelayare then discarded byOrderas older than its released frame, truncating the start of buffered audio. Update the orderer's bounds when the delay changes or derive the release decision from the current signals.Useful? React with 👍 / 👎.
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.
Fixed in f59e54f:
Orderreads its floor and max delay through a getter on every held frame, so a delay change while the head arrives applies to the next release decision. Covered by "reads its bounds as the head arrives".(Written by Claude Opus 5.5)