浏览代码

Adds dominant speaker detection on p2p sessions.

Dominant speaker detection which is just based on current audio level of local or remote p2p track. The threshold value is the same used for talk while muted detection.
master
damencho 8 年前
父节点
当前提交
5f15b09627
共有 3 个文件被更改,包括 74 次插入6 次删除
  1. 4
    0
      JitsiConference.js
  2. 56
    0
      modules/P2PDominantSpeakerDetection.js
  3. 14
    6
      modules/TalkMutedDetection.js

+ 4
- 0
JitsiConference.js 查看文件

@@ -18,6 +18,7 @@ import * as JitsiTrackEvents from './JitsiTrackEvents';
18 18
 import * as MediaType from './service/RTC/MediaType';
19 19
 import ParticipantConnectionStatusHandler
20 20
     from './modules/connectivity/ParticipantConnectionStatus';
21
+import P2PDominantSpeakerDetection from './modules/P2PDominantSpeakerDetection';
21 22
 import RTC from './modules/RTC/RTC';
22 23
 import RTCBrowserType from './modules/RTC/RTCBrowserType';
23 24
 import * as RTCEvents from './service/RTC/RTCEvents';
@@ -264,6 +265,9 @@ JitsiConference.prototype._init = function(options = {}) {
264 265
     if ('channelLastN' in options.config) {
265 266
         this.setLastN(options.config.channelLastN);
266 267
     }
268
+
269
+    // creates dominant speaker detection that works only in p2p mode
270
+    this.p2pDominantSpeakerDetection = new P2PDominantSpeakerDetection(this);
267 271
 };
268 272
 
269 273
 /**

+ 56
- 0
modules/P2PDominantSpeakerDetection.js 查看文件

@@ -0,0 +1,56 @@
1
+import * as JitsiConferenceEvents from '../JitsiConferenceEvents';
2
+
3
+/**
4
+ * The value which we use to say, every sound over this threshold
5
+ * is talking on the mic.
6
+ * @type {number}
7
+ */
8
+const SPEECH_DETECT_THRESHOLD = 0.6;
9
+
10
+/**
11
+ * The <tt>P2PDominantSpeakerDetection</tt> is activated only when p2p is
12
+ * currently used.
13
+ * Listens for changes in the audio level changes of the local p2p audio track
14
+ * or remote p2p one and fires dominant speaker events to be able to use
15
+ * features depending on those events (speaker stats), to make them work without
16
+ * the video bridge.
17
+ */
18
+export default class P2PDominantSpeakerDetection {
19
+    /**
20
+     * Creates P2PDominantSpeakerDetection
21
+     * @param conference the JitsiConference instance that created us.
22
+     * @constructor
23
+     */
24
+    constructor(conference) {
25
+        this.conference = conference;
26
+
27
+        conference.addEventListener(
28
+            JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
29
+            this._audioLevel.bind(this));
30
+
31
+        this.myUserID = this.conference.myUserId();
32
+    }
33
+
34
+    /**
35
+     * Receives audio level events for all streams in the conference.
36
+     *
37
+     * @param {String} id - The participant id
38
+     * @param {number} audioLevel - The audio level.
39
+     */
40
+    _audioLevel(id, audioLevel) {
41
+
42
+        // we do not process if p2p is not active
43
+        // or audio level is under certain threshold
44
+        // or if the audio level is for local audio track which is muted
45
+        if (!this.conference.isP2PActive()
46
+            || audioLevel <= SPEECH_DETECT_THRESHOLD
47
+            || (id === this.myUserID
48
+                    && this.conference.getLocalAudioTrack().isMuted())) {
49
+            return;
50
+        }
51
+
52
+        this.conference.eventEmitter.emit(
53
+            JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED,
54
+            id);
55
+    }
56
+}

+ 14
- 6
modules/TalkMutedDetection.js 查看文件

@@ -1,7 +1,14 @@
1 1
 import * as JitsiConferenceEvents from '../JitsiConferenceEvents';
2 2
 
3 3
 /**
4
- *
4
+ * The value which we use to say, every sound over this threshold
5
+ * is talking on the mic.
6
+ * @type {number}
7
+ */
8
+const SPEECH_DETECT_THRESHOLD = 0.6;
9
+
10
+/**
11
+ * Detect user trying to speek while is locally muted and fires an event.
5 12
  */
6 13
 export default class TalkMutedDetection {
7 14
     /**
@@ -54,21 +61,22 @@ export default class TalkMutedDetection {
54 61
     /**
55 62
      * Receives audio level events for all send and receive streams.
56 63
      *
57
-     * @param pc - WebRTC PeerConnection object of the
58
-     * @param ssrc - The synchronization source identifier (SSRC) of the
59
-     * endpoint/participant/stream being reported.
64
+     * @param {TraceablePeerConnection} pc - WebRTC PeerConnection object of the
65
+     * @param {number} ssrc - The synchronization source identifier (SSRC) of
66
+     * the endpoint/participant/stream being reported.
60 67
      * @param {number} audioLevel - The audio level of <tt>ssrc</tt>.
61 68
      * @param {boolean} isLocal - <tt>true</tt> if <tt>ssrc</tt> represents a
62 69
      * local/send stream or <tt>false</tt> for a remote/receive stream.
63 70
      */
64
-    _audioLevel(pc, ssrc, audioLevel, isLocal) {
71
+    _audioLevel(tpc, ssrc, audioLevel, isLocal) {
65 72
         // We are interested in the local audio stream only and if event is not
66 73
         // sent yet.
67 74
         if (!isLocal || !this.audioTrack || this._eventFired) {
68 75
             return;
69 76
         }
70 77
 
71
-        if (this.audioTrack.isMuted() && audioLevel > 0.6) {
78
+        if (this.audioTrack.isMuted()
79
+            && audioLevel > SPEECH_DETECT_THRESHOLD) {
72 80
             this._eventFired = true;
73 81
             this._callback();
74 82
         }

正在加载...
取消
保存