Просмотр исходного кода

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 лет назад
Родитель
Сommit
99feab14c0

+ 1
- 5
modules/browser/BrowserCapabilities.js Просмотреть файл

200
      */
200
      */
201
     supportsReceiverStats() {
201
     supportsReceiverStats() {
202
         return typeof window.RTCRtpReceiver !== 'undefined'
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 Просмотреть файл

2
 
2
 
3
 import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
3
 import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
4
 import * as JitsiTrackEvents from '../../JitsiTrackEvents';
4
 import * as JitsiTrackEvents from '../../JitsiTrackEvents';
5
-import browser from '../browser';
6
 
5
 
7
 import * as DetectionEvents from './DetectionEvents';
6
 import * as DetectionEvents from './DetectionEvents';
8
 
7
 
32
         this._timeoutTrigger = null;
31
         this._timeoutTrigger = null;
33
         this._hasAudioInput = null;
32
         this._hasAudioInput = null;
34
 
33
 
35
-        if (!browser.supportsReceiverStats()) {
36
-            conference.statistics.addAudioLevelListener(this._audioLevel.bind(this));
37
-        }
38
         conference.on(JitsiConferenceEvents.TRACK_ADDED, this._trackAdded.bind(this));
34
         conference.on(JitsiConferenceEvents.TRACK_ADDED, this._trackAdded.bind(this));
39
     }
35
     }
40
 
36
 
132
             this._clearTriggerTimeout();
128
             this._clearTriggerTimeout();
133
 
129
 
134
             // Listen for the audio levels on the newly added audio track
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 Просмотреть файл

134
  */
134
  */
135
 export default function StatsCollector(peerconnection, audioLevelsInterval, statsInterval, eventEmitter) {
135
 export default function StatsCollector(peerconnection, audioLevelsInterval, statsInterval, eventEmitter) {
136
     this.peerconnection = peerconnection;
136
     this.peerconnection = peerconnection;
137
-    this.baselineAudioLevelsReport = null;
138
-    this.currentAudioLevelsReport = null;
139
     this.currentStatsReport = null;
137
     this.currentStatsReport = null;
140
     this.previousStatsReport = null;
138
     this.previousStatsReport = null;
141
     this.audioLevelReportHistory = {};
139
     this.audioLevelReportHistory = {};
196
  * Starts stats updates.
194
  * Starts stats updates.
197
  */
195
  */
198
 StatsCollector.prototype.start = function(startAudioLevelStats) {
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
         this.audioLevelsIntervalId = setInterval(
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
             this.audioLevelsIntervalMilis
216
             this.audioLevelsIntervalMilis
679
 
660
 
680
     this._processAndEmitReport();
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 Просмотреть файл

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

Загрузка…
Отмена
Сохранить