我在这篇博文中借用了一些想法,希望我可以让它发挥作用.我们能够为我们的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",RTCPair(key: "googEchoCancellation",value: "false") ] let optionalConstraints = [ RTCPair(key: "internalSctpDataChannels",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是一个彻头彻尾的黑客,但我稍后会谈到)
解决方法 您可以在通知中心捕获事件,然后进行切换.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 } }总结
以上是内存溢出为你收集整理的在webrtc上为iOS启用立体声全部内容,希望文章能够帮你解决在webrtc上为iOS启用立体声所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)