Quellcode durchsuchen

Implement review changes 1

dev1
Mihai-Andrei Uscat vor 4 Jahren
Ursprung
Commit
e83c1234d0
3 geänderte Dateien mit 57 neuen und 73 gelöschten Zeilen
  1. 14
    23
      modules/RTC/RTCUtils.js
  2. 3
    4
      modules/RTC/ScreenObtainer.js
  3. 40
    46
      modules/RTC/TraceablePeerConnection.js

+ 14
- 23
modules/RTC/RTCUtils.js Datei anzeigen

93
 // Disables Highpass Filter
93
 // Disables Highpass Filter
94
 let disableHPF = false;
94
 let disableHPF = false;
95
 
95
 
96
-// Channel count used to enable stereo.
97
-let channelCount = null;
96
+// Enables stereo.
97
+let stereo = null;
98
 
98
 
99
 const featureDetectionAudioEl = document.createElement('audio');
99
 const featureDetectionAudioEl = document.createElement('audio');
100
 const isAudioOutputDeviceChangeAvailable
100
 const isAudioOutputDeviceChangeAvailable
414
             constraints.audio = {};
414
             constraints.audio = {};
415
         }
415
         }
416
 
416
 
417
-        // Use the standard audio constraints on non-chromium browsers.
418
-        if (browser.isFirefox() || browser.isWebKitBased()) {
419
-            constraints.audio = {
420
-                deviceId: options.micDeviceId,
421
-                autoGainControl: !disableAGC && !disableAP,
422
-                echoCancellation: !disableAEC && !disableAP,
423
-                noiseSuppression: !disableNS && !disableAP
424
-            };
425
-        } else {
426
-            constraints.audio = {
427
-                autoGainControl: { exact: !disableAGC && !disableAP },
428
-                channelCount,
429
-                deviceId: options.micDeviceId,
430
-                echoCancellation: { exact: !disableAEC && !disableAP },
431
-                noiseSuppression: { exact: !disableNS && !disableAP },
432
-                sampleRate: 48000
433
-            };
417
+        constraints.audio = {
418
+            autoGainControl: { exact: !disableAGC && !disableAP },
419
+            deviceId: options.micDeviceId,
420
+            echoCancellation: { exact: !disableAEC && !disableAP },
421
+            noiseSuppression: { exact: !disableNS && !disableAP }
422
+        };
423
+
424
+        if (stereo) {
425
+            Object.assign(constraints.audio, { channelCount: 2 });
434
         }
426
         }
435
     } else {
427
     } else {
436
         constraints.audio = false;
428
         constraints.audio = false;
767
             disableHPF = options.disableHPF;
759
             disableHPF = options.disableHPF;
768
             logger.info(`Disable HPF: ${disableHPF}`);
760
             logger.info(`Disable HPF: ${disableHPF}`);
769
         }
761
         }
770
-
771
-        if (typeof options.channelCount === 'number') {
772
-            channelCount = options.channelCount;
773
-            logger.info(`Channel count: ${channelCount}`);
762
+        if (typeof options.stereo === 'boolean') {
763
+            stereo = options.stereo;
764
+            logger.info(`Stereo: ${stereo}`);
774
         }
765
         }
775
 
766
 
776
         window.clearInterval(availableDevicesPollTimer);
767
         window.clearInterval(availableDevicesPollTimer);

+ 3
- 4
modules/RTC/ScreenObtainer.js Datei anzeigen

163
             getDisplayMedia = navigator.mediaDevices.getDisplayMedia.bind(navigator.mediaDevices);
163
             getDisplayMedia = navigator.mediaDevices.getDisplayMedia.bind(navigator.mediaDevices);
164
         }
164
         }
165
 
165
 
166
-        const { channelCount, disableAGC, disableAP, enableHdAudio } = this.options;
166
+        const { disableAGC, disableAP, enableHdAudio } = this.options;
167
         const audioProcessingValue = !disableAGC && !disableAP;
167
         const audioProcessingValue = !disableAGC && !disableAP;
168
         const audio = enableHdAudio ? {
168
         const audio = enableHdAudio ? {
169
             autoGainControl: audioProcessingValue,
169
             autoGainControl: audioProcessingValue,
170
-            channelCount,
170
+            channelCount: 2,
171
             echoCancellation: audioProcessingValue,
171
             echoCancellation: audioProcessingValue,
172
-            noiseSuppression: audioProcessingValue,
173
-            sampleRate: 48000
172
+            noiseSuppression: audioProcessingValue
174
         } : true;
173
         } : true;
175
 
174
 
176
         getDisplayMedia({
175
         getDisplayMedia({

+ 40
- 46
modules/RTC/TraceablePeerConnection.js Datei anzeigen

2149
     return localDescription;
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
  * Munges the stereo flag as well as the opusMaxAverageBitrate in the SDP, based
2153
  * Munges the stereo flag as well as the opusMaxAverageBitrate in the SDP, based
2170
  * on values set through config.js, if present.
2154
  * on values set through config.js, if present.
2172
  * @param {RTCSessionDescription} description that needs to be munged.
2156
  * @param {RTCSessionDescription} description that needs to be munged.
2173
  * @returns {RTCSessionDescription} the munged description.
2157
  * @returns {RTCSessionDescription} the munged description.
2174
  */
2158
  */
2175
-TraceablePeerConnection.prototype.mungeOpus = function(description) {
2159
+TraceablePeerConnection.prototype._mungeOpus = function(description) {
2176
     const parsedSdp = transform.parse(description.sdp);
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
     return new RTCSessionDescription({
2207
     return new RTCSessionDescription({
2214
         type: description.type,
2208
         type: description.type,
2225
     localSdp = this._mungeCodecOrder(localSdp);
2219
     localSdp = this._mungeCodecOrder(localSdp);
2226
 
2220
 
2227
     // Munge stereo flag and opusMaxAverageBitrate based on config.js
2221
     // Munge stereo flag and opusMaxAverageBitrate based on config.js
2228
-    localSdp = this.mungeOpus(localSdp);
2222
+    localSdp = this._mungeOpus(localSdp);
2229
 
2223
 
2230
     if (browser.usesPlanB()) {
2224
     if (browser.usesPlanB()) {
2231
         localSdp = this._adjustLocalMediaDirection(localSdp);
2225
         localSdp = this._adjustLocalMediaDirection(localSdp);
2434
     description = this._mungeCodecOrder(description);
2428
     description = this._mungeCodecOrder(description);
2435
 
2429
 
2436
     // Munge stereo flag and opusMaxAverageBitrate based on config.js
2430
     // Munge stereo flag and opusMaxAverageBitrate based on config.js
2437
-    description = this.mungeOpus(description);
2431
+    description = this._mungeOpus(description);
2438
 
2432
 
2439
     /* eslint-enable no-param-reassign */
2433
     /* eslint-enable no-param-reassign */
2440
 
2434
 

Laden…
Abbrechen
Speichern