浏览代码

Save track source name to JitsiRemoteTrack

* Save track source name to JitsiRemoteTrack

* add feature flag checks. code review adjustments.

* eslint cleanup1

* eslint cleanup2

* fix: move sourceName declaration outside of if block.

Co-authored-by: Dennis Dowhy <ddowhy@gmail.com>
Co-authored-by: William Liang <wliang67@bloomberg.net>
dev1
dennisbb2 3 年前
父节点
当前提交
02b69057b2
没有帐户链接到提交者的电子邮件

+ 15
- 2
modules/RTC/JitsiRemoteTrack.js 查看文件

38
      * @param {boolean} muted the initial muted state
38
      * @param {boolean} muted the initial muted state
39
      * @param {boolean} isP2P indicates whether or not this track belongs to a
39
      * @param {boolean} isP2P indicates whether or not this track belongs to a
40
      * P2P session
40
      * P2P session
41
+     * @param {String} sourceName the source name signaled for the track
41
      * @throws {TypeError} if <tt>ssrc</tt> is not a number.
42
      * @throws {TypeError} if <tt>ssrc</tt> is not a number.
42
      * @constructor
43
      * @constructor
43
      */
44
      */
51
             videoType,
52
             videoType,
52
             ssrc,
53
             ssrc,
53
             muted,
54
             muted,
54
-            isP2P) {
55
+            isP2P,
56
+            sourceName) {
55
         super(
57
         super(
56
             conference,
58
             conference,
57
             stream,
59
             stream,
71
         this.ownerEndpointId = ownerEndpointId;
73
         this.ownerEndpointId = ownerEndpointId;
72
         this.muted = muted;
74
         this.muted = muted;
73
         this.isP2P = isP2P;
75
         this.isP2P = isP2P;
76
+        this._sourceName = sourceName;
74
 
77
 
75
         logger.debug(`New remote track added: ${this}`);
78
         logger.debug(`New remote track added: ${this}`);
76
 
79
 
187
         return this.ssrc;
190
         return this.ssrc;
188
     }
191
     }
189
 
192
 
193
+
194
+    /**
195
+     * Returns the tracks source name
196
+     *
197
+     * @returns {string} the track's source name
198
+     */
199
+    getSourceName() {
200
+        return this._sourceName;
201
+    }
202
+
190
     /**
203
     /**
191
      * Changes the video type of the track.
204
      * Changes the video type of the track.
192
      *
205
      *
311
      */
324
      */
312
     toString() {
325
     toString() {
313
         return `RemoteTrack[userID: ${this.getParticipantId()}, type: ${this.getType()}, ssrc: ${
326
         return `RemoteTrack[userID: ${this.getParticipantId()}, type: ${this.getType()}, ssrc: ${
314
-            this.getSSRC()}, p2p: ${this.isP2P}, status: ${this._getStatus()}]`;
327
+            this.getSSRC()}, p2p: ${this.isP2P}, sourceName: ${this._sourceName}, status: ${this._getStatus()}]`;
315
     }
328
     }
316
 }
329
 }

+ 25
- 4
modules/RTC/TraceablePeerConnection.js 查看文件

7
 import * as MediaType from '../../service/RTC/MediaType';
7
 import * as MediaType from '../../service/RTC/MediaType';
8
 import RTCEvents from '../../service/RTC/RTCEvents';
8
 import RTCEvents from '../../service/RTC/RTCEvents';
9
 import * as SignalingEvents from '../../service/RTC/SignalingEvents';
9
 import * as SignalingEvents from '../../service/RTC/SignalingEvents';
10
+import { getSourceNameForJitsiTrack } from '../../service/RTC/SignalingLayer';
10
 import * as VideoType from '../../service/RTC/VideoType';
11
 import * as VideoType from '../../service/RTC/VideoType';
11
 import { SS_DEFAULT_FRAME_RATE } from '../RTC/ScreenObtainer';
12
 import { SS_DEFAULT_FRAME_RATE } from '../RTC/ScreenObtainer';
12
 import browser from '../browser';
13
 import browser from '../browser';
14
+import FeatureFlags from '../flags/FeatureFlags';
13
 import LocalSdpMunger from '../sdp/LocalSdpMunger';
15
 import LocalSdpMunger from '../sdp/LocalSdpMunger';
14
 import RtxModifier from '../sdp/RtxModifier';
16
 import RtxModifier from '../sdp/RtxModifier';
15
 import SDP from '../sdp/SDP';
17
 import SDP from '../sdp/SDP';
896
         return;
898
         return;
897
     }
899
     }
898
 
900
 
899
-    logger.info(`${this} creating remote track[endpoint=${ownerEndpointId},ssrc=${trackSsrc},type=${mediaType}]`);
901
+
902
+    let sourceName;
903
+
904
+    if (FeatureFlags.isSourceNameSignalingEnabled()) {
905
+        sourceName = this.signalingLayer.getTrackSourceName(trackSsrc);
906
+
907
+        // If source name was not signaled, we'll generate one which allows testing signaling
908
+        // when mixing legacy(mobile) with new clients.
909
+        if (!sourceName) {
910
+            sourceName = getSourceNameForJitsiTrack(ownerEndpointId, mediaType, 0);
911
+        }
912
+    }
913
+
914
+    // eslint-disable-next-line no-undef
915
+    logger.info(`${this} creating remote track[endpoint=${ownerEndpointId},ssrc=${trackSsrc},`
916
+        + `type=${mediaType},sourceName=${sourceName}]`);
900
 
917
 
901
     const peerMediaInfo
918
     const peerMediaInfo
902
         = this.signalingLayer.getPeerMediaInfo(ownerEndpointId, mediaType);
919
         = this.signalingLayer.getPeerMediaInfo(ownerEndpointId, mediaType);
911
     const muted = peerMediaInfo.muted;
928
     const muted = peerMediaInfo.muted;
912
     const videoType = peerMediaInfo.videoType; // can be undefined
929
     const videoType = peerMediaInfo.videoType; // can be undefined
913
 
930
 
931
+    // eslint-disable-next-line no-undef
914
     this._createRemoteTrack(
932
     this._createRemoteTrack(
915
-        ownerEndpointId, stream, track, mediaType, videoType, trackSsrc, muted);
933
+        ownerEndpointId, stream, track, mediaType, videoType, trackSsrc, muted, sourceName);
916
 };
934
 };
917
 
935
 
918
 // FIXME cleanup params
936
 // FIXME cleanup params
929
  * @param {VideoType} [videoType] the track's type of the video (if applicable)
947
  * @param {VideoType} [videoType] the track's type of the video (if applicable)
930
  * @param {number} ssrc the track's main SSRC number
948
  * @param {number} ssrc the track's main SSRC number
931
  * @param {boolean} muted the initial muted status
949
  * @param {boolean} muted the initial muted status
950
+ * @param {String} sourceName the track's source name
932
  */
951
  */
933
 TraceablePeerConnection.prototype._createRemoteTrack = function(
952
 TraceablePeerConnection.prototype._createRemoteTrack = function(
934
         ownerEndpointId,
953
         ownerEndpointId,
937
         mediaType,
956
         mediaType,
938
         videoType,
957
         videoType,
939
         ssrc,
958
         ssrc,
940
-        muted) {
959
+        muted,
960
+        sourceName) {
941
     let remoteTracksMap = this.remoteTracks.get(ownerEndpointId);
961
     let remoteTracksMap = this.remoteTracks.get(ownerEndpointId);
942
 
962
 
943
     if (!remoteTracksMap) {
963
     if (!remoteTracksMap) {
977
                 videoType,
997
                 videoType,
978
                 ssrc,
998
                 ssrc,
979
                 muted,
999
                 muted,
980
-                this.isP2P);
1000
+                this.isP2P,
1001
+                sourceName);
981
 
1002
 
982
     remoteTracksMap.set(mediaType, remoteTrack);
1003
     remoteTracksMap.set(mediaType, remoteTrack);
983
 
1004
 

+ 9
- 0
modules/xmpp/JingleSessionPC.js 查看文件

11
 } from '../../service/statistics/AnalyticsEvents';
11
 } from '../../service/statistics/AnalyticsEvents';
12
 import XMPPEvents from '../../service/xmpp/XMPPEvents';
12
 import XMPPEvents from '../../service/xmpp/XMPPEvents';
13
 import { SS_DEFAULT_FRAME_RATE } from '../RTC/ScreenObtainer';
13
 import { SS_DEFAULT_FRAME_RATE } from '../RTC/ScreenObtainer';
14
+import FeatureFlags from '../flags/FeatureFlags';
14
 import SDP from '../sdp/SDP';
15
 import SDP from '../sdp/SDP';
15
 import SDPDiffer from '../sdp/SDPDiffer';
16
 import SDPDiffer from '../sdp/SDPDiffer';
16
 import SDPUtil from '../sdp/SDPUtil';
17
 import SDPUtil from '../sdp/SDPUtil';
879
                 this._signalingLayer.setSSRCOwner(
880
                 this._signalingLayer.setSSRCOwner(
880
                     ssrc, Strophe.getResourceFromJid(this.remoteJid));
881
                     ssrc, Strophe.getResourceFromJid(this.remoteJid));
881
             } else {
882
             } else {
883
+                if (FeatureFlags.isSourceNameSignalingEnabled()) {
884
+                    // Only set sourceName for non-P2P case
885
+                    if (ssrcElement.hasAttribute('name')) {
886
+                        const sourceName = ssrcElement.getAttribute('name');
887
+
888
+                        this._signalingLayer.setTrackSourceName(ssrc, sourceName);
889
+                    }
890
+                }
882
                 $(ssrcElement)
891
                 $(ssrcElement)
883
                     .find('>ssrc-info[xmlns="http://jitsi.org/jitmeet"]')
892
                     .find('>ssrc-info[xmlns="http://jitsi.org/jitmeet"]')
884
                     .each((i3, ssrcInfoElement) => {
893
                     .each((i3, ssrcInfoElement) => {

+ 48
- 0
modules/xmpp/SignalingLayerImpl.js 查看文件

52
          * @private
52
          * @private
53
          */
53
          */
54
         this._remoteSourceState = { };
54
         this._remoteSourceState = { };
55
+
56
+        /**
57
+         * A map that stores the source name of a track identified by it's ssrc.
58
+         * We store the mapping when jingle is received, and later is used
59
+         * onaddstream webrtc event where we have only the ssrc
60
+         * FIXME: This map got filled and never cleaned and can grow during long
61
+         * conference
62
+         * @type {Map<number, string>} maps SSRC number to source name
63
+         */
64
+        this._sourceNames = new Map();
55
     }
65
     }
56
 
66
 
57
     /**
67
     /**
234
             const endpointId = Strophe.getResourceFromJid(jid);
244
             const endpointId = Strophe.getResourceFromJid(jid);
235
 
245
 
236
             delete this._remoteSourceState[endpointId];
246
             delete this._remoteSourceState[endpointId];
247
+
248
+            if (FeatureFlags.isSourceNameSignalingEnabled()) {
249
+                for (const [ key, value ] of this.ssrcOwners.entries()) {
250
+                    if (value === endpointId) {
251
+                        delete this._sourceNames[key];
252
+                    }
253
+                }
254
+            }
237
         };
255
         };
238
 
256
 
239
         room.addEventListener(XMPPEvents.MUC_MEMBER_LEFT, this._memberLeftHandler);
257
         room.addEventListener(XMPPEvents.MUC_MEMBER_LEFT, this._memberLeftHandler);
393
             this._addLocalSourceInfoToPresence();
411
             this._addLocalSourceInfoToPresence();
394
         }
412
         }
395
     }
413
     }
414
+
415
+    /**
416
+     * @inheritDoc
417
+     */
418
+    getTrackSourceName(ssrc) {
419
+        return this._sourceNames.get(ssrc);
420
+    }
421
+
422
+    /**
423
+     * Saves the source name for a track identified by it's ssrc.
424
+     * @param {number} ssrc the ssrc of the target track.
425
+     * @param {SourceName} sourceName the track's source name to save.
426
+     * @throws TypeError if <tt>ssrc</tt> is not a number
427
+     */
428
+    setTrackSourceName(ssrc, sourceName) {
429
+        if (typeof ssrc !== 'number') {
430
+            throw new TypeError(`SSRC(${ssrc}) must be a number`);
431
+        }
432
+
433
+        // Now signaling layer instance is shared between different JingleSessionPC instances, so although very unlikely
434
+        // an SSRC conflict could potentially occur. Log a message to make debugging easier.
435
+        const existingName = this._sourceNames.get(ssrc);
436
+
437
+        if (existingName && existingName !== sourceName) {
438
+            logger.error(`SSRC(${ssrc}) sourceName re-assigned from ${existingName} to ${sourceName}`);
439
+        }
440
+
441
+        this._sourceNames.set(ssrc, sourceName);
442
+    }
443
+
396
 }
444
 }

+ 9
- 0
service/RTC/SignalingLayer.js 查看文件

106
     getPeerSourceInfo(owner, sourceName) { // eslint-disable-line no-unused-vars
106
     getPeerSourceInfo(owner, sourceName) { // eslint-disable-line no-unused-vars
107
         throw new Error('not implemented');
107
         throw new Error('not implemented');
108
     }
108
     }
109
+
110
+    /**
111
+     * Obtains the source name for given SSRC.
112
+     * @param {number} ssrc the track's SSRC identifier.
113
+     * @returns {SourceName | undefined} the track's source name.
114
+     */
115
+    getTrackSourceName(ssrc) { // eslint-disable-line no-unused-vars
116
+        throw new Error('not implemented');
117
+    }
109
 }
118
 }

正在加载...
取消
保存