瀏覽代碼

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,6 +38,7 @@ export default class JitsiRemoteTrack extends JitsiTrack {
38 38
      * @param {boolean} muted the initial muted state
39 39
      * @param {boolean} isP2P indicates whether or not this track belongs to a
40 40
      * P2P session
41
+     * @param {String} sourceName the source name signaled for the track
41 42
      * @throws {TypeError} if <tt>ssrc</tt> is not a number.
42 43
      * @constructor
43 44
      */
@@ -51,7 +52,8 @@ export default class JitsiRemoteTrack extends JitsiTrack {
51 52
             videoType,
52 53
             ssrc,
53 54
             muted,
54
-            isP2P) {
55
+            isP2P,
56
+            sourceName) {
55 57
         super(
56 58
             conference,
57 59
             stream,
@@ -71,6 +73,7 @@ export default class JitsiRemoteTrack extends JitsiTrack {
71 73
         this.ownerEndpointId = ownerEndpointId;
72 74
         this.muted = muted;
73 75
         this.isP2P = isP2P;
76
+        this._sourceName = sourceName;
74 77
 
75 78
         logger.debug(`New remote track added: ${this}`);
76 79
 
@@ -187,6 +190,16 @@ export default class JitsiRemoteTrack extends JitsiTrack {
187 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 204
      * Changes the video type of the track.
192 205
      *
@@ -311,6 +324,6 @@ export default class JitsiRemoteTrack extends JitsiTrack {
311 324
      */
312 325
     toString() {
313 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,9 +7,11 @@ import MediaDirection from '../../service/RTC/MediaDirection';
7 7
 import * as MediaType from '../../service/RTC/MediaType';
8 8
 import RTCEvents from '../../service/RTC/RTCEvents';
9 9
 import * as SignalingEvents from '../../service/RTC/SignalingEvents';
10
+import { getSourceNameForJitsiTrack } from '../../service/RTC/SignalingLayer';
10 11
 import * as VideoType from '../../service/RTC/VideoType';
11 12
 import { SS_DEFAULT_FRAME_RATE } from '../RTC/ScreenObtainer';
12 13
 import browser from '../browser';
14
+import FeatureFlags from '../flags/FeatureFlags';
13 15
 import LocalSdpMunger from '../sdp/LocalSdpMunger';
14 16
 import RtxModifier from '../sdp/RtxModifier';
15 17
 import SDP from '../sdp/SDP';
@@ -896,7 +898,22 @@ TraceablePeerConnection.prototype._remoteTrackAdded = function(stream, track, tr
896 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 918
     const peerMediaInfo
902 919
         = this.signalingLayer.getPeerMediaInfo(ownerEndpointId, mediaType);
@@ -911,8 +928,9 @@ TraceablePeerConnection.prototype._remoteTrackAdded = function(stream, track, tr
911 928
     const muted = peerMediaInfo.muted;
912 929
     const videoType = peerMediaInfo.videoType; // can be undefined
913 930
 
931
+    // eslint-disable-next-line no-undef
914 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 936
 // FIXME cleanup params
@@ -929,6 +947,7 @@ TraceablePeerConnection.prototype._remoteTrackAdded = function(stream, track, tr
929 947
  * @param {VideoType} [videoType] the track's type of the video (if applicable)
930 948
  * @param {number} ssrc the track's main SSRC number
931 949
  * @param {boolean} muted the initial muted status
950
+ * @param {String} sourceName the track's source name
932 951
  */
933 952
 TraceablePeerConnection.prototype._createRemoteTrack = function(
934 953
         ownerEndpointId,
@@ -937,7 +956,8 @@ TraceablePeerConnection.prototype._createRemoteTrack = function(
937 956
         mediaType,
938 957
         videoType,
939 958
         ssrc,
940
-        muted) {
959
+        muted,
960
+        sourceName) {
941 961
     let remoteTracksMap = this.remoteTracks.get(ownerEndpointId);
942 962
 
943 963
     if (!remoteTracksMap) {
@@ -977,7 +997,8 @@ TraceablePeerConnection.prototype._createRemoteTrack = function(
977 997
                 videoType,
978 998
                 ssrc,
979 999
                 muted,
980
-                this.isP2P);
1000
+                this.isP2P,
1001
+                sourceName);
981 1002
 
982 1003
     remoteTracksMap.set(mediaType, remoteTrack);
983 1004
 

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

@@ -11,6 +11,7 @@ import {
11 11
 } from '../../service/statistics/AnalyticsEvents';
12 12
 import XMPPEvents from '../../service/xmpp/XMPPEvents';
13 13
 import { SS_DEFAULT_FRAME_RATE } from '../RTC/ScreenObtainer';
14
+import FeatureFlags from '../flags/FeatureFlags';
14 15
 import SDP from '../sdp/SDP';
15 16
 import SDPDiffer from '../sdp/SDPDiffer';
16 17
 import SDPUtil from '../sdp/SDPUtil';
@@ -879,6 +880,14 @@ export default class JingleSessionPC extends JingleSession {
879 880
                 this._signalingLayer.setSSRCOwner(
880 881
                     ssrc, Strophe.getResourceFromJid(this.remoteJid));
881 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 891
                 $(ssrcElement)
883 892
                     .find('>ssrc-info[xmlns="http://jitsi.org/jitmeet"]')
884 893
                     .each((i3, ssrcInfoElement) => {

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

@@ -52,6 +52,16 @@ export default class SignalingLayerImpl extends SignalingLayer {
52 52
          * @private
53 53
          */
54 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,6 +244,14 @@ export default class SignalingLayerImpl extends SignalingLayer {
234 244
             const endpointId = Strophe.getResourceFromJid(jid);
235 245
 
236 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 257
         room.addEventListener(XMPPEvents.MUC_MEMBER_LEFT, this._memberLeftHandler);
@@ -393,4 +411,34 @@ export default class SignalingLayerImpl extends SignalingLayer {
393 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,4 +106,13 @@ export default class SignalingLayer extends Listenable {
106 106
     getPeerSourceInfo(owner, sourceName) { // eslint-disable-line no-unused-vars
107 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
 }

Loading…
取消
儲存