简体   繁体   English

如何在webrtc sdp中删除视频编解码器?

[英]How to remove video codecs in webrtc sdp?

I would like to know how I can remove H264 codec from SDP offer. 我想知道如何从SDP产品中删除H264编解码器。 Or maybe I can disable this codec somehow? 或者也许我可以以某种方式禁用此编解码器? I found one quite nice solution but I receive error. 我找到了一个很好的解决方案,但收到错误消息。 Error appears on line 错误出现在网上

var modsdp = sdp.replace(codecre, "");​

Uncaught SyntaxError: Invalid or unexpected token 未捕获的SyntaxError:无效或意外的令牌

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);}

Thank you for any help. 感谢您的任何帮助。

Answer that I received here https://groups.google.com/forum/#!topic/discuss-webrtc/4lNUw9CkhIc works fine. 我在这里https://groups.google.com/forum/#!topic/discuss-webrtc/4lNUw9CkhIc收到的答案可以正常工作。 Just needed to rewrite few lines of code( that commented out). 只需重写几行代码(已注释掉)。 They looks the same. 他们看起来一样。 But commented out lines causes syntax error. 但是注释掉的行会导致语法错误。 I guess they written in language different from English. 我想他们用不同于英语的语言写的。 Rewriting them on English keyboard solves problem 用英文键盘重写它们可以解决问题

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);

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM