Repository navigation
feat(watch)!: video selects from the viewer grant, so a small rendition moves up #8061
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
Changes from all commits
b728a69
9273ecc
4e702c5
9f1e931
477b0a6
ae30417
cd84460
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,7 +140,7 @@ export class Game { | |
| broadcast: this.broadcast, | ||
| target: this.#target, | ||
| supported: Watch.Video.Decoder.supported, | ||
| probe: connection.probe, | ||
| rate: new Moq.Signals.Derived([connection.probe], (probe) => probe?.estimatedRecvRate), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }); | ||
| this.#signals.cleanup(() => this.videoSource.close()); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,8 +24,6 @@ export type PlayerInput = { | |
| catalogFormat: Getter<CatalogFormat | undefined>; | ||
| /** Catalog supplied when the format is `manual`. */ | ||
| catalog: Getter<Catalog.Root | undefined>; | ||
| /** Connection probe used for rendition selection. */ | ||
| probe: Getter<Moq.Connection.Probe | undefined>; | ||
| /** Pause media and captions. */ | ||
| paused: Getter<boolean>; | ||
| /** Playback distance from the live edge. */ | ||
|
|
@@ -52,7 +50,10 @@ export type PlayerInput = { | |
| /** Silence audio and stop its download. */ | ||
| muted: Getter<boolean>; | ||
| }; | ||
| /** The claim this player holds on its connection's receive estimate while it downloads. */ | ||
| /** | ||
| * The claim this player holds on its connection's receive estimate while it downloads. Video | ||
| * selects from the claim's grant less the audio it covers, so without a claim it ranks alone. | ||
| */ | ||
| viewer: { | ||
| /** Where to claim, normally the connection's `viewers`; absent claims nothing. */ | ||
| viewers: Getter<Pick<Moq.Bandwidth.Viewers, "watch"> | undefined>; | ||
|
|
@@ -104,6 +105,7 @@ export class Player { | |
| readonly textRenderer: Text.Renderer; | ||
|
|
||
| #videoEnabled = new Signal(false); | ||
| #videoRate = new Signal<number | undefined>(undefined); | ||
| #audioEnabled = new Signal(false); | ||
| #captionsEnabled = new Signal(false); | ||
| #signals = new Effect(); | ||
|
|
@@ -119,7 +121,6 @@ export class Player { | |
| follow: getter(props.follow ?? true), | ||
| catalogFormat: getter<CatalogFormat | undefined>(props.catalogFormat), | ||
| catalog: getter(props.catalog), | ||
| probe: getter(props.probe), | ||
| paused: getter(props.paused ?? false), | ||
| delay: getter(props.delay ?? "auto"), | ||
| buffer: getter(props.buffer ?? Milli.zero), | ||
|
|
@@ -151,7 +152,7 @@ export class Player { | |
| broadcast: this.broadcast, | ||
| target: this.in.video.target, | ||
| supported: Video.Decoder.supported, | ||
| probe: this.in.probe, | ||
| rate: this.#videoRate, | ||
| }); | ||
| const audioSource = new Audio.Source({ | ||
| broadcast: this.broadcast, | ||
|
|
@@ -202,18 +203,28 @@ export class Player { | |
| this.#signals.cleanup(() => this.textRenderer.close()); | ||
|
|
||
| // Claim only for the media being downloaded, so a hidden or muted player asks for less. | ||
| const audioBitrate = this.#signals.computed((effect) => | ||
| effect.get(this.#audioEnabled) ? (effect.get(audioSource.out.config)?.bitrate ?? 0) : 0, | ||
| ); | ||
| const max = this.#signals.computed((effect) => { | ||
| const video = effect.get(this.#videoEnabled); | ||
| const audio = effect.get(this.#audioEnabled); | ||
| if (!video && !audio) return 0; | ||
| if (!video && !effect.get(this.#audioEnabled)) return 0; | ||
| const override = effect.get(this.in.viewer.max); | ||
| if (override !== undefined) return override; | ||
| let max = 0; | ||
| if (video) max += effect.get(videoSource.out.ceiling) ?? 0; | ||
| if (audio) max += effect.get(audioSource.out.config)?.bitrate ?? 0; | ||
| return max; | ||
| const audio = effect.get(audioBitrate) ?? 0; | ||
| return video ? (effect.get(videoSource.out.ceiling) ?? 0) + audio : audio; | ||
| }); | ||
| const grant = holdViewer(this.#signals, this.in.viewer.viewers, max); | ||
|
|
||
| // Video spends what the grant leaves after the audio it covers. A grant that excludes video, | ||
| // while video isn't downloading, says nothing about it, so selection holds its last rate. | ||
| this.#signals.run((effect) => { | ||
| const rate = effect.get(this.#videoEnabled) ? effect.get(grant) : undefined; | ||
| effect.set( | ||
| this.#videoRate, | ||
| rate === undefined ? undefined : Math.max(0, rate - (effect.get(audioBitrate) ?? 0)), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Technical details# `Video.Source` cannot tell a released claim from an unknown rate
## Affected sites
- `js/watch/src/player.ts:225` — writes `undefined` both when `grant` is undefined and when video is not downloading.
- `js/watch/src/video/source.ts:277` — `this.#rate = effect.get(this.in.rate) ?? this.#rate` never clears the cache, so the input's `undefined` is always a hold.
- `js/watch/src/player.ts:53-56` and `doc/lib/js/watch.md:211-214` — state that without a claim video ranks alone.
- `js/watch/src/player.ts:212-213` — a `viewer.max` of `0` is the documented way to release the claim, so the contradiction is reachable at runtime.
## Required outcome
A player with no claim (no `viewer.viewers`, or `viewer.max` reaching `0` while video downloads) selects the best rendition `video.target` allows, while a claim whose grant is temporarily unknown (reconnect, hidden video) still holds the last selection.
## Suggested approach
`SourceInput.rate` has room for only two states, so split them one of two ways: have the source treat `undefined` as "no rate, rank alone" and let `Player` hold by leaving `#videoRate` unchanged (it alone knows whether a claim exists), or keep the source-side hold and drop the "without a claim it ranks alone" wording from the docs and the body. |
||
| ); | ||
| }); | ||
| holdViewer(this.#signals, this.in.viewer.viewers, max); | ||
|
|
||
| this.#signals.run((effect) => { | ||
| this.#captionsEnabled.set(effect.get(this.in.enabled) && !effect.get(this.in.paused)); | ||
|
|
||
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.
Every visible grid tile downloads video over the one shared
connection(js/moq-boy/src/element.tsx:199passes that same connection to everyGame, and#runVideoEnabledkeeps grid tiles enabled), so each game here still selects against the whole receive estimate with no claim. That is the pooled-overselect case this PR's Problem section names, and the Follow-ups section does not track it; a page with a dozen visible tiles can sum to more than the downlink.Technical details