Skip to content

Commit

Permalink
New Client API to update active simulcast layers for publishers (lync…
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague authored Jul 14, 2020
1 parent 6c19bcd commit b040a1a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 17 deletions.
10 changes: 10 additions & 0 deletions doc/client_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ In the next table we can see the functions of this class:
| [getVideoFrameURL()](#get-the-url-of-a-frame-from-the-video) | It gets the URL of a Bitmap from the video. |
| [updateConfiguration(config, callback)](#update-the-spec-of-a-stream) | Updates the spec of a stream. |
| [updateSimulcastLayersBitrate(config)](#update-simulcast-layers-bitrate) | Updates the bitrates for each simulcast layer. |
| [updateSimulcastActiveLayers(config)](#update-simulcast-active-layers) | Updates if each simulcast layer is active. |

## Check if the stream has audio, video and/or data active

Expand Down Expand Up @@ -321,6 +322,15 @@ localStream.updateSimulcastLayersBitrate({0: 80000, 1: 430000});

In this example we are configuring 2 spatial layers bitrates, limiting the lower layer to 80 Kbps and the higher to 430 Kbps.

## Update Simulcast Active Layers

We can decide which Simulcast layers are active. It can only be applied to publishers.
```
localStream.updateSimulcastActiveLayers({0: true, 1: false});
```

In this example we are disabling layer 1 while the other layer (0) is active.

# Room

It represents a Licode Room. It will handle the connection, local stream publication and remote stream subscription.
Expand Down
4 changes: 4 additions & 0 deletions erizo_controller/erizoClient/src/ErizoConnectionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ class ErizoConnection extends EventEmitterConst {
this.stack.updateSimulcastLayersBitrate(bitrates);
}

updateSimulcastActiveLayers(layersInfo) {
this.stack.updateSimulcastActiveLayers(layersInfo);
}

setQualityLevel(level) {
this.qualityLevel = QUALITY_LEVELS[level];
}
Expand Down
6 changes: 6 additions & 0 deletions erizo_controller/erizoClient/src/Stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ const Stream = (altConnectionHelpers, specInput) => {
}
};

that.updateSimulcastActiveLayers = (layersInfo) => {
if (that.pc && that.local) {
that.pc.updateSimulcastActiveLayers(layersInfo);
}
};

that.updateConfiguration = (config, callback = () => {}) => {
if (config === undefined) { return; }
if (that.pc) {
Expand Down
34 changes: 27 additions & 7 deletions erizo_controller/erizoClient/src/webrtc-stacks/BaseStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const BaseStack = (specInput) => {
log.debug(`message: Setting local description, localDesc: ${JSON.stringify(localDesc)}`);
logSDP('processOffer - Local Description', localDesc.type);
return that.peerConnection.setLocalDescription(localDesc).then(() => {
that.setSimulcastLayersBitrate();
that.setSimulcastLayersConfig();
});
};

Expand Down Expand Up @@ -410,7 +410,7 @@ const BaseStack = (specInput) => {
const rejectMessages = [];
return that.peerConnection.setLocalDescription(localDesc)
.then(() => {
that.setSimulcastLayersBitrate();
that.setSimulcastLayersConfig();
logSDP('processAnswer - Remote Description', msg.type);
that.peerConnection.setRemoteDescription(new RTCSessionDescription(msg));
})
Expand Down Expand Up @@ -455,7 +455,7 @@ const BaseStack = (specInput) => {
logSDP('protectedNegotiateBW - Local Description', localDesc.type);
that.peerConnection.setLocalDescription(localDesc)
.then(() => {
that.setSimulcastLayersBitrate();
that.setSimulcastLayersConfig();
remoteSdp = SemanticSdp.SDPInfo.processString(remoteDesc.sdp);
SdpHelpers.setMaxBW(remoteSdp, specBase);
remoteDesc.sdp = remoteSdp.toString();
Expand Down Expand Up @@ -559,14 +559,34 @@ const BaseStack = (specInput) => {
return sdpInput;
};

that.updateSimulcastLayersBitrate = (bitrates) => {
const setSpatialLayersConfig = (field, values, check = () => true) => {
if (that.simulcast) {
that.simulcast.spatialLayerBitrates = bitrates;
that.setSimulcastLayersBitrate();
Object.keys(values).forEach((layerId) => {
const value = values[layerId];
if (!that.simulcast.spatialLayerConfigs) {
that.simulcast.spatialLayerConfigs = {};
}
if (!that.simulcast.spatialLayerConfigs[layerId]) {
that.simulcast.spatialLayerConfigs[layerId] = {};
}
if (check(value)) {
that.simulcast.spatialLayerConfigs[layerId][field] = value;
}
});
that.setSimulcastLayersConfig();
}
};

that.setSimulcastLayersBitrate = () => {
that.updateSimulcastLayersBitrate = (bitrates) => {
setSpatialLayersConfig('maxBitrate', bitrates);
};

that.updateSimulcastActiveLayers = (layersInfo) => {
const ifIsBoolean = value => value === true || value === false;
setSpatialLayersConfig('active', layersInfo, ifIsBoolean);
};

that.setSimulcastLayersConfig = () => {
log.error('message: Simulcast not implemented');
};

Expand Down
33 changes: 23 additions & 10 deletions erizo_controller/erizoClient/src/webrtc-stacks/ChromeStableStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,45 @@ const ChromeStableStack = (specInput) => {
return sdp.replace(matchGroup[0], result);
};

const configureParameter = (parameters, config, layerId) => {
if (parameters.encodings[layerId] === undefined ||
config[layerId] === undefined) {
return parameters;
}
const newParameters = parameters;
newParameters.encodings[layerId].maxBitrate = config[layerId].maxBitrate;
if (config[layerId].active !== undefined) {
newParameters.encodings[layerId].active = config[layerId].active;
}
return newParameters;
};

const setBitrateForVideoLayers = (sender) => {
if (typeof sender.getParameters !== 'function' || typeof sender.setParameters !== 'function') {
log.warning('message: Cannot set simulcast layers bitrate, reason: get/setParameters not available');
return;
}
const parameters = sender.getParameters();
Object.keys(that.simulcast.spatialLayerBitrates).forEach((key) => {
if (parameters.encodings[key] !== undefined) {
log.debug(`message: Setting bitrate for layer, layer: ${key}, bps: ${that.simulcast.spatialLayerBitrates[key]}`);
parameters.encodings[key].maxBitrate = that.simulcast.spatialLayerBitrates[key];
let parameters = sender.getParameters();
Object.keys(that.simulcast.spatialLayerConfigs).forEach((layerId) => {
if (parameters.encodings[layerId] !== undefined) {
log.debug(`message: Configure parameters for layer, layer: ${layerId}, config: ${that.simulcast.spatialLayerConfigs[layerId]}`);
parameters = configureParameter(parameters, that.simulcast.spatialLayerConfigs, layerId);
}
});
sender.setParameters(parameters)
.then((result) => {
log.debug(`message: Success setting simulcast layer bitrates, result: ${result}`);
log.debug(`message: Success setting simulcast layer configs, result: ${result}`);
})
.catch((e) => {
log.warning(`message: Error setting simulcast layer bitrates, error: ${e}`);
log.warning(`message: Error setting simulcast layer configs, error: ${e}`);
});
};

that.prepareCreateOffer = () => Promise.resolve();

that.setSimulcastLayersBitrate = () => {
log.debug(`message: Maybe set simulcast Layers bitrate, simulcast: ${JSON.stringify(that.simulcast)}`);
if (that.simulcast && that.simulcast.spatialLayerBitrates) {
that.setSimulcastLayersConfig = () => {
log.debug(`message: Maybe set simulcast Layers config, simulcast: ${JSON.stringify(that.simulcast)}`);
if (that.simulcast && that.simulcast.spatialLayerConfigs) {
that.peerConnection.getSenders().forEach((sender) => {
if (sender.track.kind === 'video') {
setBitrateForVideoLayers(sender);
Expand Down

0 comments on commit b040a1a

Please sign in to comment.