Skip to content

Commit

Permalink
Fix Simulcast Quality Layers (lynckia#1723)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague authored Jun 14, 2021
1 parent 9f646c8 commit d460f3c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
2 changes: 1 addition & 1 deletion erizo_controller/erizoClient/src/ErizoConnectionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class ErizoConnection extends EventEmitterConst {
log.debug(`message: Adding stream to Connection, ${this.toLog()}, ${stream.toLog()}`);
this.streamsMap.add(stream.getID(), stream);
if (stream.local) {
this.stack.addStream(stream.stream);
this.stack.addStream(stream.stream, stream.hasScreen());
}
}

Expand Down
28 changes: 13 additions & 15 deletions erizo_controller/erizoClient/src/webrtc-stacks/BaseStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,33 +184,31 @@ const BaseStack = (specInput) => {

const defaultSimulcastSpatialLayers = 3;

const possibleLayers = [
{ rid: '3' },
{ rid: '2', scaleResolutionDownBy: 2 },
{ rid: '1', scaleResolutionDownBy: 4 },
];

const getSimulcastParameters = () => {
let numSpatialLayers = that.simulcast.numSpatialLayers || defaultSimulcastSpatialLayers;
const totalLayers = possibleLayers.length;
numSpatialLayers = numSpatialLayers < totalLayers ?
numSpatialLayers : totalLayers;
const scaleResolutionDownBase = 2;
const scaleResolutionDownBaseScreenshare = 1;

const getSimulcastParameters = (isScreenshare) => {
const numSpatialLayers = that.simulcast.numSpatialLayers || defaultSimulcastSpatialLayers;
const parameters = [];
const base = isScreenshare ? scaleResolutionDownBaseScreenshare : scaleResolutionDownBase;

for (let layer = totalLayers - 1; layer >= totalLayers - numSpatialLayers; layer -= 1) {
parameters.push(possibleLayers[layer]);
for (let layer = 1; layer <= numSpatialLayers; layer += 1) {
parameters.push({
rid: (layer).toString(),
scaleResolutionDownBy: base ** (numSpatialLayers - layer),
});
}
return parameters;
};

that.addStream = (streamInput) => {
that.addStream = (streamInput, isScreenshare) => {
const stream = streamInput;
stream.transceivers = [];
stream.getTracks().forEach(async (track) => {
let options = {};
if (track.kind === 'video' && that.simulcast) {
options = {
sendEncodings: getSimulcastParameters(),
sendEncodings: getSimulcastParameters(isScreenshare),
};
}
options.streams = [stream];
Expand Down
30 changes: 14 additions & 16 deletions erizo_controller/erizoClient/src/webrtc-stacks/FirefoxStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,37 @@ const log = Logger.module('FirefoxStack');

const defaultSimulcastSpatialLayers = 3;

const possibleLayers = [
{ rid: '3' },
{ rid: '2', scaleResolutionDownBy: 2 },
{ rid: '1', scaleResolutionDownBy: 4 },
];
const scaleResolutionDownBase = 2;
const scaleResolutionDownBaseScreenshare = 1;

const FirefoxStack = (specInput) => {
log.debug('message: Starting Firefox stack');
const that = BaseStack(specInput);

that.enableSimulcast = sdp => sdp;

const getSimulcastParameters = () => {
let numSpatialLayers = that.simulcast.numSpatialLayers || defaultSimulcastSpatialLayers;
const totalLayers = possibleLayers.length;
numSpatialLayers = numSpatialLayers < totalLayers ?
numSpatialLayers : totalLayers;
const getSimulcastParameters = (isScreenshare) => {
const numSpatialLayers = that.simulcast.numSpatialLayers || defaultSimulcastSpatialLayers;
const parameters = [];
const base = isScreenshare ? scaleResolutionDownBaseScreenshare : scaleResolutionDownBase;

for (let layer = totalLayers - 1; layer >= totalLayers - numSpatialLayers; layer -= 1) {
parameters.push(possibleLayers[layer]);
for (let layer = 1; layer <= numSpatialLayers; layer += 1) {
parameters.push({
rid: (layer).toString(),
scaleResolutionDownBy: base ** (numSpatialLayers - layer),
});
}
return parameters;
};

const getSimulcastParametersForFirefox = (sender) => {
const getSimulcastParametersForFirefox = (sender, isScreenshare) => {
const parameters = sender.getParameters() || {};
parameters.encodings = getSimulcastParameters();
parameters.encodings = getSimulcastParameters(isScreenshare);

return sender.setParameters(parameters);
};

that.addStream = (streamInput) => {
that.addStream = (streamInput, isScreenshare) => {
const stream = streamInput;
stream.transceivers = [];
stream.getTracks().forEach(async (track) => {
Expand All @@ -51,7 +49,7 @@ const FirefoxStack = (specInput) => {
const transceiver = that.peerConnection.addTransceiver(track, options);
stream.transceivers.push(transceiver);
if (track.kind === 'video' && that.simulcast) {
getSimulcastParametersForFirefox(transceiver.sender).catch(() => {});
getSimulcastParametersForFirefox(transceiver.sender, isScreenshare).catch(() => {});
}
});
};
Expand Down

0 comments on commit d460f3c

Please sign in to comment.