Skip to content

Clamp simulcast lower layers to top layer#1084

Merged
hiroshihorie merged 9 commits into
mainfrom
hiroshi/clamp-simulcast-layers
Jun 1, 2026
Merged

Clamp simulcast lower layers to top layer#1084
hiroshihorie merged 9 commits into
mainfrom
hiroshi/clamp-simulcast-layers

Conversation

@hiroshihorie
Copy link
Copy Markdown
Member

@hiroshihorie hiroshihorie commented May 15, 2026

Summary

  • Port Swift SDK simulcast lower-layer clamping behavior to Flutter.
  • Clamp lower-layer max framerate so it does not exceed the configured top layer.
  • Clamp lower-layer bitrate only when the layer does not actually downscale resolution.
  • Use the larger output dimension when computing simulcast scale-down values.
  • Add coverage for clamp behavior, ladder length, unchanged presets, priority preservation, and computed encodings.

Testing

  • dart format --output=none --set-exit-if-changed lib/src/types/video_parameters.dart lib/src/utils.dart test/utils_test.dart
  • flutter test test/utils_test.dart
  • flutter analyze --no-pub lib/src/types/video_parameters.dart lib/src/utils.dart test/utils_test.dart

Ports the four SimulcastPresetsTests cases that were missing from the
initial port: same-resolution full clamp, parameterized ladder length
over the < 480 / [480, 960) / >= 960 cutoffs, no-overshoot pass-through,
and priority forwarding through the clamp.
Mirrors the Swift guard let lowPreset = presets.first else { return
[baseParameters] } fallback. Unreachable from current call sites since
both default ladders return >= 1 entry, but keeps the function safe
against future callers passing an empty requestedPresets with a default
that could collapse to empty.
Use max/max (preset's larger dimension vs output's larger dimension) to
match the Swift Dimensions.encodings(from:) helper and the new
_clampSimulcastPreset's scaleDownBy calculation. Equivalent for
matching-aspect presets, only differs when a caller mixes a
non-matching-aspect preset with the output dimensions.
@hiroshihorie hiroshihorie changed the title Hiroshi/clamp simulcast layers Clamp simulcast layers May 18, 2026
@hiroshihorie hiroshihorie marked this pull request as ready for review May 19, 2026 10:49
…into hiroshi/clamp-simulcast-layers

# Conflicts:
#	test/utils_test.dart
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ports simulcast lower-layer clamping behavior to the Flutter SDK so lower simulcast layers can’t exceed the configured top layer in framerate, and only clamp bitrate when the “lower” layer doesn’t actually downscale resolution. It also adjusts how simulcast scale-down factors and ladder length are computed by using the larger output dimension.

Changes:

  • Update simulcast encoding scale computation to use the larger dimension (max) when calculating scaleResolutionDownBy.
  • Add Utils.computeSimulcastPresets and _clampSimulcastPreset to clamp lower-layer framerate (always) and bitrate (only when no real downscale occurs).
  • Add/expand tests covering clamping behavior, ladder length selection, unchanged pass-through behavior, priority preservation, and computed RTC encodings.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
lib/src/utils.dart Adjusts simulcast scaling calculations and introduces preset computation + clamping logic used by encoding generation.
test/utils_test.dart Adds unit tests validating simulcast preset clamping and encoding computation behavior.
.changes/clamp-simulcast-lower-layers Adds a changelog entry for the simulcast clamping fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hiroshihorie hiroshihorie changed the title Clamp simulcast layers Clamp simulcast lower layers to top layer Jun 1, 2026
@hiroshihorie hiroshihorie merged commit d83f272 into main Jun 1, 2026
17 checks passed
@hiroshihorie hiroshihorie deleted the hiroshi/clamp-simulcast-layers branch June 1, 2026 12:04
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.

3 participants