Browse Source

if enabled, prefer to use h264 (if it exists in the offer)

dev1
brian baldino 8 years ago
parent
commit
33a8694b25
2 changed files with 30 additions and 0 deletions
  1. 23
    0
      modules/xmpp/SDPUtil.js
  2. 7
    0
      modules/xmpp/TraceablePeerConnection.js

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

453
     getMedia: function (sdp, type) {
453
     getMedia: function (sdp, type) {
454
         return sdp.media.find(m => m.type === type);
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)
460
+     * @param {object} videoMLine the video mline object from
461
+     *  an sdp as parsed by transform.parse
462
+     * @param {string} the name of the preferred codec
463
+     */
464
+    preferVideoCodec: function(videoMLine, codecName) {
465
+        let payloadType = null;
466
+        videoMLine.rtp.forEach(rtp => {
467
+            if (rtp.codec === codecName) {
468
+                payloadType = rtp.payload;
469
+            }
470
+        });
471
+        if (payloadType) {
472
+            let payloadTypes = videoMLine.payloads.split(" ").map(p => parseInt(p));
473
+            const payloadIndex = payloadTypes.indexOf(payloadType);
474
+            payloadTypes.splice(payloadIndex, 1);
475
+            payloadTypes.unshift(payloadType);
476
+            videoMLine.payloads = payloadTypes.join(" ");
477
+        }
478
+    },
456
 };
479
 };
457
 
480
 
458
 module.exports = SDPUtil;
481
 module.exports = SDPUtil;

+ 7
- 0
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
+    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
     // if we're running on FF, transform to Plan A first.
399
     // if we're running on FF, transform to Plan A first.
393
     if (RTCBrowserType.usesUnifiedPlan()) {
400
     if (RTCBrowserType.usesUnifiedPlan()) {
394
         description.sdp = this.rtxModifier.stripRtx(description.sdp);
401
         description.sdp = this.rtxModifier.stripRtx(description.sdp);

Loading…
Cancel
Save