Skip to content

Commit 5abc169

Browse files
authored
Ensure maxFps applies for very low framerates (#1362)
* Ensure maxFps applies for very low framerates * naming * Create cyan-bags-shop.md
1 parent 214813d commit 5abc169

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

.changeset/cyan-bags-shop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"livekit-client": patch
3+
---
4+
5+
Ensure maxFps applies for very low framerates

src/room/participant/publishUtils.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ export function computeVideoEncodings(
125125
log.debug('using video encoding', videoEncoding);
126126
}
127127

128+
const sourceFramerate = videoEncoding.maxFramerate;
129+
128130
const original = new VideoPreset(
129131
width,
130132
height,
@@ -216,10 +218,10 @@ export function computeVideoEncodings(
216218
// based on other conditions.
217219
const size = Math.max(width, height);
218220
if (size >= 960 && midPreset) {
219-
return encodingsFromPresets(width, height, [lowPreset, midPreset, original]);
221+
return encodingsFromPresets(width, height, [lowPreset, midPreset, original], sourceFramerate);
220222
}
221223
if (size >= 480) {
222-
return encodingsFromPresets(width, height, [lowPreset, original]);
224+
return encodingsFromPresets(width, height, [lowPreset, original], sourceFramerate);
223225
}
224226
}
225227
return encodingsFromPresets(width, height, [original]);
@@ -344,6 +346,7 @@ function encodingsFromPresets(
344346
width: number,
345347
height: number,
346348
presets: VideoPreset[],
349+
sourceFramerate?: number | undefined,
347350
): RTCRtpEncodingParameters[] {
348351
const encodings: RTCRtpEncodingParameters[] = [];
349352
presets.forEach((preset, idx) => {
@@ -352,13 +355,20 @@ function encodingsFromPresets(
352355
}
353356
const size = Math.min(width, height);
354357
const rid = videoRids[idx];
358+
355359
const encoding: RTCRtpEncodingParameters = {
356360
rid,
357361
scaleResolutionDownBy: Math.max(1, size / Math.min(preset.width, preset.height)),
358362
maxBitrate: preset.encoding.maxBitrate,
359363
};
360-
if (preset.encoding.maxFramerate) {
361-
encoding.maxFramerate = preset.encoding.maxFramerate;
364+
// ensure that the sourceFramerate is the highest framerate applied across all layers so that the
365+
// original encoding doesn't get bumped unintentionally by any of the other layers
366+
const maxFramerate =
367+
sourceFramerate && preset.encoding.maxFramerate
368+
? Math.min(sourceFramerate, preset.encoding.maxFramerate)
369+
: preset.encoding.maxFramerate;
370+
if (maxFramerate) {
371+
encoding.maxFramerate = maxFramerate;
362372
}
363373
const canSetPriority = isFireFox() || idx === 0;
364374
if (preset.encoding.priority && canSetPriority) {

0 commit comments

Comments
 (0)