简体   繁体   English

如何在WebRTC音频通话中控制单声道/立体声?

[英]How to control mono/stereo in WebRTC audio call?

I'm trying to force my audio calls to mono-only, I'm willing to use PCMU, G.729, OPUS and SpeeX as my codecs for this calls. 我试图将音频呼叫强制为单声道,我愿意使用PCMU,G.729,OPUS和SpeeX作为此呼叫的编解码器。

Right now I'm using the following code to search for the chosen codec in my sdp message: 现在,我正在使用以下代码在我的sdp消息中搜索所选的编解码器:

function maybePreferCodec(sdp, type, dir, codec) {
    var str = type + ' ' + dir + ' codec';
    if (codec === '') {
        return sdp;
    }

    var sdpLines = sdp.split('\r\n');

     // Search for m line.
    var mLineIndex = findLine(sdpLines, 'm=', type);
    if (mLineIndex === null) {
        return sdp;
    }

    // If the codec is available, set it as the default in m line.
    var codecIndex = findLine(sdpLines, 'a=rtpmap', codec);
    console.log('codecIndex', codecIndex);
    if (codecIndex) {
        var payload = getCodecPayloadType(sdpLines[codecIndex]);
        if (payload) {
             sdpLines[mLineIndex] = setDefaultCodec(sdpLines[mLineIndex],       payload);
        }
    }

    sdp = sdpLines.join('\r\n');
    return sdp;
}

The other functions can be found here: 其他功能可以在这里找到:

http://www.codeforge.com/read/252733/sdputils.js__html http://www.codeforge.com/read/252733/sdputils.js__html

There are many other functions on the link but I don't know if they'll properly work on my selected codecs. 链接上还有许多其他功能,但我不知道它们是否可以在我选择的编解码器上正常工作。

Thanks in advance! 提前致谢!

For audio, the format of "a=rtpmap" lines is: 对于音频,“ a = rtpmap”行的格式为:

a=rtpmap:<payload type> <encoding name>/<clock rate>[/<number of channels>]

For example: 例如:

a=rtpmap:111 opus/48000/2

So, you can scan for those lines, and remove any codec with 2 channels. 因此,您可以扫描这些行,并删除具有2个通道的所有编解码器。 Note that to remove a codec, you'll also need to remove the payload type (in this case, 111) from the "m=" line, and remove "a=fmtp" lines for it. 请注意,要删除编解码器,您还需要从“ m =”行中删除有效负载类型(在本例中为111),并为其删除“ a = fmtp”行。 I believe sdputils.js has code to do this sort of thing. 我相信sdputils.js具有执行此类操作的代码。

Opus is a bit of a special case though, because it always appears as having 2 channels, which allows it to switch between mono and stereo in-band without doing a new offer/answer. 但是Opus有点特殊,因为它总是显示为具有2个通道,这使它可以在单声道和立体声带内之间切换,而无需进行新的报价/回答。 So with Opus, stereo vs. mono preference is indicated by a "stereo" parameter which is set to 0 or 1: 因此,对于Opus,立体声和单声道首选项由设置为0或1的“立体声”参数表示

a=fmtp:111 stereo=0

You can use https://github.com/beradrian/sdpparser and then modify the entire SDP payload as a JSON object. 您可以使用https://github.com/beradrian/sdpparser ,然后将整个SDP有效内容修改为JSON对象。 Disclaimer: I'm the author of sdpparser. 免责声明:我是sdpparser的作者。

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

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