在webrtc for iOS上启用立体声
我在iOS上使用Opus编解码器进行webrtc音频流(libjingle_peerconnection)。如何为音频播放启用立体声 我从这篇博文中借用了一些想法,希望能让它发挥作用。我们能够为web客户端启用立体声,但无法为iOS客户端启用立体声 我正在禁用报价约束和对等连接约束中的回音取消,如下所示:在webrtc for iOS上启用立体声,ios,swift,webrtc,libjingle,Ios,Swift,Webrtc,Libjingle,我在iOS上使用Opus编解码器进行webrtc音频流(libjingle_peerconnection)。如何为音频播放启用立体声 我从这篇博文中借用了一些想法,希望能让它发挥作用。我们能够为web客户端启用立体声,但无法为iOS客户端启用立体声 我正在禁用报价约束和对等连接约束中的回音取消,如下所示: private func initializeConstraints() -> RTCMediaConstraints { let mandatoryConstraints =
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)
}
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)
}
}
我正在为Opus音频编解码器启用立体声,如下所示:
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)
}
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)
}
}
我在sdpddescriptionwithstereo
中获得了所需的结果。但我还是不能让立体声工作
(是的,我知道stringByReplacingOccurrencesOfString是一个完全的黑客行为,但我稍后会讨论这个问题)您可以在通知中心捕获事件,然后切换它
NotificationCenter.default.addObserver(self, selector: #selector(JanusCommunicationManager.didSessionRouteChange), name: NSNotification.Name.AVAudioSessionRouteChange, object: nil)
@objc func didSessionRouteChange(notification:Notification) {
let dict = notification.userInfo
let routeChangeReason = dict![AVAudioSessionRouteChangeReasonKey] as! UInt
let error:Error? = nil
switch routeChangeReason {
case AVAudioSessionRouteChangeReason.categoryChange.rawValue:
try? AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
break
default:
break
}
}
找到解决方案了吗?如何在ios中解决回声停止问题webrtc@AvinashVaghasiya我从未找到解决办法。但我认为我们得出的结论是,iOS不支持WebRTC立体声。