ソースを参照

refactor the codec selection logic

dev1
Jaya Allamsetty 4年前
コミット
1009693f2e
1個のファイルの変更24行の追加76行の削除
  1. 24
    76
      modules/RTC/CodecSelection.js

+ 24
- 76
modules/RTC/CodecSelection.js ファイルの表示

@@ -53,16 +53,12 @@ export class CodecSelection {
53 53
             this.jvbPreferredCodec = CodecMimeType.VP8;
54 54
         }
55 55
 
56
-        // Keep a list of participants that join the call with a non-preferred codec.
57
-        // The call is upgraded to the preferred codec once that list is empty.
58
-        this.nonPreferredParticipants = [];
59
-
60 56
         this.conference.on(
61 57
             JitsiConferenceEvents.USER_JOINED,
62
-            this._onParticipantJoined.bind(this));
58
+            () => this._selectPreferredCodec());
63 59
         this.conference.on(
64 60
             JitsiConferenceEvents.USER_LEFT,
65
-            this._onParticipantLeft.bind(this));
61
+            () => this._selectPreferredCodec());
66 62
         this.conference.on(
67 63
             JitsiConferenceEvents._MEDIA_SESSION_STARTED,
68 64
             session => this._onMediaSessionStared(session));
@@ -115,93 +111,45 @@ export class CodecSelection {
115 111
         const disabledCodec = this.disabledCodec && this._isCodecSupported(this.disabledCodec)
116 112
             ? this.disabledCodec
117 113
             : null;
118
-        let codec = preferredCodec;
119
-
120
-        // For a new endpoint joining the call, JitsiConferenceEvents.USER_JOINED event is received before the
121
-        // media session is created, the supported codecs for all the remote endpoints in the call need to be
122
-        // compared here before setting the codec on the peerconnection.
123
-        if (!mediaSession.isP2P) {
124
-            const remoteParticipants = this.conference.getParticipants().map(participant => participant.getId());
125
-
126
-            for (const remote of remoteParticipants) {
127
-                const peerMediaInfo = mediaSession.signalingLayer.getPeerMediaInfo(remote, MediaType.VIDEO);
128 114
 
129
-                if (peerMediaInfo && peerMediaInfo.codecType && peerMediaInfo.codecType !== preferredCodec) {
130
-                    this.nonPreferredParticipants.push(remote);
131
-                    codec = peerMediaInfo.codecType;
132
-                }
133
-            }
134
-        }
135
-
136
-        mediaSession.setVideoCodecs(codec, disabledCodec);
115
+        this._selectPreferredCodec(mediaSession, preferredCodec, disabledCodec);
137 116
     }
138 117
 
139 118
     /**
140
-     * Handles the {@link JitsiConferenceEvents.USER_JOINED} event. When a new user joins the call,
141
-     * the codec types are compared and the codec configued on the peerconnection is updated when
142
-     * needed.
119
+     * Sets the codec on the media session based on the preferred codec setting and the supported codecs
120
+     * published by the remote participants in their presence.
143 121
      *
144
-     * @param {string} id endpoint id of the newly joined user.
145
-     * @returns {void}
146
-     * @private
122
+     * @param {JingleSessionPC} mediaSession session for which the codec selection has to be made.
123
+     * @param {CodecMimeType} preferredCodec preferred codec.
124
+     * @param {CodecMimeType} disabledCodec codec that needs to be disabled.
147 125
      */
148
-    _onParticipantJoined(id) {
149
-        const session = this.conference.jvbJingleSession;
150
-
151
-        if (session && !this.options.enforcePreferredCodec) {
152
-            const peerMediaInfo = session.signalingLayer.getPeerMediaInfo(id, MediaType.VIDEO);
153
-
154
-            if (!peerMediaInfo) {
155
-                return;
156
-            }
157
-            const newCodec = peerMediaInfo.codecType;
158
-            const currentCodec = session.getConfiguredVideoCodec();
159
-
160
-            if (newCodec
161
-                && newCodec !== this.jvbPreferredCodec
162
-                && newCodec !== currentCodec
163
-                && this._isCodecSupported(newCodec)) {
126
+    _selectPreferredCodec(mediaSession = null, preferredCodec = null, disabledCodec = null) {
127
+        const session = mediaSession ? mediaSession : this.conference.jvbJingleSession;
128
+        const codec = preferredCodec ? preferredCodec : this.jvbPreferredCodec;
129
+        let selectedCodec = codec;
164 130
 
165
-                // Add the participant to the list of participants that don't support the preferred codec.
166
-                this.nonPreferredParticipants.push(id);
167
-                session.setVideoCodecs(newCodec);
168
-            }
169
-        }
170
-    }
171
-
172
-    /**
173
-     * Handles the {@link JitsiConferenceEvents.USER_LEFT} event. When a user leaves the call,
174
-     * the codec configured on the peerconnection is updated to the preferred codec if all the
175
-     * users that do not support the preferred codec have left the call.
176
-     *
177
-     * @param {string} id endpoint id of the user that has left the call.
178
-     * @returns {void}
179
-     * @private
180
-     */
181
-    _onParticipantLeft(id) {
182
-        const session = this.conference.jvbJingleSession;
183
-
184
-        if (session && !this.options.enforcePreferredCodec) {
185
-            const index = this.nonPreferredParticipants.findIndex(participantId => participantId === id);
131
+        if (session && !session.isP2P && !this.options.enforcePreferredCodec) {
132
+            const remoteParticipants = this.conference.getParticipants().map(participant => participant.getId());
186 133
 
187
-            if (index > -1) {
188
-                this.nonPreferredParticipants.splice(index, 1);
189
-            }
134
+            for (const remote of remoteParticipants) {
135
+                const peerMediaInfo = session.signalingLayer.getPeerMediaInfo(remote, MediaType.VIDEO);
190 136
 
191
-            // If all the participants that have joined the conference with a
192
-            // non-preferred codec have left, switch to the preferred codec.
193
-            if (!this.nonPreferredParticipants.length) {
194
-                session.setVideoCodecs(this.jvbPreferredCodec);
137
+                if (peerMediaInfo && peerMediaInfo.codecType && peerMediaInfo.codecType !== codec) {
138
+                    selectedCodec = peerMediaInfo.codecType;
139
+                }
195 140
             }
196 141
         }
142
+        session && session.setVideoCodecs(selectedCodec, disabledCodec);
197 143
     }
198 144
 
199 145
     /**
200
-     * Returns the preferred codec for the conference.
146
+     * Returns the preferred codec for the conference. The preferred codec for the JVB media session
147
+     * is the one that gets published in presence and a comparision is made whenever a participant joins
148
+     * or leaves the call.
201 149
      *
202 150
      * @returns {CodecMimeType} preferred codec.
203 151
      */
204 152
     getPreferredCodec() {
205
-        return this.conference.isP2PActive() ? this.p2pPreferredCodec : this.jvbPreferredCodec;
153
+        return this.jvbPreferredCodec;
206 154
     }
207 155
 }

読み込み中…
キャンセル
保存