在Mozilla Firefox中调整Opus比特率-WebRTC

问题描述

我刚刚从以下链接中阅读了一篇文章https://developer.mozilla.org/en-US/docs/Web/Media/Formats/WebRTC_codecs

我想知道是否有办法手动或以编程方式将认的48 kbps调整为8 kbps?我目前正在使用WebRTC,并且需要在我的网络电话中使用窄带(NB)。

enter image description here

另一篇文章https://hacks.mozilla.org/2012/07/firefox-beta-15-supports-the-new-opus-audio-format/

enter image description here

解决方法

一旦从浏览器的报价中获得了SDP, 将该SDP传递给以下函数,它将返回修改后的SDP,其中设置了所需的音频比特率:

function onCreateOfferSuccess(desc){ desc.sdp = setAudioBitrate(desc.sdp,8,真); }

function setAudioBitrate(sdp,bitrate,isFirefox) {
var modifier = "b=AS:";
if (isFirefox) {
    bitrate = (bitrate >>> 0) * 1000;
    modifier = "b=TIAS:";
}

var lines = sdp.split("\r\n");
var line = -1;
for (var i = 0; i < lines.length; i++) {
    if (lines[i].indexOf("m=audio") === 0) {
        line = i;
        break;
    }
}

if (line === -1)
    return sdp;

// Pass the m line
line++;

// Skip i and c lines
while (lines[line].indexOf("i=") === 0 || lines[line].indexOf("c=") === 0)
    line++;

// If we are on a b line,replace it
if (lines[line].indexOf("b") === 0) {
    lines[line] = modifier + bitrate;
    return lines.join("\r\n");
}

// Add a new b line
var newLines = lines.slice(0,line);
newLines.push(modifier + bitrate);
newLines = newLines.concat(lines.slice(line,lines.length));
return newLines.join("\r\n");
}