Преглед на файлове

fix(multi-stream): Fix local SSRC cache to include multiple video streams. (#2006)

* fix(multi-stream): Fix local SSRC cache to include multiple video streams.
If multiple local video streams are found in the SDP, cache all of them instead of the first video SSRC. This fixes an issue where the resolution/fps stats for the screenshare track are not available.

* squash: new track inherits the source name of old track if it exists.
dev1
Jaya Allamsetty преди 3 години
родител
ревизия
66080c6845
No account linked to committer's email address
променени са 3 файла, в които са добавени 53 реда и са изтрити 11 реда
  1. 20
    0
      JitsiConference.js
  2. 32
    10
      modules/RTC/TraceablePeerConnection.js
  3. 1
    1
      modules/statistics/RTPStatsCollector.js

+ 20
- 0
JitsiConference.js Целия файл

@@ -1103,6 +1103,12 @@ JitsiConference.prototype.addTrack = function(track) {
1103 1103
         }
1104 1104
 
1105 1105
         if (FeatureFlags.isMultiStreamSupportEnabled() && mediaType === MediaType.VIDEO) {
1106
+            const sourceName = getSourceNameForJitsiTrack(
1107
+                this.myUserId(),
1108
+                mediaType,
1109
+                this.getLocalTracks(mediaType)?.length);
1110
+
1111
+            track.setSourceName(sourceName);
1106 1112
             const addTrackPromises = [];
1107 1113
 
1108 1114
             this.p2pJingleSession && addTrackPromises.push(this.p2pJingleSession.addTracks([ track ]));
@@ -1263,12 +1269,26 @@ JitsiConference.prototype.removeTrack = function(track) {
1263 1269
  */
1264 1270
 JitsiConference.prototype.replaceTrack = function(oldTrack, newTrack) {
1265 1271
     const oldVideoType = oldTrack?.getVideoType();
1272
+    const mediaType = oldTrack?.getType() || newTrack?.getType();
1266 1273
     const newVideoType = newTrack?.getVideoType();
1267 1274
 
1268 1275
     if (FeatureFlags.isMultiStreamSupportEnabled() && oldTrack && newTrack && oldVideoType !== newVideoType) {
1269 1276
         throw new Error(`Replacing a track of videoType=${oldVideoType} with a track of videoType=${newVideoType} is`
1270 1277
             + ' not supported in this mode.');
1271 1278
     }
1279
+
1280
+    if (FeatureFlags.isSourceNameSignalingEnabled() && newTrack) {
1281
+        if (oldTrack) {
1282
+            newTrack.setSourceName(oldTrack.getSourceName());
1283
+        } else {
1284
+            const sourceName = getSourceNameForJitsiTrack(
1285
+                this.myUserId(),
1286
+                mediaType,
1287
+                this.getLocalTracks(mediaType)?.length);
1288
+
1289
+            newTrack.setSourceName(sourceName);
1290
+        }
1291
+    }
1272 1292
     const oldTrackBelongsToConference = this === oldTrack?.conference;
1273 1293
 
1274 1294
     if (oldTrackBelongsToConference && oldTrack.disposed) {

+ 32
- 10
modules/RTC/TraceablePeerConnection.js Целия файл

@@ -1157,7 +1157,7 @@ TraceablePeerConnection.prototype._removeRemoteTrack = function(toBeRemoved) {
1157 1157
  */
1158 1158
 TraceablePeerConnection.prototype._extractSSRCMap = function(desc) {
1159 1159
     /**
1160
-     * Track SSRC infos mapped by stream ID (msid) or mediaType (unfied-plan)
1160
+     * Track SSRC infos mapped by stream ID (msid) or mediaType (unified-plan)
1161 1161
      * @type {Map<string,TrackSSRCInfo>}
1162 1162
      */
1163 1163
     const ssrcMap = new Map();
@@ -1186,14 +1186,22 @@ TraceablePeerConnection.prototype._extractSSRCMap = function(desc) {
1186 1186
     // For unified plan clients, only the first audio and video mlines will have ssrcs for the local sources.
1187 1187
     // The rest of the m-lines are for the recv-only sources, one for each remote source.
1188 1188
     if (this._usesUnifiedPlan) {
1189
-        media = [];
1190
-        [ MediaType.AUDIO, MediaType.VIDEO ].forEach(mediaType => {
1191
-            const mLine = session.media.find(m => m.type === mediaType);
1189
+        if (FeatureFlags.isMultiStreamSupportEnabled()) {
1190
+            media = media.filter(mline => mline.direction === MediaDirection.SENDONLY
1191
+                || mline.direction === MediaDirection.SENDRECV);
1192
+            logger.warn(`local m-lines is ${media.length}`);
1193
+        } else {
1194
+            media = [];
1195
+            [ MediaType.AUDIO, MediaType.VIDEO ].forEach(mediaType => {
1196
+                const mLine = session.media.find(m => m.type === mediaType);
1192 1197
 
1193
-            mLine && media.push(mLine);
1194
-        });
1198
+                mLine && media.push(mLine);
1199
+            });
1200
+        }
1195 1201
     }
1196 1202
 
1203
+    let index = 0;
1204
+
1197 1205
     for (const mLine of media) {
1198 1206
         if (!Array.isArray(mLine.ssrcs)) {
1199 1207
             continue; // eslint-disable-line no-continue
@@ -1201,8 +1209,7 @@ TraceablePeerConnection.prototype._extractSSRCMap = function(desc) {
1201 1209
 
1202 1210
         if (Array.isArray(mLine.ssrcGroups)) {
1203 1211
             for (const group of mLine.ssrcGroups) {
1204
-                if (typeof group.semantics !== 'undefined'
1205
-                    && typeof group.ssrcs !== 'undefined') {
1212
+                if (typeof group.semantics !== 'undefined' && typeof group.ssrcs !== 'undefined') {
1206 1213
                     // Parse SSRCs and store as numbers
1207 1214
                     const groupSSRCs = group.ssrcs.split(' ').map(ssrcStr => parseInt(ssrcStr, 10));
1208 1215
                     const primarySSRC = groupSSRCs[0];
@@ -1231,7 +1238,9 @@ TraceablePeerConnection.prototype._extractSSRCMap = function(desc) {
1231 1238
             // the standard and the unified plan SDPs do not have a proper msid attribute for the sources.
1232 1239
             // Also the ssrcs for sources do not change for Unified plan clients since RTCRtpSender#replaceTrack is
1233 1240
             // used for switching the tracks so it is safe to use the mediaType as the key for the TrackSSRCInfo map.
1234
-            const key = this._usesUnifiedPlan ? mLine.type : ssrc.value;
1241
+            const key = this._usesUnifiedPlan
1242
+                ? FeatureFlags.isMultiStreamSupportEnabled() ? `${mLine.type}-${index}` : mLine.type
1243
+                : ssrc.value;
1235 1244
             const ssrcNumber = ssrc.id;
1236 1245
             let ssrcInfo = ssrcMap.get(key);
1237 1246
 
@@ -1253,6 +1262,9 @@ TraceablePeerConnection.prototype._extractSSRCMap = function(desc) {
1253 1262
                 }
1254 1263
             }
1255 1264
         }
1265
+
1266
+        // Currently multi-stream is supported for video only.
1267
+        mLine.type === MediaType.VIDEO && index++;
1256 1268
     }
1257 1269
 
1258 1270
     return ssrcMap;
@@ -2922,7 +2934,17 @@ TraceablePeerConnection.prototype._extractPrimarySSRC = function(ssrcObj) {
2922 2934
  */
2923 2935
 TraceablePeerConnection.prototype._processLocalSSRCsMap = function(ssrcMap) {
2924 2936
     for (const track of this.localTracks.values()) {
2925
-        const sourceIdentifier = this._usesUnifiedPlan ? track.getType() : track.storedMSID;
2937
+        let sourceIndex, sourceName;
2938
+
2939
+        if (FeatureFlags.isMultiStreamSupportEnabled()) {
2940
+            sourceName = track.getSourceName();
2941
+            sourceIndex = sourceName?.indexOf('-') + 2;
2942
+        }
2943
+
2944
+        const sourceIdentifier = this._usesUnifiedPlan
2945
+            ? FeatureFlags.isMultiStreamSupportEnabled() && sourceIndex
2946
+                ? `${track.getType()}-${sourceName.substr(sourceIndex, 1)}` : track.getType()
2947
+            : track.storedMSID;
2926 2948
 
2927 2949
         if (ssrcMap.has(sourceIdentifier)) {
2928 2950
             const newSSRC = ssrcMap.get(sourceIdentifier);

+ 1
- 1
modules/statistics/RTPStatsCollector.js Целия файл

@@ -653,7 +653,7 @@ StatsCollector.prototype.processStatsReport = function() {
653 653
                 return;
654 654
             }
655 655
 
656
-            const ssrc = this.peerconnection.getLocalSSRC(localVideoTracks[0]);
656
+            const ssrc = this.peerconnection.getSsrcByTrackId(now.trackIdentifier);
657 657
 
658 658
             if (!ssrc) {
659 659
                 return;

Loading…
Отказ
Запис