Skip to content

Better track settings#1047

Draft
hiroshihorie wants to merge 12 commits into
mainfrom
hiroshi/better-track-settings
Draft

Better track settings#1047
hiroshihorie wants to merge 12 commits into
mainfrom
hiroshi/better-track-settings

Conversation

@hiroshihorie
Copy link
Copy Markdown
Member

@hiroshihorie hiroshihorie commented Apr 1, 2026

Attempt to use a "merged" logic with user track preference when adaptiveStream is enabled, instead of ignoring or throwing .

@hiroshihorie hiroshihorie changed the title Hiroshi/better track settings Better track settings May 29, 2026
A manual setVideoQuality/Dimensions/FPS/enable/disable sent immediately via
_emitTrackUpdate() but did not cancel a pending debounced visibility send. The
debounce captured a stale settings snapshot that could fire ~1.5s later and
overwrite the manual update; since the visibility send never updated
_lastSentTrackSettings, the dedup gate then suppressed any re-correction,
leaving the server permanently on stale settings.

- _emitTrackUpdate() now cancels any pending debounced send before sending.
- the debounced send re-builds from current state at fire time and updates
  _lastSentTrackSettings, so it can never deliver or wedge on stale settings.
Mirrors the JS SDK tri-state. Previously `disabled` was computed as
`!_enabled || !_adaptiveStreamEnabled`, an OR that meant an explicit enable()
could never keep an off-screen track streaming when adaptive stream was on.

- Replace the plain bool _enabled with a tri-state bool? _requestedDisabled
  (null = no explicit request); an explicit enable()/disable() now takes
  precedence over visibility, matching JS isEnabled.
- Decouple the misnamed _adaptiveStreamEnabled into _adaptiveStreamActive
  (feature active for this pub) and _adaptiveStreamVisible (views visible).
- Extract the precedence into a pure resolveDisabled() in track_settings.dart.
The annotation pointed callers at the private _emitTrackUpdate (unusable
externally), contradicted the @internal annotation, and was suppressed for the
only same-package caller (room.dart) by analysis_options anyway. Keep it as a
plain @internal shim.
The merge is performed client-side (resolveVideoSettings), and only the single
resolved value is sent; the server does not receive both and pick the smaller.
The existing 'equal areas keep preferred' test passed identical dimensions as
both adaptive and preferred, so the assertion held regardless of which branch
ran and could not catch a < -> <= regression. Use distinct same-area
dimensions (720x320 vs 640x360), and add a one-px-smaller case where adaptive
should win.
_buildTrackSettings had no coverage for the disabled computation, fps
passthrough, or the proto field mapping. Extract the proto assembly into a pure
buildUpdateTrackSettings() (alongside the new resolveDisabled()) so both are
unit-testable without a live RemoteTrackPublication, and add tests for the
tri-state disabled precedence and the dimensions/quality/fps mapping.
Replace the nullable bool _requestedDisabled (null/false/true) with an
@internal TrackEnabledPreference { unset, enabled, disabled } enum. Removes the
double-negative (requestedDisabled = false meaning 'enabled') and makes the
precedence in resolveDisabled() read as an explicit switch. Behavior is
unchanged; the enum is internal-only (non-exported file, @internal).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant