Skip to content

Commit 3488ba8

Browse files
authored
Align screen-share simulcast default lower layer (#1089)
## Summary Align Flutter's generated default lower screen-share simulcast layer with the common SDK behavior. This updates the default generated lower layer to: - use half resolution - keep the top layer's frame rate - use `max(150kbps, topLayerBitrate / 4)` - carry through explicit bitrate/network priorities Also aligns the `screenShareH720FPS5` and `screenShareH1080FPS30` preset bitrates with the common SDK values. ## Notes This does not add the JS-only screen-share presets such as `h360fps15`, `h720fps30`, or `original`; that broader preset parity work should be handled separately. ## Tests - `dart format --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`
1 parent c5103bf commit 3488ba8

4 files changed

Lines changed: 68 additions & 11 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patch type="fixed" "Align screen share simulcast default low layer"

lib/src/types/video_parameters.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ extension VideoParametersPresets on VideoParameters {
274274
static const screenShareH720FPS5 = VideoParameters(
275275
dimensions: VideoDimensionsPresets.h720_169,
276276
encoding: VideoEncoding(
277-
maxBitrate: 400 * 1000,
277+
maxBitrate: 800 * 1000,
278278
maxFramerate: 5,
279279
),
280280
);
@@ -298,7 +298,7 @@ extension VideoParametersPresets on VideoParameters {
298298
static const screenShareH1080FPS30 = VideoParameters(
299299
dimensions: VideoDimensionsPresets.h1080_169,
300300
encoding: VideoEncoding(
301-
maxBitrate: 4000 * 1000,
301+
maxBitrate: 5000 * 1000,
302302
maxFramerate: 30,
303303
),
304304
);

lib/src/utils.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,23 +229,24 @@ class Utils {
229229
static List<VideoParameters> _computeDefaultScreenShareSimulcastParams({
230230
required VideoParameters original,
231231
}) {
232-
final layers = [rtc.RTCRtpEncoding(scaleResolutionDownBy: 2, maxFramerate: 3)];
233-
return layers.map((e) {
234-
final scale = e.scaleResolutionDownBy ?? 1;
235-
final fps = e.maxFramerate ?? 3;
232+
final originalEncoding = original.encoding!;
233+
const scale = 2.0;
236234

237-
return VideoParameters(
235+
return [
236+
VideoParameters(
238237
dimensions:
239238
VideoDimensions((original.dimensions.width / scale).floor(), (original.dimensions.height / scale).floor()),
240239
encoding: VideoEncoding(
241240
maxBitrate: math.max(
242241
150 * 1000,
243-
(original.encoding!.maxBitrate / (math.pow(scale, 2) * (original.encoding!.maxFramerate / fps))).floor(),
242+
(originalEncoding.maxBitrate / math.pow(scale, 2)).floor(),
244243
),
245-
maxFramerate: fps,
244+
maxFramerate: originalEncoding.maxFramerate,
245+
bitratePriority: originalEncoding.bitratePriority,
246+
networkPriority: originalEncoding.networkPriority,
246247
),
247-
);
248-
}).toList();
248+
),
249+
];
249250
}
250251

251252
static List<VideoParameters> _computeDefaultSimulcastParams({

test/utils_test.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
// limitations under the License.
1414

1515
import 'package:flutter_test/flutter_test.dart';
16+
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
1617

18+
import 'package:livekit_client/livekit_client.dart' as lk;
1719
import 'package:livekit_client/src/utils.dart';
1820

1921
void main() {
@@ -54,4 +56,57 @@ void main() {
5456
),
5557
);
5658
});
59+
60+
group('screen share simulcast encodings', () {
61+
test('screen share preset bitrates match common SDK presets', () {
62+
expect(lk.VideoParametersPresets.screenShareH720FPS5.encoding?.maxBitrate, 800000);
63+
expect(lk.VideoParametersPresets.screenShareH1080FPS30.encoding?.maxBitrate, 5000000);
64+
});
65+
66+
test('default lower layer follows top layer fps and priorities', () {
67+
final encodings = Utils.computeVideoEncodings(
68+
isScreenShare: true,
69+
dimensions: const lk.VideoDimensions(1920, 1080),
70+
options: const lk.VideoPublishOptions(
71+
screenShareEncoding: lk.VideoEncoding(
72+
maxBitrate: 2500000,
73+
maxFramerate: 15,
74+
bitratePriority: lk.Priority.high,
75+
networkPriority: lk.Priority.high,
76+
),
77+
),
78+
);
79+
80+
expect(encodings, hasLength(2));
81+
82+
final lowLayer = encodings![0];
83+
expect(lowLayer.rid, 'q');
84+
expect(lowLayer.scaleResolutionDownBy, 2);
85+
expect(lowLayer.maxFramerate, 15);
86+
expect(lowLayer.maxBitrate, 625000);
87+
expect(lowLayer.priority, rtc.RTCPriorityType.high);
88+
expect(lowLayer.networkPriority, rtc.RTCPriorityType.high);
89+
});
90+
91+
test('default lower layer follows selected screen share preset', () {
92+
final encodings = Utils.computeVideoEncodings(
93+
isScreenShare: true,
94+
dimensions: const lk.VideoDimensions(1920, 1080),
95+
);
96+
97+
expect(encodings, hasLength(2));
98+
99+
final lowLayer = encodings![0];
100+
expect(lowLayer.rid, 'q');
101+
expect(lowLayer.scaleResolutionDownBy, 2);
102+
expect(lowLayer.maxFramerate, 15);
103+
expect(lowLayer.maxBitrate, 625000);
104+
105+
final topLayer = encodings[1];
106+
expect(topLayer.rid, 'h');
107+
expect(topLayer.scaleResolutionDownBy, 1);
108+
expect(topLayer.maxFramerate, 15);
109+
expect(topLayer.maxBitrate, 2500000);
110+
});
111+
});
57112
}

0 commit comments

Comments
 (0)