Parcourir la source

setNoSrcDataNotificationUid

master
Andrei Gavrilescu il y a 6 ans
Parent
révision
7828bf8d46

+ 0
- 2
react/features/base/devices/services/index.js Voir le fichier

@@ -1,2 +0,0 @@
1
-export * from './vad-reporter/Events';
2
-export * from './vad-reporter/VADReportingService';

+ 0
- 10
react/features/base/devices/services/vad-reporter/Events.js Voir le fichier

@@ -1,10 +0,0 @@
1
-/**
2
- * Event generated by VADReportingService when if finishes creating a VAD report for the monitored devices.
3
- * The generated objects are of type Array<Object>, one score for each monitored device.
4
- * @event VAD_REPORT_PUBLISHED
5
- * @type Array<Object> with the following structure:
6
- * @property {Date} timestamp - Timestamp at which the compute took place.
7
- * @property {number} avgVAD - Average VAD score over monitored period of time.
8
- * @property {string} deviceId - Associate local audio device ID.
9
- */
10
-export const VAD_REPORT_PUBLISHED = 'vad-report-published';

+ 0
- 284
react/features/base/devices/services/vad-reporter/VADReportingService.js Voir le fichier

@@ -1,284 +0,0 @@
1
-// @flow
2
-
3
-import { createRnnoiseProcessorPromise } from '../../../../rnnoise';
4
-import EventEmitter from 'events';
5
-import logger from '../../logger';
6
-import JitsiMeetJS, { JitsiDetectionEvents } from '../../../lib-jitsi-meet';
7
-import { VAD_REPORT_PUBLISHED } from './Events';
8
-
9
-/**
10
- * Sample rate used by TrackVADEmitter, this value determines how often the ScriptProcessorNode is going to call the
11
- * process audio function and with what sample size.
12
- * Basically lower values mean more callbacks with lower processing times bigger values less callbacks with longer
13
- * processing times. This value is somewhere in the middle, so we strike a balance between flooding with callbacks
14
- * and processing time. Possible values  256, 512, 1024, 2048, 4096, 8192, 16384. Passing other values will default
15
- * to closes neighbor.
16
- */
17
-const SCRIPT_NODE_SAMPLE_RATE = 4096;
18
-
19
-/**
20
- * Context that contains the emitter and additional information about the device.
21
- */
22
-type VADDeviceContext = {
23
-
24
-    /**
25
-     * MediaDeviceInfo for associated context
26
-     */
27
-    deviceInfo: MediaDeviceInfo,
28
-
29
-    /**
30
-     * Array with VAD scores publish from the emitter.
31
-     */
32
-    scoreArray: Array<Object>,
33
-
34
-    /**
35
-     * TrackVADEmitter associated with media device
36
-     */
37
-    vadEmitter: Object
38
-};
39
-
40
-/**
41
- * Voice activity detection reporting service. The service create TrackVADEmitters for the provided devices and
42
- * publishes an average of their VAD score over the specified interval via EventEmitter.
43
- * The service is not reusable if destroyed a new one needs to be created, i.e. when a new device is added to the system
44
- * a new service needs to be created and the old discarded.
45
- */
46
-export default class VADReportingService extends EventEmitter {
47
-    /**
48
-     * Map containing context for devices currently being monitored by the reporting service.
49
-     */
50
-    _contextMap: Map<string, VADDeviceContext>;
51
-
52
-    /**
53
-     * State flag, check if the instance was destroyed.
54
-     */
55
-    _destroyed: boolean = false;
56
-
57
-    /**
58
-     * Delay at which to publish VAD score for monitored devices.
59
-     */
60
-    _intervalDelay: number;
61
-
62
-    /**
63
-     * Identifier for the interval publishing stats on the set interval.
64
-     */
65
-    _intervalId: ?IntervalID;
66
-
67
-    /**
68
-     * Constructor.
69
-     *
70
-     * @param {number} intervalDelay - Delay at which to publish VAD score for monitored devices.
71
-     * @param {Function} publishScoreCallBack - Function called on the specific interval with the calculated VAD score.
72
-     */
73
-    constructor(intervalDelay: number) {
74
-        super();
75
-        this._contextMap = new Map();
76
-        this._intervalDelay = intervalDelay;
77
-
78
-        logger.log(`Constructed VADReportingService with publish interval of: ${intervalDelay}`);
79
-    }
80
-
81
-    /**
82
-     * Factory methods that creates the TrackVADEmitters for the associated array of devices and instantiates
83
-     * a VADReportingService.
84
-     *
85
-     * @param {Array<MediaDeviceInfo>} micDeviceList - Device list that is monitored inside the service.
86
-     * @param {number} intervalDelay - Delay at which to publish VAD score for monitored devices.
87
-     * @param {Function} publishScoreCallBack - Function called on the specific interval with the calculated VAD score.
88
-     *
89
-     * @returns {Promise<VADReportingService>}
90
-     */
91
-    static async create(micDeviceList: Array<MediaDeviceInfo>, intervalDelay: number) {
92
-        const vadReportingService = new VADReportingService(intervalDelay);
93
-        const emitterPromiseArray = [];
94
-
95
-        // Create a TrackVADEmitter for each provided audioinput device.
96
-        for (const micDevice of micDeviceList) {
97
-            if (micDevice.kind !== 'audioinput') {
98
-                logger.warn(`Provided device ${micDevice.label} -> ${micDevice.deviceId}, is not audioinput ignoring!`);
99
-
100
-                return;
101
-            }
102
-
103
-            logger.log(`Initializing VAD context for mic: ${micDevice.label} -> ${micDevice.deviceId}`);
104
-
105
-            const rnnoiseProcessor = await createRnnoiseProcessorPromise();
106
-
107
-            const emitterPromise = JitsiMeetJS.createTrackVADEmitter(
108
-                micDevice.deviceId,
109
-                SCRIPT_NODE_SAMPLE_RATE,
110
-                rnnoiseProcessor
111
-            ).then(emitter => {
112
-                emitter.on(
113
-                    JitsiDetectionEvents.VAD_SCORE_PUBLISHED,
114
-                    vadReportingService._devicePublishVADScore.bind(vadReportingService)
115
-                );
116
-
117
-                return {
118
-                    vadEmitter: emitter,
119
-                    deviceInfo: micDevice,
120
-                    scoreArray: []
121
-                };
122
-            });
123
-
124
-            emitterPromiseArray.push(emitterPromise);
125
-        }
126
-
127
-        // Once all the TrackVADEmitter promises are resolved check if all of them resolved properly if not reject
128
-        // the promise and clear the already created emitters.
129
-        // $FlowFixMe - allSettled is not part of flow prototype even though it's a valid Promise function
130
-        return Promise.allSettled(emitterPromiseArray).then(outcomeArray => {
131
-            const vadContextArray = [];
132
-            const rejectedEmitterPromiseArray = [];
133
-
134
-            for (const outcome of outcomeArray) {
135
-                if (outcome.status === 'fulfilled') {
136
-                    vadContextArray.push(outcome.value);
137
-                } else {
138
-                    // Promise was rejected.
139
-                    logger.error(`Create TrackVADEmitter promise failed with ${outcome.reason}`);
140
-
141
-                    rejectedEmitterPromiseArray.push(outcome);
142
-                }
143
-            }
144
-
145
-            // Check if there were any rejected promises and clear the already created ones list.
146
-            if (rejectedEmitterPromiseArray.length > 0) {
147
-                logger.error('Cleaning up remaining VADDeviceContext, due to create fail!');
148
-
149
-                for (const context of vadContextArray) {
150
-                    context.vadEmitter.destroy();
151
-                }
152
-
153
-                // Reject create promise if one emitter failed to instantiate, we might one just ignore it,
154
-                // leaving it like this for now
155
-                throw new Error('Create VADReportingService failed due to TrackVADEmitter creation issues!');
156
-            }
157
-
158
-            vadReportingService._setVADContextArray(vadContextArray);
159
-            vadReportingService._startPublish();
160
-
161
-            return vadReportingService;
162
-        });
163
-    }
164
-
165
-    /**
166
-     * Destroy TrackVADEmitters and clear the context map.
167
-     *
168
-     * @returns {void}
169
-     */
170
-    _clearContextMap() {
171
-        for (const vadContext of this._contextMap.values()) {
172
-            vadContext.vadEmitter.destroy();
173
-        }
174
-        this._contextMap.clear();
175
-    }
176
-
177
-    /**
178
-     * Set the watched device contexts.
179
-     *
180
-     * @param {Array<VADDeviceContext>} vadContextArray - List of mics.
181
-     * @returns {void}
182
-     */
183
-    _setVADContextArray(vadContextArray: Array<VADDeviceContext>): void {
184
-        for (const vadContext of vadContextArray) {
185
-            this._contextMap.set(vadContext.deviceInfo.deviceId, vadContext);
186
-        }
187
-    }
188
-
189
-    /**
190
-     * Start the setInterval reporting process.
191
-     *
192
-     * @returns {void}.
193
-     */
194
-    _startPublish() {
195
-        logger.log('VADReportingService started publishing.');
196
-        this._intervalId = setInterval(() => {
197
-            this._reportVadScore();
198
-        }, this._intervalDelay);
199
-    }
200
-
201
-    /**
202
-     * Function called at set interval with selected compute. The result will be published on the set callback.
203
-     *
204
-     * @returns {void}
205
-     * @fires VAD_REPORT_PUBLISHED
206
-     */
207
-    _reportVadScore() {
208
-        const vadComputeScoreArray = [];
209
-        const computeTimestamp = Date.now();
210
-
211
-        // Go through each device and compute cumulated VAD score.
212
-
213
-        for (const [ deviceId, vadContext ] of this._contextMap) {
214
-            const nrOfVADScores = vadContext.scoreArray.length;
215
-            let vadSum = 0;
216
-
217
-            vadContext.scoreArray.forEach(vadScore => {
218
-                vadSum += vadScore.score;
219
-            });
220
-
221
-            // TODO For now we just calculate the average score for each device, more compute algorithms will be added.
222
-            const avgVAD = vadSum / nrOfVADScores;
223
-
224
-            vadContext.scoreArray = [];
225
-
226
-            vadComputeScoreArray.push({
227
-                timestamp: computeTimestamp,
228
-                score: avgVAD,
229
-                deviceId
230
-            });
231
-        }
232
-
233
-        /**
234
-         * Once the computation for all the tracked devices is done, fire an event containing all the necessary
235
-         * information.
236
-         *
237
-         * @event VAD_REPORT_PUBLISHED
238
-         * @type Array<Object> with the following structure:
239
-         * @property {Date} timestamp - Timestamo at which the compute took place.
240
-         * @property {number} avgVAD - Average VAD score over monitored period of time.
241
-         * @property {string} deviceId - Associate local audio device ID.
242
-         */
243
-        this.emit(VAD_REPORT_PUBLISHED, vadComputeScoreArray);
244
-    }
245
-
246
-    /**
247
-     * Callback method passed to vad emitters in order to publish their score.
248
-     *
249
-     * @param {Object} vadScore -VAD score emitted by.
250
-     * @param {Date}   vadScore.timestamp - Exact time at which processed PCM sample was generated.
251
-     * @param {number} vadScore.score - VAD score on a scale from 0 to 1 (i.e. 0.7).
252
-     * @param {string} vadScore.deviceId - Device id of the associated track.
253
-     * @returns {void}
254
-     * @listens VAD_SCORE_PUBLISHED
255
-     */
256
-    _devicePublishVADScore(vadScore: Object) {
257
-        const context = this._contextMap.get(vadScore.deviceId);
258
-
259
-        if (context) {
260
-            context.scoreArray.push(vadScore);
261
-        }
262
-    }
263
-
264
-    /**
265
-     * Destroy the VADReportingService, stops the setInterval reporting, destroys the emitters and clears the map.
266
-     * After this call the instance is no longer usable.
267
-     *
268
-     * @returns {void}.
269
-     */
270
-    destroy() {
271
-        if (this._destroyed) {
272
-            return;
273
-        }
274
-
275
-        logger.log('Destroying VADReportingService.');
276
-
277
-        if (this._intervalId) {
278
-            clearInterval(this._intervalId);
279
-            this._intervalId = null;
280
-        }
281
-        this._clearContextMap();
282
-        this._destroyed = true;
283
-    }
284
-}

+ 2
- 2
react/features/base/tracks/actionTypes.js Voir le fichier

@@ -3,11 +3,11 @@
3 3
  * no data from source notification. Used to check if such a notification was previously displayed.
4 4
  *
5 5
  * {
6
- *     type: SET_NO_SRC_DATA_NOTI_UID,
6
+ *     type: SET_NO_SRC_DATA_NOTIFICATION_UID,
7 7
  *     uid: ?number
8 8
  * }
9 9
  */
10
-export const SET_NO_SRC_DATA_NOTI_UID = 'SET_NO_SRC_DATA_NOTI_UID';
10
+export const SET_NO_SRC_DATA_NOTIFICATION_UID = 'SET_NO_SRC_DATA_NOTIFICATION_UID';
11 11
 
12 12
 /**
13 13
  * The type of redux action dispatched to disable screensharing or to start the

+ 2
- 2
react/features/base/tracks/reducer.js Voir le fichier

@@ -2,7 +2,7 @@ import { PARTICIPANT_ID_CHANGED } from '../participants';
2 2
 import { ReducerRegistry, set } from '../redux';
3 3
 
4 4
 import {
5
-    SET_NO_SRC_DATA_NOTI_UID,
5
+    SET_NO_SRC_DATA_NOTIFICATION_UID,
6 6
     TRACK_ADDED,
7 7
     TRACK_CREATE_CANCELED,
8 8
     TRACK_CREATE_ERROR,
@@ -140,7 +140,7 @@ ReducerRegistry.register('features/base/tracks', (state = [], action) => {
140 140
  */
141 141
 ReducerRegistry.register('features/base/no-src-data', (state = {}, action) => {
142 142
     switch (action.type) {
143
-    case SET_NO_SRC_DATA_NOTI_UID:
143
+    case SET_NO_SRC_DATA_NOTIFICATION_UID:
144 144
         return set(state, 'noSrcDataNotificationUid', action.uid);
145 145
 
146 146
     default:

+ 4
- 3
react/features/no-audio-signal/middleware.js Voir le fichier

@@ -1,5 +1,7 @@
1 1
 // @flow
2 2
 import { setNoAudioSignalNotificationUid } from './actions';
3
+import { NO_AUDIO_SIGNAL_SOUND_ID } from './constants';
4
+import { NO_AUDIO_SIGNAL_SOUND_FILE } from './sounds';
3 5
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
4 6
 import { CONFERENCE_JOINED } from '../base/conference';
5 7
 import {
@@ -10,9 +12,7 @@ import JitsiMeetJS, { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
10 12
 import { MiddlewareRegistry } from '../base/redux';
11 13
 import { updateSettings } from '../base/settings';
12 14
 import { playSound, registerSound, unregisterSound } from '../base/sounds';
13
-import { NO_AUDIO_SIGNAL_SOUND_ID } from './constants';
14 15
 import { hideNotification, showNotification } from '../notifications';
15
-import { NO_AUDIO_SIGNAL_SOUND_FILE } from './sounds';
16 16
 
17 17
 MiddlewareRegistry.register(store => next => async action => {
18 18
     const result = next(action);
@@ -34,6 +34,7 @@ MiddlewareRegistry.register(store => next => async action => {
34 34
 
35 35
             confAudioInputState = hasAudioInput;
36 36
 
37
+            // In case the notification is displayed but the conference detected audio input signal we hide it.
37 38
             if (noAudioSignalNotificationUid && hasAudioInput) {
38 39
                 dispatch(hideNotification(noAudioSignalNotificationUid));
39 40
                 dispatch(setNoAudioSignalNotificationUid());
@@ -50,7 +51,7 @@ MiddlewareRegistry.register(store => next => async action => {
50 51
             }
51 52
 
52 53
             // Force the flag to false in case AUDIO_INPUT_STATE_CHANGE is received after the notification is displayed,
53
-            // thus making sure we check properly if the notification should display.
54
+            // possibly preventing the notification from displaying because of an outdated state.
54 55
             confAudioInputState = false;
55 56
 
56 57
 

Chargement…
Annuler
Enregistrer