Pārlūkot izejas kodu

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 gadus atpakaļ
vecāks
revīzija
66080c6845
Revīzijas autora e-pasta adrese nav piesaistīta nevienam kontam

+ 20
- 0
JitsiConference.js Parādīt failu

1103
         }
1103
         }
1104
 
1104
 
1105
         if (FeatureFlags.isMultiStreamSupportEnabled() && mediaType === MediaType.VIDEO) {
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
             const addTrackPromises = [];
1112
             const addTrackPromises = [];
1107
 
1113
 
1108
             this.p2pJingleSession && addTrackPromises.push(this.p2pJingleSession.addTracks([ track ]));
1114
             this.p2pJingleSession && addTrackPromises.push(this.p2pJingleSession.addTracks([ track ]));
1263
  */
1269
  */
1264
 JitsiConference.prototype.replaceTrack = function(oldTrack, newTrack) {
1270
 JitsiConference.prototype.replaceTrack = function(oldTrack, newTrack) {
1265
     const oldVideoType = oldTrack?.getVideoType();
1271
     const oldVideoType = oldTrack?.getVideoType();
1272
+    const mediaType = oldTrack?.getType() || newTrack?.getType();
1266
     const newVideoType = newTrack?.getVideoType();
1273
     const newVideoType = newTrack?.getVideoType();
1267
 
1274
 
1268
     if (FeatureFlags.isMultiStreamSupportEnabled() && oldTrack && newTrack && oldVideoType !== newVideoType) {
1275
     if (FeatureFlags.isMultiStreamSupportEnabled() && oldTrack && newTrack && oldVideoType !== newVideoType) {
1269
         throw new Error(`Replacing a track of videoType=${oldVideoType} with a track of videoType=${newVideoType} is`
1276
         throw new Error(`Replacing a track of videoType=${oldVideoType} with a track of videoType=${newVideoType} is`
1270
             + ' not supported in this mode.');
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
     const oldTrackBelongsToConference = this === oldTrack?.conference;
1292
     const oldTrackBelongsToConference = this === oldTrack?.conference;
1273
 
1293
 
1274
     if (oldTrackBelongsToConference && oldTrack.disposed) {
1294
     if (oldTrackBelongsToConference && oldTrack.disposed) {

+ 32
- 10
modules/RTC/TraceablePeerConnection.js Parādīt failu

1157
  */
1157
  */
1158
 TraceablePeerConnection.prototype._extractSSRCMap = function(desc) {
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
      * @type {Map<string,TrackSSRCInfo>}
1161
      * @type {Map<string,TrackSSRCInfo>}
1162
      */
1162
      */
1163
     const ssrcMap = new Map();
1163
     const ssrcMap = new Map();
1186
     // For unified plan clients, only the first audio and video mlines will have ssrcs for the local sources.
1186
     // For unified plan clients, only the first audio and video mlines will have ssrcs for the local sources.
1187
     // The rest of the m-lines are for the recv-only sources, one for each remote source.
1187
     // The rest of the m-lines are for the recv-only sources, one for each remote source.
1188
     if (this._usesUnifiedPlan) {
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
     for (const mLine of media) {
1205
     for (const mLine of media) {
1198
         if (!Array.isArray(mLine.ssrcs)) {
1206
         if (!Array.isArray(mLine.ssrcs)) {
1199
             continue; // eslint-disable-line no-continue
1207
             continue; // eslint-disable-line no-continue
1201
 
1209
 
1202
         if (Array.isArray(mLine.ssrcGroups)) {
1210
         if (Array.isArray(mLine.ssrcGroups)) {
1203
             for (const group of mLine.ssrcGroups) {
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
                     // Parse SSRCs and store as numbers
1213
                     // Parse SSRCs and store as numbers
1207
                     const groupSSRCs = group.ssrcs.split(' ').map(ssrcStr => parseInt(ssrcStr, 10));
1214
                     const groupSSRCs = group.ssrcs.split(' ').map(ssrcStr => parseInt(ssrcStr, 10));
1208
                     const primarySSRC = groupSSRCs[0];
1215
                     const primarySSRC = groupSSRCs[0];
1231
             // the standard and the unified plan SDPs do not have a proper msid attribute for the sources.
1238
             // the standard and the unified plan SDPs do not have a proper msid attribute for the sources.
1232
             // Also the ssrcs for sources do not change for Unified plan clients since RTCRtpSender#replaceTrack is
1239
             // Also the ssrcs for sources do not change for Unified plan clients since RTCRtpSender#replaceTrack is
1233
             // used for switching the tracks so it is safe to use the mediaType as the key for the TrackSSRCInfo map.
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
             const ssrcNumber = ssrc.id;
1244
             const ssrcNumber = ssrc.id;
1236
             let ssrcInfo = ssrcMap.get(key);
1245
             let ssrcInfo = ssrcMap.get(key);
1237
 
1246
 
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
     return ssrcMap;
1270
     return ssrcMap;
2922
  */
2934
  */
2923
 TraceablePeerConnection.prototype._processLocalSSRCsMap = function(ssrcMap) {
2935
 TraceablePeerConnection.prototype._processLocalSSRCsMap = function(ssrcMap) {
2924
     for (const track of this.localTracks.values()) {
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
         if (ssrcMap.has(sourceIdentifier)) {
2949
         if (ssrcMap.has(sourceIdentifier)) {
2928
             const newSSRC = ssrcMap.get(sourceIdentifier);
2950
             const newSSRC = ssrcMap.get(sourceIdentifier);

+ 1
- 1
modules/statistics/RTPStatsCollector.js Parādīt failu

653
                 return;
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
             if (!ssrc) {
658
             if (!ssrc) {
659
                 return;
659
                 return;

Notiek ielāde…
Atcelt
Saglabāt