Clamp simulcast lower layers to top layer#1084
Merged
Merged
Conversation
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.
cloudwebrtc
approved these changes
May 19, 2026
…into hiroshi/clamp-simulcast-layers # Conflicts: # test/utils_test.dart
There was a problem hiding this comment.
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 calculatingscaleResolutionDownBy. - Add
Utils.computeSimulcastPresetsand_clampSimulcastPresetto 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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Testing
dart format --output=none --set-exit-if-changed lib/src/types/video_parameters.dart lib/src/utils.dart test/utils_test.dartflutter test test/utils_test.dartflutter analyze --no-pub lib/src/types/video_parameters.dart lib/src/utils.dart test/utils_test.dart