Skip to content

Commit

Permalink
Disable simulcast if an user provides an empty array for custom simul…
Browse files Browse the repository at this point in the history
…cast layers (#382)

* disable simulcast if an user provides empty array for custom layers

* changeset
  • Loading branch information
lukasIO committed Aug 5, 2022
1 parent fc97dd1 commit 8499723
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-ducks-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Disable simulcast if an user provides empty array for custom layers
12 changes: 12 additions & 0 deletions src/room/participant/publishUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ describe('computeVideoEncodings', () => {
expect(encodings![1].maxBitrate).toBe(VideoPresets.h360.encoding.maxBitrate);
});

it('returns one encoding if an empty array is provided for custom screen share layers', () => {
const encodings = computeVideoEncodings(true, 1920, 1080, {
simulcast: true,
screenShareSimulcastLayers: [],
});
expect(encodings).toHaveLength(1);

// ensure they are what we expect
expect(encodings![0].rid).toBe('q');
expect(encodings![0].scaleResolutionDownBy).toBe(1);
});

it('respects provided min resolution', () => {
const encodings = computeVideoEncodings(false, 100, 120, {
simulcast: true,
Expand Down
40 changes: 21 additions & 19 deletions src/room/participant/publishUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,28 @@ export function computeVideoEncodings(
sortPresets(options?.videoSimulcastLayers) ?? defaultSimulcastLayers(isScreenShare, original);
}
let midPreset: VideoPreset | undefined;
const lowPreset = presets[0];
if (presets.length > 1) {
[, midPreset] = presets;
}
if (presets.length > 0) {
const lowPreset = presets[0];
if (presets.length > 1) {
[, midPreset] = presets;
}

// NOTE:
// 1. Ordering of these encodings is important. Chrome seems
// to use the index into encodings to decide which layer
// to disable when CPU constrained.
// So encodings should be ordered in increasing spatial
// resolution order.
// 2. ion-sfu translates rids into layers. So, all encodings
// should have the base layer `q` and then more added
// based on other conditions.
const size = Math.max(width, height);
if (size >= 960 && midPreset) {
return encodingsFromPresets(width, height, [lowPreset, midPreset, original]);
}
if (size >= 480) {
return encodingsFromPresets(width, height, [lowPreset, original]);
// NOTE:
// 1. Ordering of these encodings is important. Chrome seems
// to use the index into encodings to decide which layer
// to disable when CPU constrained.
// So encodings should be ordered in increasing spatial
// resolution order.
// 2. ion-sfu translates rids into layers. So, all encodings
// should have the base layer `q` and then more added
// based on other conditions.
const size = Math.max(width, height);
if (size >= 960 && midPreset) {
return encodingsFromPresets(width, height, [lowPreset, midPreset, original]);
}
if (size >= 480) {
return encodingsFromPresets(width, height, [lowPreset, original]);
}
}
return encodingsFromPresets(width, height, [original]);
}
Expand Down

0 comments on commit 8499723

Please sign in to comment.