iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在webrtc上为iOS启用立体声大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在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",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启用立体声所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。