Browse Source

Merge pull request #358 from bbaldino/strip_rtx

Strip rtx
dev1
George Politis 8 years ago
parent
commit
2f2bbe8d92

+ 41
- 52
modules/xmpp/RtxModifier.js View File

69
  * @param {number} rtxSsrc the rtx ssrc to associate with the primary ssrc
69
  * @param {number} rtxSsrc the rtx ssrc to associate with the primary ssrc
70
  */
70
  */
71
 function updateAssociatedRtxStream (videoMLine, primarySsrcInfo, rtxSsrc) {
71
 function updateAssociatedRtxStream (videoMLine, primarySsrcInfo, rtxSsrc) {
72
-    logger.info("Updating mline to associate " + rtxSsrc + 
72
+    logger.debug("Updating mline to associate " + rtxSsrc + 
73
         " rtx ssrc with primary stream ", primarySsrcInfo.id);
73
         " rtx ssrc with primary stream ", primarySsrcInfo.id);
74
     let primarySsrc = primarySsrcInfo.id;
74
     let primarySsrc = primarySsrcInfo.id;
75
     let primarySsrcMsid = primarySsrcInfo.msid;
75
     let primarySsrcMsid = primarySsrcInfo.msid;
78
     let previousAssociatedRtxStream = 
78
     let previousAssociatedRtxStream = 
79
         getRtxSsrc (videoMLine, primarySsrc);
79
         getRtxSsrc (videoMLine, primarySsrc);
80
     if (previousAssociatedRtxStream === rtxSsrc) {
80
     if (previousAssociatedRtxStream === rtxSsrc) {
81
-        logger.info(rtxSsrc + " was already associated with " +
81
+        logger.debug(rtxSsrc + " was already associated with " +
82
             primarySsrc);
82
             primarySsrc);
83
         return;
83
         return;
84
     }
84
     }
85
     if (previousAssociatedRtxStream) {
85
     if (previousAssociatedRtxStream) {
86
-        logger.info(primarySsrc + " was previously assocaited with rtx " +
86
+        logger.debug(primarySsrc + " was previously assocaited with rtx " +
87
             previousAssociatedRtxStream + ", removing all references to it");
87
             previousAssociatedRtxStream + ", removing all references to it");
88
         // Stream already had an rtx ssrc that is different than the one given,
88
         // Stream already had an rtx ssrc that is different than the one given,
89
         //  remove all trace of the old one
89
         //  remove all trace of the old one
90
         videoMLine.ssrcs = videoMLine.ssrcs
90
         videoMLine.ssrcs = videoMLine.ssrcs
91
             .filter(ssrcInfo => ssrcInfo.id !== previousAssociatedRtxStream);
91
             .filter(ssrcInfo => ssrcInfo.id !== previousAssociatedRtxStream);
92
-        logger.info("groups before filtering for " + 
92
+        logger.debug("groups before filtering for " + 
93
             previousAssociatedRtxStream);
93
             previousAssociatedRtxStream);
94
-        logger.info(JSON.stringify(videoMLine.ssrcGroups));
94
+        logger.debug(JSON.stringify(videoMLine.ssrcGroups));
95
         videoMLine.ssrcGroups = videoMLine.ssrcGroups
95
         videoMLine.ssrcGroups = videoMLine.ssrcGroups
96
             .filter(groupInfo => {
96
             .filter(groupInfo => {
97
                 return groupInfo
97
                 return groupInfo
151
      *  ssrcs to their corresponding rtx ssrcs
151
      *  ssrcs to their corresponding rtx ssrcs
152
      */
152
      */
153
     setSsrcCache (ssrcMapping) {
153
     setSsrcCache (ssrcMapping) {
154
-        logger.info("Setting ssrc cache to ", ssrcMapping);
154
+        logger.debug("Setting ssrc cache to ", ssrcMapping);
155
         this.correspondingRtxSsrcs = ssrcMapping;
155
         this.correspondingRtxSsrcs = ssrcMapping;
156
     }
156
     }
157
 
157
 
168
             parsedSdp.media.find(mLine => mLine.type === "video");
168
             parsedSdp.media.find(mLine => mLine.type === "video");
169
         if (videoMLine.direction === "inactive" ||
169
         if (videoMLine.direction === "inactive" ||
170
                 videoMLine.direction === "recvonly") {
170
                 videoMLine.direction === "recvonly") {
171
-            logger.info("RtxModifier doing nothing, video " +
171
+            logger.debug("RtxModifier doing nothing, video " +
172
                 "m line is inactive or recvonly");
172
                 "m line is inactive or recvonly");
173
             return sdpStr;
173
             return sdpStr;
174
         }
174
         }
175
         if (!videoMLine.ssrcs) {
175
         if (!videoMLine.ssrcs) {
176
-          logger.info("RtxModifier doing nothing, no video ssrcs present");
176
+          logger.debug("RtxModifier doing nothing, no video ssrcs present");
177
           return sdpStr;
177
           return sdpStr;
178
         }
178
         }
179
-        logger.info("Current ssrc mapping: ", this.correspondingRtxSsrcs);
179
+        logger.debug("Current ssrc mapping: ", this.correspondingRtxSsrcs);
180
         let primaryVideoSsrcs = getPrimaryVideoSsrcs(videoMLine);
180
         let primaryVideoSsrcs = getPrimaryVideoSsrcs(videoMLine);
181
-        logger.info("Parsed primary video ssrcs ", primaryVideoSsrcs, " " +
181
+        logger.debug("Parsed primary video ssrcs ", primaryVideoSsrcs, " " +
182
             "making sure all have rtx streams");
182
             "making sure all have rtx streams");
183
         primaryVideoSsrcs.forEach(ssrc => {
183
         primaryVideoSsrcs.forEach(ssrc => {
184
             let msid = SDPUtil.getSsrcAttribute(videoMLine, ssrc, "msid");
184
             let msid = SDPUtil.getSsrcAttribute(videoMLine, ssrc, "msid");
185
             let cname = SDPUtil.getSsrcAttribute(videoMLine, ssrc, "cname");
185
             let cname = SDPUtil.getSsrcAttribute(videoMLine, ssrc, "cname");
186
             let correspondingRtxSsrc = this.correspondingRtxSsrcs.get(ssrc);
186
             let correspondingRtxSsrc = this.correspondingRtxSsrcs.get(ssrc);
187
             if (correspondingRtxSsrc) {
187
             if (correspondingRtxSsrc) {
188
-                logger.info("Already have an associated rtx ssrc for " +
188
+                logger.debug("Already have an associated rtx ssrc for " +
189
                     " video ssrc " + ssrc + ": " + 
189
                     " video ssrc " + ssrc + ": " + 
190
                     correspondingRtxSsrc);
190
                     correspondingRtxSsrc);
191
             } else {
191
             } else {
192
-                logger.info("No previously associated rtx ssrc for " +
192
+                logger.debug("No previously associated rtx ssrc for " +
193
                     " video ssrc " + ssrc);
193
                     " video ssrc " + ssrc);
194
                 // If there's one in the sdp already for it, we'll just set
194
                 // If there's one in the sdp already for it, we'll just set
195
                 //  that as the corresponding one
195
                 //  that as the corresponding one
196
                 let previousAssociatedRtxStream = 
196
                 let previousAssociatedRtxStream = 
197
                     getRtxSsrc (videoMLine, ssrc);
197
                     getRtxSsrc (videoMLine, ssrc);
198
                 if (previousAssociatedRtxStream) {
198
                 if (previousAssociatedRtxStream) {
199
-                    logger.info("Rtx stream " + previousAssociatedRtxStream + 
199
+                    logger.debug("Rtx stream " + previousAssociatedRtxStream + 
200
                         " already existed in the sdp as an rtx stream for " +
200
                         " already existed in the sdp as an rtx stream for " +
201
                         ssrc);
201
                         ssrc);
202
                     correspondingRtxSsrc = previousAssociatedRtxStream;
202
                     correspondingRtxSsrc = previousAssociatedRtxStream;
203
                 } else {
203
                 } else {
204
                     correspondingRtxSsrc = SDPUtil.generateSsrc();
204
                     correspondingRtxSsrc = SDPUtil.generateSsrc();
205
-                    logger.info("Generated rtx ssrc " + correspondingRtxSsrc + 
205
+                    logger.debug("Generated rtx ssrc " + correspondingRtxSsrc + 
206
                         " for ssrc " + ssrc);
206
                         " for ssrc " + ssrc);
207
                 }
207
                 }
208
-                logger.info("Caching rtx ssrc " + correspondingRtxSsrc + 
208
+                logger.debug("Caching rtx ssrc " + correspondingRtxSsrc + 
209
                     " for video ssrc " + ssrc);
209
                     " for video ssrc " + ssrc);
210
                 this.correspondingRtxSsrcs.set(ssrc, correspondingRtxSsrc);
210
                 this.correspondingRtxSsrcs.set(ssrc, correspondingRtxSsrc);
211
             }
211
             }
222
     }
222
     }
223
 
223
 
224
     /**
224
     /**
225
-     * Remove all reference to any rtx ssrcs that 
226
-     *  don't correspond to the primary stream.
227
-     * Must be called *after* any simulcast streams
228
-     *  have been imploded
225
+     * Strip all rtx streams from the given sdp
229
      * @param {string} sdpStr sdp in raw string format
226
      * @param {string} sdpStr sdp in raw string format
227
+     * @returns {string} sdp string with all rtx streams stripped
230
      */
228
      */
231
-    implodeRemoteRtxSsrcs (sdpStr) {
232
-        let parsedSdp = transform.parse(sdpStr);
233
-        let videoMLine = 
229
+    stripRtx (sdpStr) {
230
+        const parsedSdp = transform.parse(sdpStr);
231
+        const videoMLine = 
234
             parsedSdp.media.find(mLine => mLine.type === "video");
232
             parsedSdp.media.find(mLine => mLine.type === "video");
235
         if (videoMLine.direction === "inactive" ||
233
         if (videoMLine.direction === "inactive" ||
236
                 videoMLine.direction === "recvonly") {
234
                 videoMLine.direction === "recvonly") {
237
-            logger.info("RtxModifier doing nothing, video " +
235
+            logger.debug("RtxModifier doing nothing, video " +
238
                 "m line is inactive or recvonly");
236
                 "m line is inactive or recvonly");
239
             return sdpStr;
237
             return sdpStr;
240
         }
238
         }
239
+        if (!videoMLine.ssrcs) {
240
+          logger.debug("RtxModifier doing nothing, no video ssrcs present");
241
+          return sdpStr;
242
+        }
241
         if (!videoMLine.ssrcGroups) {
243
         if (!videoMLine.ssrcGroups) {
242
-            // Nothing to do
243
-            return sdpStr;
244
+          logger.debug("RtxModifier doing nothing, " + 
245
+              "no video ssrcGroups present");
246
+          return sdpStr;
244
         }
247
         }
245
-
246
-        // Returns true if the given ssrc is present
247
-        //  in the mLine's ssrc list
248
-        let ssrcExists = (ssrcToFind) => {
249
-            return videoMLine.ssrcs.
250
-              find((ssrc) => ssrc.id + "" === ssrcToFind);
251
-        };
252
-        let ssrcsToRemove = [];
253
-        videoMLine.ssrcGroups.forEach(group => {
254
-            if (group.semantics === "FID") {
255
-                let primarySsrc = group.ssrcs.split(" ")[0];
256
-                let rtxSsrc = group.ssrcs.split(" ")[1];
257
-                if (!ssrcExists(primarySsrc)) {
258
-                    ssrcsToRemove.push(rtxSsrc);
259
-                }
260
-            }
248
+        const fidGroups = videoMLine.ssrcGroups
249
+            .filter(group => group.semantics === "FID");
250
+        // Remove the fid groups from the mline
251
+        videoMLine.ssrcGroups = videoMLine.ssrcGroups
252
+            .filter(group => group.semantics !== "FID");
253
+        // Get the rtx ssrcs and remove them from the mline
254
+        const ssrcsToRemove = [];
255
+        fidGroups.forEach(fidGroup => {
256
+            const groupSsrcs = SDPUtil.parseGroupSsrcs(fidGroup);
257
+            const rtxSsrc = groupSsrcs[1];
258
+            ssrcsToRemove.push(rtxSsrc);
261
         });
259
         });
262
         videoMLine.ssrcs = videoMLine.ssrcs
260
         videoMLine.ssrcs = videoMLine.ssrcs
263
-            .filter(ssrc => ssrcsToRemove.indexOf(ssrc.id + "") === -1);
264
-        videoMLine.ssrcGroups = videoMLine.ssrcGroups
265
-            .filter(group => {
266
-                let ssrcs = group.ssrcs.split(" ");
267
-                for (let i = 0; i < ssrcs.length; ++i) {
268
-                    if (ssrcsToRemove.indexOf(ssrcs[i]) !== -1) {
269
-                        return false;
270
-                    }
271
-                }
272
-                return true;
273
-            });
261
+            .filter(line => ssrcsToRemove.indexOf(line.id) === -1);
262
+        
274
         return transform.write(parsedSdp);
263
         return transform.write(parsedSdp);
275
     }
264
     }
276
 }
265
 }

+ 18
- 0
modules/xmpp/RtxModifier.spec.js View File

287
         });
287
         });
288
       });
288
       });
289
     });
289
     });
290
+
291
+    describe("stripRtx", function() {
292
+        beforeEach(function() {
293
+        });
294
+        it ("should strip all rtx streams from an sdp with rtx", function() {
295
+            const sdpStr = transform.write(SampleSdpStrings.rtxVideoSdp);
296
+            const newSdpStr = this.rtxModifier.stripRtx(sdpStr);
297
+            const newSdp = transform.parse(newSdpStr);
298
+            const fidGroups = getVideoGroups(newSdp, "FID");
299
+            expect(fidGroups.length).toEqual(0);
300
+            expect(numVideoSsrcs(newSdp)).toEqual(1);
301
+        });
302
+        it ("should do nothing to an sdp with no rtx", function() {
303
+            const sdpStr = transform.write(SampleSdpStrings.plainVideoSdp);
304
+            const newSdpStr = this.rtxModifier.stripRtx(sdpStr);
305
+            expect(newSdpStr).toEqual(sdpStr);
306
+        });
307
+    });
290
 });
308
 });
291
 
309
 
292
 /*eslint-enable max-len*/
310
 /*eslint-enable max-len*/

+ 10
- 0
modules/xmpp/SDPUtil.js View File

443
             .split(" ")
443
             .split(" ")
444
             .map(ssrcStr => parseInt(ssrcStr));
444
             .map(ssrcStr => parseInt(ssrcStr));
445
     },
445
     },
446
+
447
+    /**
448
+     * Get the mline of the given type from the given sdp
449
+     * @param {object} sdp sdp as parsed from transform.parse
450
+     * @param {string} type the type of the desired mline (e.g. "video")
451
+     * @returns {object} a media object
452
+     */
453
+    getMedia: function (sdp, type) {
454
+        return sdp.media.find(m => m.type === type);
455
+    },
446
 };
456
 };
447
 
457
 
448
 module.exports = SDPUtil;
458
 module.exports = SDPUtil;

+ 2
- 3
modules/xmpp/TraceablePeerConnection.js View File

389
     description = this.simulcast.mungeRemoteDescription(description);
389
     description = this.simulcast.mungeRemoteDescription(description);
390
     this.trace('setRemoteDescription::postTransform (simulcast)', dumpSDP(description));
390
     this.trace('setRemoteDescription::postTransform (simulcast)', dumpSDP(description));
391
 
391
 
392
-    description.sdp = this.rtxModifier.implodeRemoteRtxSsrcs(description.sdp);
393
-    this.trace('setRemoteDescription::postTransform (implodeRemoteRtxSsrcs)', dumpSDP(description));
394
-
395
     // if we're running on FF, transform to Plan A first.
392
     // if we're running on FF, transform to Plan A first.
396
     if (RTCBrowserType.usesUnifiedPlan()) {
393
     if (RTCBrowserType.usesUnifiedPlan()) {
394
+        description.sdp = this.rtxModifier.stripRtx(description.sdp);
395
+        this.trace('setRemoteDescription::postTransform (stripRtx)', dumpSDP(description));
397
         description = this.interop.toUnifiedPlan(description);
396
         description = this.interop.toUnifiedPlan(description);
398
         this.trace('setRemoteDescription::postTransform (Plan A)', dumpSDP(description));
397
         this.trace('setRemoteDescription::postTransform (Plan A)', dumpSDP(description));
399
     }
398
     }

Loading…
Cancel
Save