如何删除 webrtc sdp 中的视频编解码器?
How to remove video codecs in webrtc sdp?
我想知道如何从 SDP 报价中删除 H264 编解码器。或者我可以以某种方式禁用此编解码器?我找到了一个非常好的解决方案,但我收到错误。行
出现错误
var modsdp = sdp.replace(codecre, "");
Uncaught SyntaxError: Invalid or unexpected token
function removeCodec(orgsdp, codec) {
var internalFunc = function(sdp) {
var codecre = new RegExp('(a=rtpmap:(\d*) ' + codec + '\/90000\r\n)');
var rtpmaps = sdp.match(codecre);
if (rtpmaps == null || rtpmaps.length <= 2) {
return sdp;
}
var rtpmap = rtpmaps[2];
var modsdp = sdp.replace(codecre, "");
var rtcpre = new RegExp('(a=rtcp-fb:' + rtpmap + '.*\r\n)', 'g');
modsdp = modsdp.replace(rtcpre, "");
var fmtpre = new RegExp('(a=fmtp:' + rtpmap + '.*\r\n)', 'g');
modsdp = modsdp.replace(fmtpre, "");
var aptpre = new RegExp('(a=fmtp:(\d*) apt=' + rtpmap + '\r\n)');
var aptmaps = modsdp.match(aptpre);
var fmtpmap = "";
if (aptmaps != null && aptmaps.length >= 3) {
fmtpmap = aptmaps[2];
modsdp = modsdp.replace(aptpre, "");
var rtppre = new RegExp('(a=rtpmap:' + fmtpmap + '.*\r\n)', 'g');
modsdp = modsdp.replace(rtppre, "");
}
var videore = /(m=video.*\r\n)/;
var videolines = modsdp.match(videore);
if (videolines != null) {
//If many m=video are found in SDP, this program doesn't work.
var videoline = videolines[0].substring(0, videolines[0].length - 2);
var videoelem = videoline.split(" ");
var modvideoline = videoelem[0];
for (var i = 1; i < videoelem.length; i++) {
if (videoelem[i] == rtpmap || videoelem[i] == fmtpmap) {
continue;
}
modvideoline += " " + videoelem[i];
}
modvideoline += "\r\n";
modsdp = modsdp.replace(videore, modvideoline);
}
return internalFunc(modsdp);
};
return internalFunc(orgsdp);}
感谢您的帮助。
我在此处收到的答案 https://groups.google.com/forum/#!topic/discuss-webrtc/4lNUw9CkhIc 工作正常。只需要重写几行代码(已注释掉)。他们看起来一样。但是注释掉的行会导致语法错误。我猜他们是用不同于英语的语言写的。在英文键盘上重写它们解决了问题
function removeCodec(orgsdp, codec) {
var internalFunc = function(sdp) {
var codecre = new RegExp('(a=rtpmap:(\d*) ' + codec + '\/90000\r\n)');
var rtpmaps = sdp.match(codecre);
if (rtpmaps == null || rtpmaps.length <= 2) {
return sdp;
}
var rtpmap = rtpmaps[2];
// var modsdp = sdp.replace(codecre, "");
var modsdp = sdp.replace(codecre, "");
var rtcpre = new RegExp('(a=rtcp-fb:' + rtpmap + '.*\r\n)', 'g');
// modsdp = modsdp.replace(rtcpre, "");
modsdp = modsdp.replace(rtcpre, "");
var fmtpre = new RegExp('(a=fmtp:' + rtpmap + '.*\r\n)', 'g');
// modsdp = modsdp.replace(fmtpre, "");
modsdp = modsdp.replace(fmtpre, "");
var aptpre = new RegExp('(a=fmtp:(\d*) apt=' + rtpmap + '\r\n)');
var aptmaps = modsdp.match(aptpre);
var fmtpmap = "";
if (aptmaps != null && aptmaps.length >= 3) {
fmtpmap = aptmaps[2];
// modsdp = modsdp.replace(aptpre, "");
modsdp = modsdp.replace(aptpre, "");
var rtppre = new RegExp('(a=rtpmap:' + fmtpmap + '.*\r\n)', 'g');
modsdp = modsdp.replace(rtppre, "");
}
var videore = /(m=video.*\r\n)/;
var videolines = modsdp.match(videore);
if (videolines != null) {
//If many m=video are found in SDP, this program doesn't work.
var videoline = videolines[0].substring(0, videolines[0].length - 2);
var videoelem = videoline.split(" ");
var modvideoline = videoelem[0];
for (var i = 1; i < videoelem.length; i++) {
if (videoelem[i] == rtpmap || videoelem[i] == fmtpmap) {
continue;
}
modvideoline += " " + videoelem[i];
}
modvideoline += "\r\n";
modsdp = modsdp.replace(videore, modvideoline);
}
return internalFunc(modsdp);
};
return internalFunc(orgsdp);
}
我想知道如何从 SDP 报价中删除 H264 编解码器。或者我可以以某种方式禁用此编解码器?我找到了一个非常好的解决方案,但我收到错误。行
出现错误var modsdp = sdp.replace(codecre, "");
Uncaught SyntaxError: Invalid or unexpected token
function removeCodec(orgsdp, codec) {
var internalFunc = function(sdp) {
var codecre = new RegExp('(a=rtpmap:(\d*) ' + codec + '\/90000\r\n)');
var rtpmaps = sdp.match(codecre);
if (rtpmaps == null || rtpmaps.length <= 2) {
return sdp;
}
var rtpmap = rtpmaps[2];
var modsdp = sdp.replace(codecre, "");
var rtcpre = new RegExp('(a=rtcp-fb:' + rtpmap + '.*\r\n)', 'g');
modsdp = modsdp.replace(rtcpre, "");
var fmtpre = new RegExp('(a=fmtp:' + rtpmap + '.*\r\n)', 'g');
modsdp = modsdp.replace(fmtpre, "");
var aptpre = new RegExp('(a=fmtp:(\d*) apt=' + rtpmap + '\r\n)');
var aptmaps = modsdp.match(aptpre);
var fmtpmap = "";
if (aptmaps != null && aptmaps.length >= 3) {
fmtpmap = aptmaps[2];
modsdp = modsdp.replace(aptpre, "");
var rtppre = new RegExp('(a=rtpmap:' + fmtpmap + '.*\r\n)', 'g');
modsdp = modsdp.replace(rtppre, "");
}
var videore = /(m=video.*\r\n)/;
var videolines = modsdp.match(videore);
if (videolines != null) {
//If many m=video are found in SDP, this program doesn't work.
var videoline = videolines[0].substring(0, videolines[0].length - 2);
var videoelem = videoline.split(" ");
var modvideoline = videoelem[0];
for (var i = 1; i < videoelem.length; i++) {
if (videoelem[i] == rtpmap || videoelem[i] == fmtpmap) {
continue;
}
modvideoline += " " + videoelem[i];
}
modvideoline += "\r\n";
modsdp = modsdp.replace(videore, modvideoline);
}
return internalFunc(modsdp);
};
return internalFunc(orgsdp);}
感谢您的帮助。
我在此处收到的答案 https://groups.google.com/forum/#!topic/discuss-webrtc/4lNUw9CkhIc 工作正常。只需要重写几行代码(已注释掉)。他们看起来一样。但是注释掉的行会导致语法错误。我猜他们是用不同于英语的语言写的。在英文键盘上重写它们解决了问题
function removeCodec(orgsdp, codec) {
var internalFunc = function(sdp) {
var codecre = new RegExp('(a=rtpmap:(\d*) ' + codec + '\/90000\r\n)');
var rtpmaps = sdp.match(codecre);
if (rtpmaps == null || rtpmaps.length <= 2) {
return sdp;
}
var rtpmap = rtpmaps[2];
// var modsdp = sdp.replace(codecre, "");
var modsdp = sdp.replace(codecre, "");
var rtcpre = new RegExp('(a=rtcp-fb:' + rtpmap + '.*\r\n)', 'g');
// modsdp = modsdp.replace(rtcpre, "");
modsdp = modsdp.replace(rtcpre, "");
var fmtpre = new RegExp('(a=fmtp:' + rtpmap + '.*\r\n)', 'g');
// modsdp = modsdp.replace(fmtpre, "");
modsdp = modsdp.replace(fmtpre, "");
var aptpre = new RegExp('(a=fmtp:(\d*) apt=' + rtpmap + '\r\n)');
var aptmaps = modsdp.match(aptpre);
var fmtpmap = "";
if (aptmaps != null && aptmaps.length >= 3) {
fmtpmap = aptmaps[2];
// modsdp = modsdp.replace(aptpre, "");
modsdp = modsdp.replace(aptpre, "");
var rtppre = new RegExp('(a=rtpmap:' + fmtpmap + '.*\r\n)', 'g');
modsdp = modsdp.replace(rtppre, "");
}
var videore = /(m=video.*\r\n)/;
var videolines = modsdp.match(videore);
if (videolines != null) {
//If many m=video are found in SDP, this program doesn't work.
var videoline = videolines[0].substring(0, videolines[0].length - 2);
var videoelem = videoline.split(" ");
var modvideoline = videoelem[0];
for (var i = 1; i < videoelem.length; i++) {
if (videoelem[i] == rtpmap || videoelem[i] == fmtpmap) {
continue;
}
modvideoline += " " + videoelem[i];
}
modvideoline += "\r\n";
modsdp = modsdp.replace(videore, modvideoline);
}
return internalFunc(modsdp);
};
return internalFunc(orgsdp);
}