Browse Source

fix(statistics) Use RTCRtpReceiver:getSynchronizationSources for audioLevels always.

Track based stats have been removed recently and RTCRtpReceiver:getSynchronizationSources has been available in the browsers for a while now.
master
Jaya Allamsetty 2 years ago
parent
commit
99feab14c0

+ 1
- 5
modules/browser/BrowserCapabilities.js View File

@@ -200,11 +200,7 @@ export default class BrowserCapabilities extends BrowserDetection {
200 200
      */
201 201
     supportsReceiverStats() {
202 202
         return typeof window.RTCRtpReceiver !== 'undefined'
203
-            && Object.keys(RTCRtpReceiver.prototype).indexOf('getSynchronizationSources') > -1
204
-
205
-            // Disable this on Safari because it is reporting 0.000001 as the audio levels for all
206
-            // remote audio tracks.
207
-            && !this.isWebKitBased();
203
+            && Object.keys(RTCRtpReceiver.prototype).indexOf('getSynchronizationSources') > -1;
208 204
     }
209 205
 
210 206
     /**

+ 13
- 19
modules/detection/NoAudioSignalDetection.js View File

@@ -2,7 +2,6 @@ import EventEmitter from 'events';
2 2
 
3 3
 import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
4 4
 import * as JitsiTrackEvents from '../../JitsiTrackEvents';
5
-import browser from '../browser';
6 5
 
7 6
 import * as DetectionEvents from './DetectionEvents';
8 7
 
@@ -32,9 +31,6 @@ export default class NoAudioSignalDetection extends EventEmitter {
32 31
         this._timeoutTrigger = null;
33 32
         this._hasAudioInput = null;
34 33
 
35
-        if (!browser.supportsReceiverStats()) {
36
-            conference.statistics.addAudioLevelListener(this._audioLevel.bind(this));
37
-        }
38 34
         conference.on(JitsiConferenceEvents.TRACK_ADDED, this._trackAdded.bind(this));
39 35
     }
40 36
 
@@ -132,21 +128,19 @@ export default class NoAudioSignalDetection extends EventEmitter {
132 128
             this._clearTriggerTimeout();
133 129
 
134 130
             // Listen for the audio levels on the newly added audio track
135
-            if (browser.supportsReceiverStats()) {
136
-                track.on(
137
-                    JitsiTrackEvents.NO_AUDIO_INPUT,
138
-                    audioLevel => {
139
-                        this._handleNoAudioInputDetection(audioLevel);
140
-                    }
141
-                );
142
-                track.on(
143
-                    JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
144
-                    audioLevel => {
145
-                        this._handleNoAudioInputDetection(audioLevel);
146
-                        this._handleAudioInputStateChange(audioLevel);
147
-                    }
148
-                );
149
-            }
131
+            track.on(
132
+                JitsiTrackEvents.NO_AUDIO_INPUT,
133
+                audioLevel => {
134
+                    this._handleNoAudioInputDetection(audioLevel);
135
+                }
136
+            );
137
+            track.on(
138
+                JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
139
+                audioLevel => {
140
+                    this._handleNoAudioInputDetection(audioLevel);
141
+                    this._handleAudioInputStateChange(audioLevel);
142
+                }
143
+            );
150 144
         }
151 145
     }
152 146
 }

+ 14
- 71
modules/statistics/RTPStatsCollector.js View File

@@ -134,8 +134,6 @@ function ConferenceStats() {
134 134
  */
135 135
 export default function StatsCollector(peerconnection, audioLevelsInterval, statsInterval, eventEmitter) {
136 136
     this.peerconnection = peerconnection;
137
-    this.baselineAudioLevelsReport = null;
138
-    this.currentAudioLevelsReport = null;
139 137
     this.currentStatsReport = null;
140 138
     this.previousStatsReport = null;
141 139
     this.audioLevelReportHistory = {};
@@ -196,40 +194,23 @@ StatsCollector.prototype.errorCallback = function(error) {
196 194
  * Starts stats updates.
197 195
  */
198 196
 StatsCollector.prototype.start = function(startAudioLevelStats) {
199
-    if (startAudioLevelStats) {
200
-        if (browser.supportsReceiverStats()) {
201
-            logger.info('Using RTCRtpSynchronizationSource for remote audio levels');
202
-        }
197
+    if (startAudioLevelStats && browser.supportsReceiverStats()) {
203 198
         this.audioLevelsIntervalId = setInterval(
204 199
             () => {
205
-                if (browser.supportsReceiverStats()) {
206
-                    const audioLevels = this.peerconnection.getAudioLevels(this.speakerList);
207
-
208
-                    for (const ssrc in audioLevels) {
209
-                        if (audioLevels.hasOwnProperty(ssrc)) {
210
-                            // Use a scaling factor of 2.5 to report the same
211
-                            // audio levels that getStats reports.
212
-                            const audioLevel = audioLevels[ssrc] * 2.5;
213
-
214
-                            this.eventEmitter.emit(
215
-                                StatisticsEvents.AUDIO_LEVEL,
216
-                                this.peerconnection,
217
-                                Number.parseInt(ssrc, 10),
218
-                                audioLevel,
219
-                                false /* isLocal */);
220
-                        }
200
+                const audioLevels = this.peerconnection.getAudioLevels(this.speakerList);
201
+
202
+                for (const ssrc in audioLevels) {
203
+                    if (audioLevels.hasOwnProperty(ssrc)) {
204
+                        // Use a scaling factor of 2.5 to report the same audio levels that getStats reports.
205
+                        const audioLevel = audioLevels[ssrc] * 2.5;
206
+
207
+                        this.eventEmitter.emit(
208
+                            StatisticsEvents.AUDIO_LEVEL,
209
+                            this.peerconnection,
210
+                            Number.parseInt(ssrc, 10),
211
+                            audioLevel,
212
+                            false /* isLocal */);
221 213
                     }
222
-                } else {
223
-                    // Interval updates
224
-                    this.peerconnection.getStats()
225
-                        .then(report => {
226
-                            this.currentAudioLevelsReport = typeof report?.result === 'function'
227
-                                ? report.result()
228
-                                : report;
229
-                            this.processAudioLevelReport();
230
-                            this.baselineAudioLevelsReport = this.currentAudioLevelsReport;
231
-                        })
232
-                        .catch(error => this.errorCallback(error));
233 214
                 }
234 215
             },
235 216
             this.audioLevelsIntervalMilis
@@ -679,41 +660,3 @@ StatsCollector.prototype.processStatsReport = function() {
679 660
 
680 661
     this._processAndEmitReport();
681 662
 };
682
-
683
-/**
684
- * Stats processing logic.
685
- */
686
-StatsCollector.prototype.processAudioLevelReport = function() {
687
-    if (!this.baselineAudioLevelsReport) {
688
-        return;
689
-    }
690
-
691
-    this.currentAudioLevelsReport.forEach(now => {
692
-        if (now.type !== 'track') {
693
-            return;
694
-        }
695
-
696
-        // Audio level
697
-        const audioLevel = now.audioLevel;
698
-
699
-        if (!audioLevel) {
700
-            return;
701
-        }
702
-
703
-        const trackIdentifier = now.trackIdentifier;
704
-        const ssrc = this.peerconnection.getSsrcByTrackId(trackIdentifier);
705
-
706
-        if (ssrc) {
707
-            const isLocal
708
-                = ssrc === this.peerconnection.getLocalSSRC(
709
-                this.peerconnection.getLocalTracks(MediaType.AUDIO));
710
-
711
-            this.eventEmitter.emit(
712
-                StatisticsEvents.AUDIO_LEVEL,
713
-                this.peerconnection,
714
-                ssrc,
715
-                audioLevel,
716
-                isLocal);
717
-        }
718
-    });
719
-};

+ 0
- 1
types/hand-crafted/modules/statistics/RTPStatsCollector.d.ts View File

@@ -7,7 +7,6 @@ export default class StatsCollector {
7 7
   start: ( startAudioLevelStats: unknown ) => void;
8 8
   getNonNegativeStat: ( report: unknown, name: string ) => number;
9 9
   processStatsReport: () => void;
10
-  processAudioLevelReport: () => void;
11 10
   getNonNegativeValue: ( v: unknown ) => number; // TODO:
12 11
   setSpeakerList: ( speakerList: Array<string> ) => void;
13 12
 }

Loading…
Cancel
Save