|
@@ -2149,6 +2149,73 @@ TraceablePeerConnection.prototype._adjustLocalMediaDirection = function(
|
2149
|
2149
|
return localDescription;
|
2150
|
2150
|
};
|
2151
|
2151
|
|
|
2152
|
+/**
|
|
2153
|
+ * Converts an object to a config-like string.
|
|
2154
|
+ *
|
|
2155
|
+ * @param {Object} obj - The object to be converted into a config string.
|
|
2156
|
+ * @returns {String} - The config string.
|
|
2157
|
+ */
|
|
2158
|
+TraceablePeerConnection.prototype.getConfigFromObject = function(obj) {
|
|
2159
|
+ let config = '';
|
|
2160
|
+
|
|
2161
|
+ for (const key of Object.keys(obj)) {
|
|
2162
|
+ config += `${key}=${obj[key]}; `;
|
|
2163
|
+ }
|
|
2164
|
+
|
|
2165
|
+ return config.trim();
|
|
2166
|
+};
|
|
2167
|
+
|
|
2168
|
+/**
|
|
2169
|
+ * Munges the stereo flag as well as the opusMaxAverageBitrate in the SDP, based
|
|
2170
|
+ * on values set through config.js, if present.
|
|
2171
|
+ *
|
|
2172
|
+ * @param {RTCSessionDescription} description that needs to be munged.
|
|
2173
|
+ * @returns {RTCSessionDescription} the munged description.
|
|
2174
|
+ */
|
|
2175
|
+TraceablePeerConnection.prototype.mungeOpus = function(description) {
|
|
2176
|
+ const parsedSdp = transform.parse(description.sdp);
|
|
2177
|
+ const audio = parsedSdp.media.find(mLine => mLine.type === 'audio');
|
|
2178
|
+ const { payload } = audio.rtp.find(protocol => protocol.codec === 'opus');
|
|
2179
|
+
|
|
2180
|
+ if (!payload) {
|
|
2181
|
+ // No Opus.
|
|
2182
|
+ return description;
|
|
2183
|
+ }
|
|
2184
|
+
|
|
2185
|
+ let fmtpOpus = audio.fmtp.find(protocol => protocol.payload === payload);
|
|
2186
|
+
|
|
2187
|
+ if (!fmtpOpus) {
|
|
2188
|
+ fmtpOpus = {
|
|
2189
|
+ payload,
|
|
2190
|
+ config: ''
|
|
2191
|
+ };
|
|
2192
|
+ }
|
|
2193
|
+
|
|
2194
|
+ const fmtpConfig = transform.parseParams(fmtpOpus.config);
|
|
2195
|
+ let sdpChanged = false;
|
|
2196
|
+
|
|
2197
|
+ if (this.options.stereo) {
|
|
2198
|
+ fmtpConfig.stereo = 1;
|
|
2199
|
+ sdpChanged = true;
|
|
2200
|
+ }
|
|
2201
|
+
|
|
2202
|
+ if (this.options.opusMaxAverageBitrate) {
|
|
2203
|
+ fmtpConfig.opusMaxAverageBitrate = this.options.opusMaxAverageBitrate;
|
|
2204
|
+ sdpChanged = true;
|
|
2205
|
+ }
|
|
2206
|
+
|
|
2207
|
+ if (!sdpChanged) {
|
|
2208
|
+ return description;
|
|
2209
|
+ }
|
|
2210
|
+
|
|
2211
|
+ fmtpOpus.config = this.getConfigFromObject(fmtpConfig);
|
|
2212
|
+
|
|
2213
|
+ return new RTCSessionDescription({
|
|
2214
|
+ type: description.type,
|
|
2215
|
+ sdp: transform.write(parsedSdp)
|
|
2216
|
+ });
|
|
2217
|
+};
|
|
2218
|
+
|
2152
|
2219
|
TraceablePeerConnection.prototype.setLocalDescription = function(description) {
|
2153
|
2220
|
let localSdp = description;
|
2154
|
2221
|
|
|
@@ -2157,6 +2224,9 @@ TraceablePeerConnection.prototype.setLocalDescription = function(description) {
|
2157
|
2224
|
// Munge the order of the codecs based on the preferences set through config.js
|
2158
|
2225
|
localSdp = this._mungeCodecOrder(localSdp);
|
2159
|
2226
|
|
|
2227
|
+ // Munge stereo flag and opusMaxAverageBitrate based on config.js
|
|
2228
|
+ localSdp = this.mungeOpus(localSdp);
|
|
2229
|
+
|
2160
|
2230
|
if (browser.usesPlanB()) {
|
2161
|
2231
|
localSdp = this._adjustLocalMediaDirection(localSdp);
|
2162
|
2232
|
localSdp = this._ensureSimulcastGroupIsLast(localSdp);
|
|
@@ -2358,10 +2428,16 @@ TraceablePeerConnection.prototype.setMaxBitRate = function() {
|
2358
|
2428
|
TraceablePeerConnection.prototype.setRemoteDescription = function(description) {
|
2359
|
2429
|
this.trace('setRemoteDescription::preTransform', dumpSDP(description));
|
2360
|
2430
|
|
|
2431
|
+ /* eslint-disable no-param-reassign */
|
|
2432
|
+
|
2361
|
2433
|
// Munge the order of the codecs based on the preferences set through config.js
|
2362
|
|
- // eslint-disable-next-line no-param-reassign
|
2363
|
2434
|
description = this._mungeCodecOrder(description);
|
2364
|
2435
|
|
|
2436
|
+ // Munge stereo flag and opusMaxAverageBitrate based on config.js
|
|
2437
|
+ description = this.mungeOpus(description);
|
|
2438
|
+
|
|
2439
|
+ /* eslint-enable no-param-reassign */
|
|
2440
|
+
|
2365
|
2441
|
if (browser.usesPlanB()) {
|
2366
|
2442
|
// TODO the focus should squeze or explode the remote simulcast
|
2367
|
2443
|
if (this.isSimulcastOn()) {
|