[Pkg-voip-commits] [janus] 20/163: Reorganized how we munge SDP when simulcasting as a method, and added to createAnswer (but not for Chrome, it breaks video there)
Jonas Smedegaard
dr at jones.dk
Sat Oct 28 01:22:04 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/0.2.5-1
in repository janus.
commit 90f487594479040d0bcdc1f049fb369793d2db5b
Author: Lorenzo Miniero <lminiero at gmail.com>
Date: Mon Jul 10 19:01:15 2017 +0200
Reorganized how we munge SDP when simulcasting as a method, and added to createAnswer (but not for Chrome, it breaks video there)
---
html/janus.js | 315 +++++++++++++++++++++++++++++++++----------------
html/janus.nojquery.js | 315 +++++++++++++++++++++++++++++++++----------------
2 files changed, 428 insertions(+), 202 deletions(-)
diff --git a/html/janus.js b/html/janus.js
index c7dda70..275c3f0 100644
--- a/html/janus.js
+++ b/html/janus.js
@@ -1759,7 +1759,8 @@ function Janus(gatewayCallbacks) {
}
Janus.debug(mediaConstraints);
// Check if this is Firefox and we've been asked to do simulcasting
- if(simulcast && adapter.browserDetails.browser === "firefox") {
+ var sendVideo = isVideoSendEnabled(media);
+ if(sendVideo && simulcast && adapter.browserDetails.browser === "firefox") {
// FIXME Based on https://gist.github.com/voluntas/088bc3cc62094730647b
Janus.log("Enabling Simulcasting for Firefox (RID)");
var sender = config.pc.getSenders()[1];
@@ -1777,108 +1778,11 @@ function Janus(gatewayCallbacks) {
Janus.debug(offer);
if(config.mySdp === null || config.mySdp === undefined) {
Janus.log("Setting local description");
- if(simulcast) {
+ if(sendVideo && simulcast) {
// This SDP munging only works with Chrome
if(adapter.browserDetails.browser === "chrome") {
Janus.log("Enabling Simulcasting for Chrome (SDP munging)");
- // Let's munge the SDP to add the attributes for enabling simulcasting
- // (based on https://gist.github.com/ggarber/a19b4c33510028b9c657)
- var lines = offer.sdp.split("\r\n");
- var video = false;
- var ssrc = [ -1 ], ssrc_fid = -1;
- var cname = null, msid = null, mslabel = null, label = null;
- var insertAt = -1;
- for(var i=0; i<lines.length; i++) {
- var mline = lines[i].match(/m=(\w+) */);
- if(mline) {
- var medium = mline[1];
- if(medium === "video") {
- // New video m-line: make sure it's the first one
- if(ssrc[0] < 0) {
- video = true;
- } else {
- // We're done, let's add the new attributes here
- insertAt = i;
- break;
- }
- } else {
- // New non-video m-line: do we have what we were looking for?
- if(ssrc[0] > -1) {
- // We're done, let's add the new attributes here
- insertAt = i;
- break;
- }
- }
- continue;
- }
- var fid = lines[i].match(/a=ssrc-group:FID (\d+) (\d+)/);
- if(fid) {
- ssrc[0] = fid[1];
- ssrc_fid = fid[2];
- lines.splice(i, 1); i--;
- continue;
- }
- if(ssrc[0]) {
- var match = lines[i].match('a=ssrc:' + ssrc[0] + ' cname:(.+)')
- if(match) {
- cname = match[1];
- }
- match = lines[i].match('a=ssrc:' + ssrc[0] + ' msid:(.+)')
- if(match) {
- msid = match[1];
- }
- match = lines[i].match('a=ssrc:' + ssrc[0] + ' mslabel:(.+)')
- if(match) {
- mslabel = match[1];
- }
- match = lines[i].match('a=ssrc:' + ssrc + ' label:(.+)')
- if(match) {
- label = match[1];
- }
- if(lines[i].indexOf('a=ssrc:' + ssrc_fid) === 0) {
- lines.splice(i, 1); i--;
- continue;
- }
- if(lines[i].indexOf('a=ssrc:' + ssrc[0]) === 0) {
- lines.splice(i, 1); i--;
- continue;
- }
- }
- if(lines[i].length == 0) {
- lines.splice(i, 1); i--;
- continue;
- }
- }
- if(insertAt < 0) {
- // Append at the end
- insertAt = lines.length;
- }
- // Generate a couple of SSRCs
- ssrc[1] = Math.floor(Math.random()*0xFFFFFFFF);
- ssrc[2] = Math.floor(Math.random()*0xFFFFFFFF);
- // Add attributes to the SDP
- for(var i=0; i<ssrc.length; i++) {
- if(cname) {
- lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' cname:' + cname);
- insertAt++;
- }
- if(msid) {
- lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' msid:' + msid);
- insertAt++;
- }
- if(mslabel) {
- lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' mslabel:' + msid);
- insertAt++;
- }
- if(label) {
- lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' label:' + msid);
- insertAt++;
- }
- }
- lines.splice(insertAt, 0, 'a=ssrc-group:SIM ' + ssrc[0] + ' ' + ssrc[1] + ' ' + ssrc[2]);
- offer.sdp = lines.join("\r\n");
- if(!offer.sdp.endsWith("\r\n"))
- offer.sdp += "\r\n";
+ offer.sdp = mungeSdpForSimulcasting(offer.sdp);
} else if(adapter.browserDetails.browser !== "firefox") {
Janus.warn("simulcast=true, but this is not Chrome nor Firefox, ignoring");
}
@@ -1920,7 +1824,12 @@ function Janus(gatewayCallbacks) {
return;
}
var config = pluginHandle.webrtcStuff;
- Janus.log("Creating answer (iceDone=" + config.iceDone + ")");
+ var simulcast = callbacks.simulcast === true ? true : false;
+ if(!simulcast) {
+ Janus.log("Creating answer (iceDone=" + config.iceDone + ")");
+ } else {
+ Janus.log("Creating answer (iceDone=" + config.iceDone + ", simulcast=" + simulcast + ")");
+ }
var mediaConstraints = null;
if(adapter.browserDetails.browser == "firefox" || adapter.browserDetails.browser == "edge") {
mediaConstraints = {
@@ -1936,11 +1845,37 @@ function Janus(gatewayCallbacks) {
};
}
Janus.debug(mediaConstraints);
+ // Check if this is Firefox and we've been asked to do simulcasting
+ var sendVideo = isVideoSendEnabled(media);
+ if(sendVideo && simulcast && adapter.browserDetails.browser === "firefox") {
+ // FIXME Based on https://gist.github.com/voluntas/088bc3cc62094730647b
+ Janus.log("Enabling Simulcasting for Firefox (RID)");
+ var sender = config.pc.getSenders()[1];
+ Janus.log(sender);
+ var parameters = sender.getParameters();
+ Janus.log(parameters);
+ sender.setParameters({encodings: [
+ { rid: "high", active: true, priority: "high", maxBitrate: 1000000 },
+ { rid: "medium", active: true, priority: "medium", maxBitrate: 300000 },
+ { rid: "low", active: true, priority: "low", maxBitrate: 100000 }
+ ]});
+ }
config.pc.createAnswer(
function(answer) {
Janus.debug(answer);
if(config.mySdp === null || config.mySdp === undefined) {
Janus.log("Setting local description");
+ if(sendVideo && simulcast) {
+ // This SDP munging only works with Chrome
+ if(adapter.browserDetails.browser === "chrome") {
+ // FIXME Apparently trying to simulcast when answering breaks video in Chrome...
+ //~ Janus.log("Enabling Simulcasting for Chrome (SDP munging)");
+ //~ answer.sdp = mungeSdpForSimulcasting(answer.sdp);
+ Janus.warn("simulcast=true, but this is an answer, and video breaks in Chrome if we enable it");
+ } else if(adapter.browserDetails.browser !== "firefox") {
+ Janus.warn("simulcast=true, but this is not Chrome nor Firefox, ignoring");
+ }
+ }
config.mySdp = answer.sdp;
config.pc.setLocalDescription(answer);
}
@@ -2253,6 +2188,184 @@ function Janus(gatewayCallbacks) {
pluginHandle.oncleanup();
}
+ // Helper method to munge an SDP to enable simulcasting (Chrome only)
+ function mungeSdpForSimulcasting(sdp) {
+ // Let's munge the SDP to add the attributes for enabling simulcasting
+ // (based on https://gist.github.com/ggarber/a19b4c33510028b9c657)
+ var lines = sdp.split("\r\n");
+ var video = false;
+ var ssrc = [ -1 ], ssrc_fid = -1;
+ var cname = null, msid = null, mslabel = null, label = null;
+ var insertAt = -1;
+ for(var i=0; i<lines.length; i++) {
+ var mline = lines[i].match(/m=(\w+) */);
+ if(mline) {
+ var medium = mline[1];
+ if(medium === "video") {
+ // New video m-line: make sure it's the first one
+ if(ssrc[0] < 0) {
+ video = true;
+ } else {
+ // We're done, let's add the new attributes here
+ insertAt = i;
+ break;
+ }
+ } else {
+ // New non-video m-line: do we have what we were looking for?
+ if(ssrc[0] > -1) {
+ // We're done, let's add the new attributes here
+ insertAt = i;
+ break;
+ }
+ }
+ continue;
+ }
+ if(!video)
+ continue;
+ var fid = lines[i].match(/a=ssrc-group:FID (\d+) (\d+)/);
+ if(fid) {
+ ssrc[0] = fid[1];
+ ssrc_fid = fid[2];
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ if(ssrc[0]) {
+ var match = lines[i].match('a=ssrc:' + ssrc[0] + ' cname:(.+)')
+ if(match) {
+ cname = match[1];
+ }
+ match = lines[i].match('a=ssrc:' + ssrc[0] + ' msid:(.+)')
+ if(match) {
+ msid = match[1];
+ }
+ match = lines[i].match('a=ssrc:' + ssrc[0] + ' mslabel:(.+)')
+ if(match) {
+ mslabel = match[1];
+ }
+ match = lines[i].match('a=ssrc:' + ssrc + ' label:(.+)')
+ if(match) {
+ label = match[1];
+ }
+ if(lines[i].indexOf('a=ssrc:' + ssrc_fid) === 0) {
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ if(lines[i].indexOf('a=ssrc:' + ssrc[0]) === 0) {
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ }
+ if(lines[i].length == 0) {
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ }
+ if(ssrc[0] < 0) {
+ // Couldn't find a FID attribute, let's just take the first video SSRC we find
+ insertAt = -1;
+ video = false;
+ for(var i=0; i<lines.length; i++) {
+ var mline = lines[i].match(/m=(\w+) */);
+ if(mline) {
+ var medium = mline[1];
+ if(medium === "video") {
+ // New video m-line: make sure it's the first one
+ if(ssrc[0] < 0) {
+ video = true;
+ } else {
+ // We're done, let's add the new attributes here
+ insertAt = i;
+ break;
+ }
+ } else {
+ // New non-video m-line: do we have what we were looking for?
+ if(ssrc[0] > -1) {
+ // We're done, let's add the new attributes here
+ insertAt = i;
+ break;
+ }
+ }
+ continue;
+ }
+ if(!video)
+ continue;
+ if(ssrc[0] < 0) {
+ var value = lines[i].match(/a=ssrc:(\d+)/);
+ if(value) {
+ ssrc[0] = value[1];
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ } else {
+ var match = lines[i].match('a=ssrc:' + ssrc[0] + ' cname:(.+)')
+ if(match) {
+ cname = match[1];
+ }
+ match = lines[i].match('a=ssrc:' + ssrc[0] + ' msid:(.+)')
+ if(match) {
+ msid = match[1];
+ }
+ match = lines[i].match('a=ssrc:' + ssrc[0] + ' mslabel:(.+)')
+ if(match) {
+ mslabel = match[1];
+ }
+ match = lines[i].match('a=ssrc:' + ssrc + ' label:(.+)')
+ if(match) {
+ label = match[1];
+ }
+ if(lines[i].indexOf('a=ssrc:' + ssrc_fid) === 0) {
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ if(lines[i].indexOf('a=ssrc:' + ssrc[0]) === 0) {
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ }
+ if(lines[i].length == 0) {
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ }
+ }
+ if(ssrc[0] < 0) {
+ // Still nothing, let's just return the SDP we were asked to munge
+ Janus.warn("Couldn't find the video SSRC, simulcasting NOT enabled");
+ return sdp;
+ }
+ if(insertAt < 0) {
+ // Append at the end
+ insertAt = lines.length;
+ }
+ // Generate a couple of SSRCs
+ ssrc[1] = Math.floor(Math.random()*0xFFFFFFFF);
+ ssrc[2] = Math.floor(Math.random()*0xFFFFFFFF);
+ // Add attributes to the SDP
+ for(var i=0; i<ssrc.length; i++) {
+ if(cname) {
+ lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' cname:' + cname);
+ insertAt++;
+ }
+ if(msid) {
+ lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' msid:' + msid);
+ insertAt++;
+ }
+ if(mslabel) {
+ lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' mslabel:' + msid);
+ insertAt++;
+ }
+ if(label) {
+ lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' label:' + msid);
+ insertAt++;
+ }
+ }
+ lines.splice(insertAt, 0, 'a=ssrc-group:SIM ' + ssrc[0] + ' ' + ssrc[1] + ' ' + ssrc[2]);
+ sdp = lines.join("\r\n");
+ if(!sdp.endsWith("\r\n"))
+ sdp += "\r\n";
+ return sdp;
+ }
+
// Helper methods to parse a media object
function isAudioSendEnabled(media) {
Janus.debug("isAudioSendEnabled:", media);
diff --git a/html/janus.nojquery.js b/html/janus.nojquery.js
index 23ba62e..5df54c6 100644
--- a/html/janus.nojquery.js
+++ b/html/janus.nojquery.js
@@ -1810,7 +1810,8 @@ function Janus(gatewayCallbacks) {
}
Janus.debug(mediaConstraints);
// Check if this is Firefox and we've been asked to do simulcasting
- if(simulcast && adapter.browserDetails.browser === "firefox") {
+ var sendVideo = isVideoSendEnabled(media);
+ if(sendVideo && simulcast && adapter.browserDetails.browser === "firefox") {
// FIXME Based on https://gist.github.com/voluntas/088bc3cc62094730647b
Janus.log("Enabling Simulcasting for Firefox (RID)");
var sender = config.pc.getSenders()[1];
@@ -1828,108 +1829,11 @@ function Janus(gatewayCallbacks) {
Janus.debug(offer);
if(config.mySdp === null || config.mySdp === undefined) {
Janus.log("Setting local description");
- if(simulcast) {
+ if(sendVideo && simulcast) {
// This SDP munging only works with Chrome
if(adapter.browserDetails.browser === "chrome") {
Janus.log("Enabling Simulcasting for Chrome (SDP munging)");
- // Let's munge the SDP to add the attributes for enabling simulcasting
- // (based on https://gist.github.com/ggarber/a19b4c33510028b9c657)
- var lines = offer.sdp.split("\r\n");
- var video = false;
- var ssrc = [ -1 ], ssrc_fid = -1;
- var cname = null, msid = null, mslabel = null, label = null;
- var insertAt = -1;
- for(var i=0; i<lines.length; i++) {
- var mline = lines[i].match(/m=(\w+) */);
- if(mline) {
- var medium = mline[1];
- if(medium === "video") {
- // New video m-line: make sure it's the first one
- if(ssrc[0] < 0) {
- video = true;
- } else {
- // We're done, let's add the new attributes here
- insertAt = i;
- break;
- }
- } else {
- // New non-video m-line: do we have what we were looking for?
- if(ssrc[0] > -1) {
- // We're done, let's add the new attributes here
- insertAt = i;
- break;
- }
- }
- continue;
- }
- var fid = lines[i].match(/a=ssrc-group:FID (\d+) (\d+)/);
- if(fid) {
- ssrc[0] = fid[1];
- ssrc_fid = fid[2];
- lines.splice(i, 1); i--;
- continue;
- }
- if(ssrc[0]) {
- var match = lines[i].match('a=ssrc:' + ssrc[0] + ' cname:(.+)')
- if(match) {
- cname = match[1];
- }
- match = lines[i].match('a=ssrc:' + ssrc[0] + ' msid:(.+)')
- if(match) {
- msid = match[1];
- }
- match = lines[i].match('a=ssrc:' + ssrc[0] + ' mslabel:(.+)')
- if(match) {
- mslabel = match[1];
- }
- match = lines[i].match('a=ssrc:' + ssrc + ' label:(.+)')
- if(match) {
- label = match[1];
- }
- if(lines[i].indexOf('a=ssrc:' + ssrc_fid) === 0) {
- lines.splice(i, 1); i--;
- continue;
- }
- if(lines[i].indexOf('a=ssrc:' + ssrc[0]) === 0) {
- lines.splice(i, 1); i--;
- continue;
- }
- }
- if(lines[i].length == 0) {
- lines.splice(i, 1); i--;
- continue;
- }
- }
- if(insertAt < 0) {
- // Append at the end
- insertAt = lines.length;
- }
- // Generate a couple of SSRCs
- ssrc[1] = Math.floor(Math.random()*0xFFFFFFFF);
- ssrc[2] = Math.floor(Math.random()*0xFFFFFFFF);
- // Add attributes to the SDP
- for(var i=0; i<ssrc.length; i++) {
- if(cname) {
- lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' cname:' + cname);
- insertAt++;
- }
- if(msid) {
- lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' msid:' + msid);
- insertAt++;
- }
- if(mslabel) {
- lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' mslabel:' + msid);
- insertAt++;
- }
- if(label) {
- lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' label:' + msid);
- insertAt++;
- }
- }
- lines.splice(insertAt, 0, 'a=ssrc-group:SIM ' + ssrc[0] + ' ' + ssrc[1] + ' ' + ssrc[2]);
- offer.sdp = lines.join("\r\n");
- if(!offer.sdp.endsWith("\r\n"))
- offer.sdp += "\r\n";
+ offer.sdp = mungeSdpForSimulcasting(offer.sdp);
} else if(adapter.browserDetails.browser !== "firefox") {
Janus.warn("simulcast=true, but this is not Chrome nor Firefox, ignoring");
}
@@ -1971,7 +1875,12 @@ function Janus(gatewayCallbacks) {
return;
}
var config = pluginHandle.webrtcStuff;
- Janus.log("Creating answer (iceDone=" + config.iceDone + ")");
+ var simulcast = callbacks.simulcast === true ? true : false;
+ if(!simulcast) {
+ Janus.log("Creating answer (iceDone=" + config.iceDone + ")");
+ } else {
+ Janus.log("Creating answer (iceDone=" + config.iceDone + ", simulcast=" + simulcast + ")");
+ }
var mediaConstraints = null;
if(adapter.browserDetails.browser == "firefox" || adapter.browserDetails.browser == "edge") {
mediaConstraints = {
@@ -1987,11 +1896,37 @@ function Janus(gatewayCallbacks) {
};
}
Janus.debug(mediaConstraints);
+ // Check if this is Firefox and we've been asked to do simulcasting
+ var sendVideo = isVideoSendEnabled(media);
+ if(sendVideo && simulcast && adapter.browserDetails.browser === "firefox") {
+ // FIXME Based on https://gist.github.com/voluntas/088bc3cc62094730647b
+ Janus.log("Enabling Simulcasting for Firefox (RID)");
+ var sender = config.pc.getSenders()[1];
+ Janus.log(sender);
+ var parameters = sender.getParameters();
+ Janus.log(parameters);
+ sender.setParameters({encodings: [
+ { rid: "high", active: true, priority: "high", maxBitrate: 1000000 },
+ { rid: "medium", active: true, priority: "medium", maxBitrate: 300000 },
+ { rid: "low", active: true, priority: "low", maxBitrate: 100000 }
+ ]});
+ }
config.pc.createAnswer(
function(answer) {
Janus.debug(answer);
if(config.mySdp === null || config.mySdp === undefined) {
Janus.log("Setting local description");
+ if(sendVideo && simulcast) {
+ // This SDP munging only works with Chrome
+ if(adapter.browserDetails.browser === "chrome") {
+ // FIXME Apparently trying to simulcast when answering breaks video in Chrome...
+ //~ Janus.log("Enabling Simulcasting for Chrome (SDP munging)");
+ //~ answer.sdp = mungeSdpForSimulcasting(answer.sdp);
+ Janus.warn("simulcast=true, but this is an answer, and video breaks in Chrome if we enable it");
+ } else if(adapter.browserDetails.browser !== "firefox") {
+ Janus.warn("simulcast=true, but this is not Chrome nor Firefox, ignoring");
+ }
+ }
config.mySdp = answer.sdp;
config.pc.setLocalDescription(answer);
}
@@ -2302,6 +2237,184 @@ function Janus(gatewayCallbacks) {
pluginHandle.oncleanup();
}
+ // Helper method to munge an SDP to enable simulcasting (Chrome only)
+ function mungeSdpForSimulcasting(sdp) {
+ // Let's munge the SDP to add the attributes for enabling simulcasting
+ // (based on https://gist.github.com/ggarber/a19b4c33510028b9c657)
+ var lines = sdp.split("\r\n");
+ var video = false;
+ var ssrc = [ -1 ], ssrc_fid = -1;
+ var cname = null, msid = null, mslabel = null, label = null;
+ var insertAt = -1;
+ for(var i=0; i<lines.length; i++) {
+ var mline = lines[i].match(/m=(\w+) */);
+ if(mline) {
+ var medium = mline[1];
+ if(medium === "video") {
+ // New video m-line: make sure it's the first one
+ if(ssrc[0] < 0) {
+ video = true;
+ } else {
+ // We're done, let's add the new attributes here
+ insertAt = i;
+ break;
+ }
+ } else {
+ // New non-video m-line: do we have what we were looking for?
+ if(ssrc[0] > -1) {
+ // We're done, let's add the new attributes here
+ insertAt = i;
+ break;
+ }
+ }
+ continue;
+ }
+ if(!video)
+ continue;
+ var fid = lines[i].match(/a=ssrc-group:FID (\d+) (\d+)/);
+ if(fid) {
+ ssrc[0] = fid[1];
+ ssrc_fid = fid[2];
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ if(ssrc[0]) {
+ var match = lines[i].match('a=ssrc:' + ssrc[0] + ' cname:(.+)')
+ if(match) {
+ cname = match[1];
+ }
+ match = lines[i].match('a=ssrc:' + ssrc[0] + ' msid:(.+)')
+ if(match) {
+ msid = match[1];
+ }
+ match = lines[i].match('a=ssrc:' + ssrc[0] + ' mslabel:(.+)')
+ if(match) {
+ mslabel = match[1];
+ }
+ match = lines[i].match('a=ssrc:' + ssrc + ' label:(.+)')
+ if(match) {
+ label = match[1];
+ }
+ if(lines[i].indexOf('a=ssrc:' + ssrc_fid) === 0) {
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ if(lines[i].indexOf('a=ssrc:' + ssrc[0]) === 0) {
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ }
+ if(lines[i].length == 0) {
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ }
+ if(ssrc[0] < 0) {
+ // Couldn't find a FID attribute, let's just take the first video SSRC we find
+ insertAt = -1;
+ video = false;
+ for(var i=0; i<lines.length; i++) {
+ var mline = lines[i].match(/m=(\w+) */);
+ if(mline) {
+ var medium = mline[1];
+ if(medium === "video") {
+ // New video m-line: make sure it's the first one
+ if(ssrc[0] < 0) {
+ video = true;
+ } else {
+ // We're done, let's add the new attributes here
+ insertAt = i;
+ break;
+ }
+ } else {
+ // New non-video m-line: do we have what we were looking for?
+ if(ssrc[0] > -1) {
+ // We're done, let's add the new attributes here
+ insertAt = i;
+ break;
+ }
+ }
+ continue;
+ }
+ if(!video)
+ continue;
+ if(ssrc[0] < 0) {
+ var value = lines[i].match(/a=ssrc:(\d+)/);
+ if(value) {
+ ssrc[0] = value[1];
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ } else {
+ var match = lines[i].match('a=ssrc:' + ssrc[0] + ' cname:(.+)')
+ if(match) {
+ cname = match[1];
+ }
+ match = lines[i].match('a=ssrc:' + ssrc[0] + ' msid:(.+)')
+ if(match) {
+ msid = match[1];
+ }
+ match = lines[i].match('a=ssrc:' + ssrc[0] + ' mslabel:(.+)')
+ if(match) {
+ mslabel = match[1];
+ }
+ match = lines[i].match('a=ssrc:' + ssrc + ' label:(.+)')
+ if(match) {
+ label = match[1];
+ }
+ if(lines[i].indexOf('a=ssrc:' + ssrc_fid) === 0) {
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ if(lines[i].indexOf('a=ssrc:' + ssrc[0]) === 0) {
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ }
+ if(lines[i].length == 0) {
+ lines.splice(i, 1); i--;
+ continue;
+ }
+ }
+ }
+ if(ssrc[0] < 0) {
+ // Still nothing, let's just return the SDP we were asked to munge
+ Janus.warn("Couldn't find the video SSRC, simulcasting NOT enabled");
+ return sdp;
+ }
+ if(insertAt < 0) {
+ // Append at the end
+ insertAt = lines.length;
+ }
+ // Generate a couple of SSRCs
+ ssrc[1] = Math.floor(Math.random()*0xFFFFFFFF);
+ ssrc[2] = Math.floor(Math.random()*0xFFFFFFFF);
+ // Add attributes to the SDP
+ for(var i=0; i<ssrc.length; i++) {
+ if(cname) {
+ lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' cname:' + cname);
+ insertAt++;
+ }
+ if(msid) {
+ lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' msid:' + msid);
+ insertAt++;
+ }
+ if(mslabel) {
+ lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' mslabel:' + msid);
+ insertAt++;
+ }
+ if(label) {
+ lines.splice(insertAt, 0, 'a=ssrc:' + ssrc[i] + ' label:' + msid);
+ insertAt++;
+ }
+ }
+ lines.splice(insertAt, 0, 'a=ssrc-group:SIM ' + ssrc[0] + ' ' + ssrc[1] + ' ' + ssrc[2]);
+ sdp = lines.join("\r\n");
+ if(!sdp.endsWith("\r\n"))
+ sdp += "\r\n";
+ return sdp;
+ }
+
// Helper methods to parse a media object
function isAudioSendEnabled(media) {
Janus.debug("isAudioSendEnabled:", media);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/janus.git
More information about the Pkg-voip-commits
mailing list