我在 iOS 上使用 Opus 编解码器进行 webrtc 音频流 (libjingle_peerconnection)。如何为音频播放启用立体声?
我从这里的这篇博文中借鉴了一些想法,希望我可以让它发挥作用。我们能够为我们的 Web 客户端启用立体声,但不能为我们的 iOS 客户端启用立体声。
https://www.webrtcexample.com/blog/?go=all/how-to-support-stereo-in-a-webrtc-application/
我在优惠和对等连接约束的约束中禁用回声消除,如下所示:
private func initializeConstraints() -> RTCMediaConstraints {
let mandatoryConstraints = [
RTCPair(key: "OfferToReceiveAudio", value: "true"),
RTCPair(key: "OfferToReceiveVideo", value: "false"),
RTCPair(key: "echoCancellation", value: "false"),
RTCPair(key: "googEchoCancellation", value: "false")
]
let optionalConstraints = [
RTCPair(key: "internalSctpDataChannels", value: "true"),
RTCPair(key: "DtlsSrtpKeyAgreement", value: "true")
]
return RTCMediaConstraints(mandatoryConstraints: mandatoryConstraints, optionalConstraints: optionalConstraints)
}
我正在为 Opus 音频编解码器启用立体声,如下所示:
func peerConnection(peerConnection: RTCPeerConnection!, didCreateSessionDescription sdp: RTCSessionDescription!, error: NSError?) {
LOGD("created sdp")
guard error == nil else {
LOGE("error creating session description: \(error!)")
delegate.onError(self, description: "Error creating sdp")
return
}
dispatch_async(dispatch_get_main_queue()) {
let replaceThis = "fmtp:111 minptime=10; useinbandfec=1"
let replaceWith = "fmtp:111 minptime=10; useinbandfec=1; stereo=1; sprop-stereo=1"
let sdpDescriptionWithStereo = sdp.description.stringByReplacingOccurrencesOfString(replaceThis, withString: replaceWith)
let sdpWithStereo = RTCSessionDescription(type: sdp.type, sdp: sdpDescriptionWithStereo)
peerConnection.setLocalDescriptionWithDelegate(self, sessionDescription: sdpWithStereo)
self.delegate.onLocalSDP(self, type: sdp.type, sdp: sdpDescriptionWithStereo)
}
}
我得到了想要的结果sdpDescriptionWithStereo
。但我仍然无法让立体声工作。
(而且,是的,我知道 stringByReplacingOccurrencesOfString 完全是 hack,但我稍后会谈到)