Browse Source

ref(Sdp) Modify SDPTransformUtil.selectMedia() to return all m-lines for a given media type.

dev1
Jaya Allamsetty 3 years ago
parent
commit
135eed57af

+ 5
- 5
modules/RTC/TraceablePeerConnection.js View File

1346
     }
1346
     }
1347
 
1347
 
1348
     const transformer = new SdpTransformWrap(localDescription.sdp);
1348
     const transformer = new SdpTransformWrap(localDescription.sdp);
1349
-    const audioMedia = transformer.selectMedia(MediaType.AUDIO);
1349
+    const audioMedia = transformer.selectMedia(MediaType.AUDIO)?.[0];
1350
     let changed = false;
1350
     let changed = false;
1351
 
1351
 
1352
     if (audioMedia && audioMedia.direction !== MediaDirection.SENDRECV) {
1352
     if (audioMedia && audioMedia.direction !== MediaDirection.SENDRECV) {
1359
         changed = true;
1359
         changed = true;
1360
     }
1360
     }
1361
 
1361
 
1362
-    const videoMedia = transformer.selectMedia(MediaType.VIDEO);
1362
+    const videoMedia = transformer.selectMedia(MediaType.VIDEO)?.[0];
1363
 
1363
 
1364
     if (videoMedia && videoMedia.direction !== MediaDirection.SENDRECV) {
1364
     if (videoMedia && videoMedia.direction !== MediaDirection.SENDRECV) {
1365
         videoMedia.direction = MediaDirection.SENDRECV;
1365
         videoMedia.direction = MediaDirection.SENDRECV;
2079
 TraceablePeerConnection.prototype._adjustLocalMediaDirection = function(localDescription) {
2079
 TraceablePeerConnection.prototype._adjustLocalMediaDirection = function(localDescription) {
2080
     const transformer = new SdpTransformWrap(localDescription.sdp);
2080
     const transformer = new SdpTransformWrap(localDescription.sdp);
2081
     let modifiedDirection = false;
2081
     let modifiedDirection = false;
2082
-    const audioMedia = transformer.selectMedia(MediaType.AUDIO);
2082
+    const audioMedia = transformer.selectMedia(MediaType.AUDIO)?.[0];
2083
 
2083
 
2084
     if (audioMedia) {
2084
     if (audioMedia) {
2085
         const desiredAudioDirection = this.getDesiredMediaDirection(MediaType.AUDIO);
2085
         const desiredAudioDirection = this.getDesiredMediaDirection(MediaType.AUDIO);
2093
         logger.warn(`${this} No "audio" media found in the local description`);
2093
         logger.warn(`${this} No "audio" media found in the local description`);
2094
     }
2094
     }
2095
 
2095
 
2096
-    const videoMedia = transformer.selectMedia(MediaType.VIDEO);
2096
+    const videoMedia = transformer.selectMedia(MediaType.VIDEO)?.[0];
2097
 
2097
 
2098
     if (videoMedia) {
2098
     if (videoMedia) {
2099
         const desiredVideoDirection = this.getDesiredMediaDirection(MediaType.VIDEO);
2099
         const desiredVideoDirection = this.getDesiredMediaDirection(MediaType.VIDEO);
2129
     const transformer = new SdpTransformWrap(remoteDescription.sdp);
2129
     const transformer = new SdpTransformWrap(remoteDescription.sdp);
2130
 
2130
 
2131
     [ MediaType.AUDIO, MediaType.VIDEO ].forEach(mediaType => {
2131
     [ MediaType.AUDIO, MediaType.VIDEO ].forEach(mediaType => {
2132
-        const media = transformer.selectMedia(mediaType);
2132
+        const media = transformer.selectMedia(mediaType)?.[0];
2133
         const hasLocalSource = this.hasAnyTracksOfType(mediaType);
2133
         const hasLocalSource = this.hasAnyTracksOfType(mediaType);
2134
         const hasRemoteSource = this.getRemoteTracks(null, mediaType).length > 0;
2134
         const hasRemoteSource = this.getRemoteTracks(null, mediaType).length > 0;
2135
 
2135
 

+ 3
- 3
modules/sdp/LocalSdpMunger.js View File

58
                     + 'Strange things may happen !', localVideos);
58
                     + 'Strange things may happen !', localVideos);
59
         }
59
         }
60
 
60
 
61
-        const videoMLine = transformer.selectMedia('video');
61
+        const videoMLine = transformer.selectMedia(MediaType.VIDEO)?.[0];
62
 
62
 
63
         if (!videoMLine) {
63
         if (!videoMLine) {
64
             logger.debug(
64
             logger.debug(
305
         }
305
         }
306
 
306
 
307
         const transformer = new SdpTransformWrap(sessionDesc.sdp);
307
         const transformer = new SdpTransformWrap(sessionDesc.sdp);
308
-        const audioMLine = transformer.selectMedia('audio');
308
+        const audioMLine = transformer.selectMedia(MediaType.AUDIO)?.[0];
309
 
309
 
310
         if (audioMLine) {
310
         if (audioMLine) {
311
             this._transformMediaIdentifiers(audioMLine);
311
             this._transformMediaIdentifiers(audioMLine);
312
             this._injectSourceNames(audioMLine);
312
             this._injectSourceNames(audioMLine);
313
         }
313
         }
314
 
314
 
315
-        const videoMLine = transformer.selectMedia('video');
315
+        const videoMLine = transformer.selectMedia(MediaType.VIDEO)?.[0];
316
 
316
 
317
         if (videoMLine) {
317
         if (videoMLine) {
318
             this._transformMediaIdentifiers(videoMLine);
318
             this._transformMediaIdentifiers(videoMLine);

+ 4
- 2
modules/sdp/RtxModifier.js View File

1
 import { getLogger } from '@jitsi/logger';
1
 import { getLogger } from '@jitsi/logger';
2
 
2
 
3
+import * as MediaType from '../../service/RTC/MediaType';
4
+
3
 import SDPUtil from './SDPUtil';
5
 import SDPUtil from './SDPUtil';
4
 import { parseSecondarySSRC, SdpTransformWrap } from './SdpTransformUtil';
6
 import { parseSecondarySSRC, SdpTransformWrap } from './SdpTransformUtil';
5
 
7
 
99
      */
101
      */
100
     modifyRtxSsrcs(sdpStr) {
102
     modifyRtxSsrcs(sdpStr) {
101
         const sdpTransformer = new SdpTransformWrap(sdpStr);
103
         const sdpTransformer = new SdpTransformWrap(sdpStr);
102
-        const videoMLine = sdpTransformer.selectMedia('video');
104
+        const videoMLine = sdpTransformer.selectMedia(MediaType.VIDEO)?.[0];
103
 
105
 
104
         if (!videoMLine) {
106
         if (!videoMLine) {
105
             logger.debug(`No 'video' media found in the sdp: ${sdpStr}`);
107
             logger.debug(`No 'video' media found in the sdp: ${sdpStr}`);
168
      */
170
      */
169
     stripRtx(sdpStr) {
171
     stripRtx(sdpStr) {
170
         const sdpTransformer = new SdpTransformWrap(sdpStr);
172
         const sdpTransformer = new SdpTransformWrap(sdpStr);
171
-        const videoMLine = sdpTransformer.selectMedia('video');
173
+        const videoMLine = sdpTransformer.selectMedia(MediaType.VIDEO)?.[0];
172
 
174
 
173
         if (!videoMLine) {
175
         if (!videoMLine) {
174
             logger.debug(`No 'video' media found in the sdp: ${sdpStr}`);
176
             logger.debug(`No 'video' media found in the sdp: ${sdpStr}`);

+ 3
- 1
modules/sdp/SdpConsistency.js View File

1
 import { getLogger } from '@jitsi/logger';
1
 import { getLogger } from '@jitsi/logger';
2
 
2
 
3
+import * as MediaType from '../../service/RTC/MediaType';
4
+
3
 import {
5
 import {
4
     parsePrimarySSRC,
6
     parsePrimarySSRC,
5
     parseSecondarySSRC,
7
     parseSecondarySSRC,
72
      */
74
      */
73
     makeVideoPrimarySsrcsConsistent(sdpStr) {
75
     makeVideoPrimarySsrcsConsistent(sdpStr) {
74
         const sdpTransformer = new SdpTransformWrap(sdpStr);
76
         const sdpTransformer = new SdpTransformWrap(sdpStr);
75
-        const videoMLine = sdpTransformer.selectMedia('video');
77
+        const videoMLine = sdpTransformer.selectMedia(MediaType.VIDEO)?.[0];
76
 
78
 
77
         if (!videoMLine) {
79
         if (!videoMLine) {
78
             logger.debug(`${this.logPrefix} no 'video' media found in the sdp: ${sdpStr}`);
80
             logger.debug(`${this.logPrefix} no 'video' media found in the sdp: ${sdpStr}`);

+ 10
- 10
modules/sdp/SdpTransformUtil.js View File

408
     }
408
     }
409
 
409
 
410
     /**
410
     /**
411
-     * Selects the first media SDP of given name.
412
-     * @param {string} mediaType the name of the media e.g. 'audio', 'video',
413
-     * 'data'.
414
-     * @return {MLineWrap|null} return {@link MLineWrap} instance for the media
415
-     * line or <tt>null</tt> if not found. The object returned references
416
-     * the underlying SDP state held by this <tt>SdpTransformWrap</tt> instance
417
-     * (it's not a copy).
411
+     * Selects all the m-lines from the SDP for a given media type.
412
+     *
413
+     * @param {string} mediaType the name of the media e.g. 'audio', 'video', 'data'.
414
+     * @return {MLineWrap|null} return {@link MLineWrap} instance for the media line or <tt>null</tt> if not found. The
415
+     * object returned references the underlying SDP state held by this <tt>SdpTransformWrap</tt> instance (it's not a
416
+     * copy).
418
      */
417
      */
419
     selectMedia(mediaType) {
418
     selectMedia(mediaType) {
420
-        const selectedMLine
421
-            = this.parsedSDP.media.find(mLine => mLine.type === mediaType);
419
+        const selectedMLines = this.parsedSDP.media
420
+            .filter(mLine => mLine.type === mediaType)
421
+            .map(mLine => new MLineWrap(mLine));
422
 
422
 
423
-        return selectedMLine ? new MLineWrap(selectedMLine) : null;
423
+        return selectedMLines ?? null;
424
     }
424
     }
425
 
425
 
426
     /**
426
     /**

+ 1
- 1
types/auto/modules/sdp/SdpConsistency.d.ts View File

20
      *  makeVideoPrimarySsrcsConsistent
20
      *  makeVideoPrimarySsrcsConsistent
21
      */
21
      */
22
     clearVideoSsrcCache(): void;
22
     clearVideoSsrcCache(): void;
23
-    cachedPrimarySsrc: number;
23
+    cachedPrimarySsrc: any;
24
     injectRecvOnly: boolean;
24
     injectRecvOnly: boolean;
25
     /**
25
     /**
26
      * Explicitly set the primary ssrc to be used in
26
      * Explicitly set the primary ssrc to be used in

+ 6
- 7
types/auto/modules/sdp/SdpTransformUtil.d.ts View File

35
     constructor(rawSDP: string);
35
     constructor(rawSDP: string);
36
     parsedSDP: any;
36
     parsedSDP: any;
37
     /**
37
     /**
38
-     * Selects the first media SDP of given name.
39
-     * @param {string} mediaType the name of the media e.g. 'audio', 'video',
40
-     * 'data'.
41
-     * @return {MLineWrap|null} return {@link MLineWrap} instance for the media
42
-     * line or <tt>null</tt> if not found. The object returned references
43
-     * the underlying SDP state held by this <tt>SdpTransformWrap</tt> instance
44
-     * (it's not a copy).
38
+     * Selects all the m-lines from the SDP for a given media type.
39
+     *
40
+     * @param {string} mediaType the name of the media e.g. 'audio', 'video', 'data'.
41
+     * @return {MLineWrap|null} return {@link MLineWrap} instance for the media line or <tt>null</tt> if not found. The
42
+     * object returned references the underlying SDP state held by this <tt>SdpTransformWrap</tt> instance (it's not a
43
+     * copy).
45
      */
44
      */
46
     selectMedia(mediaType: string): MLineWrap | null;
45
     selectMedia(mediaType: string): MLineWrap | null;
47
     /**
46
     /**

Loading…
Cancel
Save