|
@@ -2149,22 +2149,6 @@ 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
|
2152
|
/**
|
2169
|
2153
|
* Munges the stereo flag as well as the opusMaxAverageBitrate in the SDP, based
|
2170
|
2154
|
* on values set through config.js, if present.
|
|
@@ -2172,43 +2156,53 @@ TraceablePeerConnection.prototype.getConfigFromObject = function(obj) {
|
2172
|
2156
|
* @param {RTCSessionDescription} description that needs to be munged.
|
2173
|
2157
|
* @returns {RTCSessionDescription} the munged description.
|
2174
|
2158
|
*/
|
2175
|
|
-TraceablePeerConnection.prototype.mungeOpus = function(description) {
|
|
2159
|
+TraceablePeerConnection.prototype._mungeOpus = function(description) {
|
2176
|
2160
|
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');
|
|
2161
|
+ const mLines = parsedSdp.media;
|
2179
|
2162
|
|
2180
|
|
- if (!payload) {
|
2181
|
|
- // No Opus.
|
2182
|
|
- return description;
|
2183
|
|
- }
|
|
2163
|
+ for (const mLine of mLines) {
|
|
2164
|
+ if (mLine.type === 'audio') {
|
|
2165
|
+ const { payload } = mLine.rtp.find(protocol => protocol.codec === 'opus');
|
2184
|
2166
|
|
2185
|
|
- let fmtpOpus = audio.fmtp.find(protocol => protocol.payload === payload);
|
|
2167
|
+ if (!payload) {
|
|
2168
|
+ break;
|
|
2169
|
+ }
|
2186
|
2170
|
|
2187
|
|
- if (!fmtpOpus) {
|
2188
|
|
- fmtpOpus = {
|
2189
|
|
- payload,
|
2190
|
|
- config: ''
|
2191
|
|
- };
|
2192
|
|
- }
|
|
2171
|
+ let fmtpOpus = mLine.fmtp.find(protocol => protocol.payload === payload);
|
|
2172
|
+
|
|
2173
|
+ if (!fmtpOpus) {
|
|
2174
|
+ fmtpOpus = {
|
|
2175
|
+ payload,
|
|
2176
|
+ config: ''
|
|
2177
|
+ };
|
|
2178
|
+ }
|
2193
|
2179
|
|
2194
|
|
- const fmtpConfig = transform.parseParams(fmtpOpus.config);
|
2195
|
|
- let sdpChanged = false;
|
|
2180
|
+ const fmtpConfig = transform.parseParams(fmtpOpus.config);
|
|
2181
|
+ let sdpChanged = false;
|
2196
|
2182
|
|
2197
|
|
- if (this.options.stereo) {
|
2198
|
|
- fmtpConfig.stereo = 1;
|
2199
|
|
- sdpChanged = true;
|
2200
|
|
- }
|
|
2183
|
+ if (this.options.stereo) {
|
|
2184
|
+ fmtpConfig.stereo = 1;
|
|
2185
|
+ sdpChanged = true;
|
|
2186
|
+ }
|
2201
|
2187
|
|
2202
|
|
- if (this.options.opusMaxAverageBitrate) {
|
2203
|
|
- fmtpConfig.opusMaxAverageBitrate = this.options.opusMaxAverageBitrate;
|
2204
|
|
- sdpChanged = true;
|
2205
|
|
- }
|
|
2188
|
+ if (this.options.opusMaxAverageBitrate) {
|
|
2189
|
+ fmtpConfig.opusMaxAverageBitrate = this.options.opusMaxAverageBitrate;
|
|
2190
|
+ sdpChanged = true;
|
|
2191
|
+ }
|
2206
|
2192
|
|
2207
|
|
- if (!sdpChanged) {
|
2208
|
|
- return description;
|
2209
|
|
- }
|
|
2193
|
+ if (!sdpChanged) {
|
|
2194
|
+ break;
|
|
2195
|
+ }
|
2210
|
2196
|
|
2211
|
|
- fmtpOpus.config = this.getConfigFromObject(fmtpConfig);
|
|
2197
|
+ let mungedConfig = '';
|
|
2198
|
+
|
|
2199
|
+ for (const key of Object.keys(fmtpConfig)) {
|
|
2200
|
+ mungedConfig += `${key}=${fmtpConfig[key]}; `;
|
|
2201
|
+ }
|
|
2202
|
+
|
|
2203
|
+ fmtpOpus.config = mungedConfig.trim();
|
|
2204
|
+ }
|
|
2205
|
+ }
|
2212
|
2206
|
|
2213
|
2207
|
return new RTCSessionDescription({
|
2214
|
2208
|
type: description.type,
|
|
@@ -2225,7 +2219,7 @@ TraceablePeerConnection.prototype.setLocalDescription = function(description) {
|
2225
|
2219
|
localSdp = this._mungeCodecOrder(localSdp);
|
2226
|
2220
|
|
2227
|
2221
|
// Munge stereo flag and opusMaxAverageBitrate based on config.js
|
2228
|
|
- localSdp = this.mungeOpus(localSdp);
|
|
2222
|
+ localSdp = this._mungeOpus(localSdp);
|
2229
|
2223
|
|
2230
|
2224
|
if (browser.usesPlanB()) {
|
2231
|
2225
|
localSdp = this._adjustLocalMediaDirection(localSdp);
|
|
@@ -2434,7 +2428,7 @@ TraceablePeerConnection.prototype.setRemoteDescription = function(description) {
|
2434
|
2428
|
description = this._mungeCodecOrder(description);
|
2435
|
2429
|
|
2436
|
2430
|
// Munge stereo flag and opusMaxAverageBitrate based on config.js
|
2437
|
|
- description = this.mungeOpus(description);
|
|
2431
|
+ description = this._mungeOpus(description);
|
2438
|
2432
|
|
2439
|
2433
|
/* eslint-enable no-param-reassign */
|
2440
|
2434
|
|