我一直试图通过WebRTC传输一些高质量的音频流。操作系统,主要广告的编解码器似乎是完美的,因为它可以支持高达510 main /s,远远超过需要。问题是,建立Webrtc并不像看起来那么明显。多亏了Muaz Khan的伟大工作,我才能强迫它达到128 that/s。
function setBandwidth(sdp) {
var sdpLines = sdp.split('\r\n');
// Find opus payload.
var opusIndex = findLine(sdpLines, 'a=rtpmap', 'opus/48000');
var opusPayload;
if (opusIndex) {
opusPayload = '109';
}
sdpLines[opusIndex]='a=rtpmap:'+opusPayload+' opus/48000/2';
var mediaIndex = findLine(sdpLines, 'm=audio');
sdpLines[mediaIndex]=(sdpLines[mediaIndex].slice(0,(sdpLines[mediaIndex].indexOf("RTP/SAVPF")+10))).concat(opusPayload);
var abIndex = findLine(sdpLines, 'a=mid:');
sdpLines[abIndex]='a=mid:audio\r\nb=AS:300000';
// Find the payload in fmtp line.
var fmtpLineIndex = findLine(sdpLines, 'a=fmtp:' + opusPayload.toString());
if (fmtpLineIndex == null) {
sdpLines[opusIndex] = sdpLines[opusIndex].concat('\r\n'+'a=fmtp:' + opusPayload.toString()+ ' minptime=10; useinbandfec=1; maxaveragebitrate='+128*1024+'; stereo=1; sprop-stereo=1 ; cbr=1');
sdp = sdpLines.join('\r\n');
return sdp;
}
// Append stereo=1 to fmtp line.
// added maxaveragebitrate here; about 50 kbits/s
// added stereo=1 here for stereo audio
// x-google-min-bitrate=50; x-google-max-bitrate=50
sdpLines[fmtpLineIndex] = sdpLines[fmtpLineIndex].concat('; maxaveragebitrate='+128*1024+'; stereo=1; sprop-stereo=1 ; cbr=1');
sdp = sdpLines.join('\r\n');
return sdp;
}
所以现在一切都设置好了,firefox和chrome都为发送者和接收者显示了正确的值,通信打开了,音乐播放了!
adding answer-sdp v=0
o=mozilla...THIS_IS_SDPARTA-42.0 502631676322875352 0 IN IP4 0.0.0.0
s=-
t=0 0
a=fingerprint:sha-256.....
a=ice-options:trickle
a=msid-semantic:WMS *
m=audio 9 RTP/SAVPF 109
c=IN IP4 0.0.0.0
a=recvonly
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=ice-pwd:c56d106030599efe08cfa2a4f9b3ad5a
a=ice-ufrag:93982a76
a=mid:audio
b=AS:300000
a=rtcp-mux
a=rtpmap:109 opus/48000/2
a=fmtp:109 minptime=10; useinbandfec=1; maxaveragebitrate=131072; stereo=1; sprop-stereo=1 ; cbr=1
a=setup:active
a=ssrc:1948755120 cname:{208483df-13c9-e347-ba4a-c71604df3ad9}
但质量太差了。铬显示约30kbit/s的铬://webrtc-内部/和声音是严重扭曲的可变体积.在这个问题上有什么线索吗?
发布于 2015-11-11 13:40:04
我创建了一个SDP解析器。输入SDP描述,获取一个JSON对象,然后再次序列化它。
这样,将SDP作为对象处理要比作为大容量文本处理容易得多。
发布于 2019-01-09 20:22:03
造成质量不佳的主要原因是浏览器的音频处理。您需要将音频约束传递给GetUserMedia对象:
{‘信道计数’:{‘精确’:2},‘回声星座’:假,‘自动控制’:假,‘噪音抑制’:假}
发布于 2019-11-17 07:06:40
您需要在SDP上设置stereo
和maxaveragebitrate
姿态:
let answer = await peer.conn.createAnswer(offerOptions);
answer.sdp = answer.sdp.replace('useinbandfec=1', 'useinbandfec=1; stereo=1; maxaveragebitrate=510000');
await peer.conn.setLocalDescription(answer);
这将输出如下所示的字符串:
a=fmtp:111 minptime=10;useinbandfec=1; stereo=1; maxaveragebitrate=510000
这给了我520 me /s的比特率立体声,这是260 per每通道。实际的比特率将根据网络的速度和信号的强度而变化。
有更多的SDP属性记录在:https://www.rfc-editor.org/rfc/rfc7587中。
https://stackoverflow.com/questions/33649283
复制相似问题