Explorar el Código

Merge pull request #355 from bbaldino/prefer_h264_option

if enabled, prefer to use h264 (if it exists in the offer)
dev1
bbaldino hace 8 años
padre
commit
c2235fd6ae

+ 2
- 0
doc/API.md Ver fichero

@@ -54,6 +54,8 @@ The ```options``` parameter is JS object with the following properties:
54 54
     14. enableAnalyticsLogging - boolean property (default false). Enables/disables analytics logging.
55 55
     15. callStatsCustomScriptUrl - (optional) custom url to access callstats client script
56 56
     16. callStatsConfIDNamespace - (optional) a namespace to prepend the callstats conference ID with. Defaults to the window.location.hostname
57
+    17. disableRtx - (optional) boolean property (default to false).  Enables/disable the use of RTX.
58
+    18. preferH264 - (optional) boolean property (default to false).  Enables/disable preferring the first instance of an h264 codec in an offer by moving it to the front of the codec list.
57 59
 
58 60
 * ```JitsiMeetJS.JitsiConnection``` - the ```JitsiConnection``` constructor. You can use that to create new server connection.
59 61
 

+ 28
- 0
modules/xmpp/SDPUtil.js Ver fichero

@@ -453,6 +453,34 @@ var SDPUtil = {
453 453
     getMedia: function (sdp, type) {
454 454
         return sdp.media.find(m => m.type === type);
455 455
     },
456
+    /**
457
+     * Sets the given codecName as the preferred codec by
458
+     *  moving it to the beginning of the payload types
459
+     *  list (modifies the given mline in place).  If there
460
+     *  are multiple options within the same codec (multiple h264
461
+     *  profiles, for instance), this will prefer the first one
462
+     *  that is found.
463
+     * @param {object} videoMLine the video mline object from
464
+     *  an sdp as parsed by transform.parse
465
+     * @param {string} the name of the preferred codec
466
+     */
467
+    preferVideoCodec: function(videoMLine, codecName) {
468
+        let payloadType = null;
469
+        for (let i = 0; i < videoMLine.rtp.length; ++i) {
470
+          const rtp = videoMLine.rtp[i];
471
+          if (rtp.codec === codecName) {
472
+              payloadType = rtp.payload;
473
+              break;
474
+          }
475
+        }
476
+        if (payloadType) {
477
+            const payloadTypes = videoMLine.payloads.split(" ").map(p => parseInt(p));
478
+            const payloadIndex = payloadTypes.indexOf(payloadType);
479
+            payloadTypes.splice(payloadIndex, 1);
480
+            payloadTypes.unshift(payloadType);
481
+            videoMLine.payloads = payloadTypes.join(" ");
482
+        }
483
+    },
456 484
 };
457 485
 
458 486
 module.exports = SDPUtil;

+ 15
- 4
modules/xmpp/SDPUtil.spec.js Ver fichero

@@ -1,11 +1,22 @@
1
-var SDPUtil = require("./SDPUtil.js");
1
+import * as SDPUtil from "./SDPUtil";
2
+import * as SampleSdpStrings from "./SampleSdpStrings.js";
2 3
 
3 4
 describe("SDPUtil", function() {
4
-
5 5
     it("should parse an ice ufrag correctly", function() {
6
-        let line = "a=ice-ufrag:3jlcc1b3j1rqt6";
7
-        let parsed = SDPUtil.parse_iceufrag(line);
6
+        const line = "a=ice-ufrag:3jlcc1b3j1rqt6";
7
+        const parsed = SDPUtil.parse_iceufrag(line);
8 8
 
9 9
         expect(parsed).toEqual("3jlcc1b3j1rqt6");
10 10
     });
11
+
12
+    describe("preferVideoCodec", function() {
13
+        it("should move a preferred codec to the front", function() {
14
+            const sdp = SampleSdpStrings.multiCodecVideoSdp;
15
+            const videoMLine = sdp.media.find(m => m.type === "video");
16
+            SDPUtil.preferVideoCodec(videoMLine, "H264");
17
+            const newPayloadTypesOrder = 
18
+                videoMLine.payloads.split(" ").map(ptStr => parseInt(ptStr));
19
+            expect(newPayloadTypesOrder[0]).toEqual(126);
20
+        });
21
+    });
11 22
 });

+ 28
- 0
modules/xmpp/SampleSdpStrings.js Ver fichero

@@ -69,6 +69,31 @@ const plainVideoMLineSdp = "" +
69 69
 "a=ssrc:1757014965 cname:peDGrDD6WsxUOki/\r\n" +
70 70
 "a=rtcp-mux\r\n";
71 71
 
72
+// A basic sdp video mline with a single stream and multiple codecs
73
+const multiCodecVideoMLine = "" +
74
+"m=video 9 RTP/SAVPF 100 126 97\r\n" +
75
+"c=IN IP4 0.0.0.0\r\n" +
76
+"a=rtpmap:100 VP8/90000\r\n" +
77
+"a=rtpmap:126 H264/90000\r\n" +
78
+"a=rtpmap:97 H264/90000\r\n" +
79
+"a=rtcp:9 IN IP4 0.0.0.0\r\n" +
80
+"a=rtcp-fb:100 ccm fir\r\n" +
81
+"a=rtcp-fb:100 nack\r\n" +
82
+"a=rtcp-fb:100 nack pli\r\n" +
83
+"a=rtcp-fb:100 goog-remb\r\n" +
84
+"a=fmtp:126 profile-level-id=42e01f;level-asymmetry-allowed=1;packetization-mode=1\r\n" +
85
+"a=fmtp:97 profile-level-id=42e01f;level-asymmetry-allowed=1\r\n" +
86
+"a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n" +
87
+"a=setup:passive\r\n" +
88
+"a=mid:video\r\n" +
89
+"a=sendrecv\r\n" +
90
+"a=ice-ufrag:adPg\r\n" +
91
+"a=ice-pwd:Xsr05Mq8S7CR44DAnusZE26F\r\n" +
92
+"a=fingerprint:sha-256 6A:39:DE:11:24:AD:2E:4E:63:D6:69:D3:85:05:53:C7:3C:38:A4:B7:91:74:C0:91:44:FC:94:63:7F:01:AB:A9\r\n" +
93
+"a=ssrc:1757014965 msid:0836cc8e-a7bb-47e9-affb-0599414bc56d bdbd2c0a-7959-4578-8db5-9a6a1aec4ecf\r\n" +
94
+"a=ssrc:1757014965 cname:peDGrDD6WsxUOki/\r\n" +
95
+"a=rtcp-mux\r\n";
96
+
72 97
 // An sdp video mline with 3 simulcast streams
73 98
 const simulcastVideoMLineSdp = "" +
74 99
 "m=video 9 RTP/SAVPF 100\r\n" +
@@ -165,10 +190,13 @@ const simulcastRtxSdpStr = baseSessionSdp + baseAudioMLineSdp + simulcastRtxVide
165 190
 const plainVideoSdpStr = baseSessionSdp + baseAudioMLineSdp + plainVideoMLineSdp + baseDataMLineSdp;
166 191
 // A full sdp string representing a client doing a single video stream with rtx
167 192
 const rtxVideoSdpStr = baseSessionSdp + baseAudioMLineSdp + rtxVideoMLineSdp + baseDataMLineSdp;
193
+// A full sdp string representing a client doing a single video stream with multiple codec options
194
+const multiCodecVideoSdpStr = baseSessionSdp + baseAudioMLineSdp + multiCodecVideoMLine + baseDataMLineSdp;
168 195
 
169 196
 export const simulcastSdp = transform.parse(simulcastSdpStr);
170 197
 export const simulcastRtxSdp = transform.parse(simulcastRtxSdpStr);
171 198
 export const plainVideoSdp = transform.parse(plainVideoSdpStr);
172 199
 export const rtxVideoSdp = transform.parse(rtxVideoSdpStr);
200
+export const multiCodecVideoSdp = transform.parse(multiCodecVideoSdpStr);
173 201
 
174 202
 /*eslint-enable max-len*/

+ 7
- 0
modules/xmpp/TraceablePeerConnection.js Ver fichero

@@ -389,6 +389,13 @@ TraceablePeerConnection.prototype.setRemoteDescription
389 389
     description = this.simulcast.mungeRemoteDescription(description);
390 390
     this.trace('setRemoteDescription::postTransform (simulcast)', dumpSDP(description));
391 391
 
392
+    if (this.session.room.options.preferH264) {
393
+        const parsedSdp = transform.parse(description.sdp);
394
+        const videoMLine = parsedSdp.media.find(m => m.type === "video");
395
+        SDPUtil.preferVideoCodec(videoMLine, "h264");
396
+        description.sdp = transform.write(parsedSdp);
397
+    }
398
+
392 399
     // if we're running on FF, transform to Plan A first.
393 400
     if (RTCBrowserType.usesUnifiedPlan()) {
394 401
         description.sdp = this.rtxModifier.stripRtx(description.sdp);

Loading…
Cancelar
Guardar