|
@@ -595,6 +595,61 @@ const SDPUtil = {
|
595
|
595
|
payloadTypes.unshift(payloadType);
|
596
|
596
|
videoMLine.payloads = payloadTypes.join(' ');
|
597
|
597
|
}
|
|
598
|
+ },
|
|
599
|
+
|
|
600
|
+ /**
|
|
601
|
+ * Strips the given codec from the given mline. All related RTX payload
|
|
602
|
+ * types are also stripped. If the resulting mline would have no codecs,
|
|
603
|
+ * it's disabled.
|
|
604
|
+ *
|
|
605
|
+ * @param {object} videoMLine the video mline object from an sdp as parsed
|
|
606
|
+ * by transform.parse.
|
|
607
|
+ * @param {string} codecName the name of the codec which will be stripped.
|
|
608
|
+ */
|
|
609
|
+ stripVideoCodec(videoMLine, codecName) {
|
|
610
|
+ if (!codecName) {
|
|
611
|
+ return;
|
|
612
|
+ }
|
|
613
|
+
|
|
614
|
+ const removePts = [];
|
|
615
|
+
|
|
616
|
+ for (const rtp of videoMLine.rtp) {
|
|
617
|
+ if (rtp.codec
|
|
618
|
+ && rtp.codec.toLowerCase() === codecName.toLowerCase()) {
|
|
619
|
+ removePts.push(rtp.payload);
|
|
620
|
+ }
|
|
621
|
+ }
|
|
622
|
+
|
|
623
|
+ if (removePts.length > 0) {
|
|
624
|
+ // We also need to remove the payload types that are related to RTX
|
|
625
|
+ // for the codecs we want to disable.
|
|
626
|
+ const rtxApts = removePts.map(item => `apt=${item}`);
|
|
627
|
+ const rtxPts = videoMLine.fmtp.filter(
|
|
628
|
+ item => rtxApts.indexOf(item.config) !== -1);
|
|
629
|
+
|
|
630
|
+ removePts.push(...rtxPts.map(item => item.payload));
|
|
631
|
+
|
|
632
|
+ const allPts = videoMLine.payloads.split(' ').map(Number);
|
|
633
|
+ const keepPts = allPts.filter(pt => removePts.indexOf(pt) === -1);
|
|
634
|
+
|
|
635
|
+ if (keepPts.length === 0) {
|
|
636
|
+ // There are no other video codecs, disable the stream.
|
|
637
|
+ videoMLine.port = 0;
|
|
638
|
+ videoMLine.direction = 'inactive';
|
|
639
|
+ videoMLine.payloads = '*';
|
|
640
|
+ } else {
|
|
641
|
+ videoMLine.payloads = keepPts.join(' ');
|
|
642
|
+ }
|
|
643
|
+
|
|
644
|
+ videoMLine.rtp = videoMLine.rtp.filter(
|
|
645
|
+ item => keepPts.indexOf(item.payload) !== -1);
|
|
646
|
+ videoMLine.fmtp = videoMLine.fmtp.filter(
|
|
647
|
+ item => keepPts.indexOf(item.payload) !== -1);
|
|
648
|
+ if (videoMLine.rtcpFb) {
|
|
649
|
+ videoMLine.rtcpFb = videoMLine.rtcpFb.filter(
|
|
650
|
+ item => keepPts.indexOf(item.payload) !== -1);
|
|
651
|
+ }
|
|
652
|
+ }
|
598
|
653
|
}
|
599
|
654
|
};
|
600
|
655
|
|