gpt4 book ai didi

ios - 在 iOS 的 webrtc 上启用立体声

转载 作者:搜寻专家 更新时间:2023-10-31 19:38:23 26 4
gpt4 key购买 nike

我在 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 完全是一个黑客,但我稍后会谈到)

最佳答案

您可以在通知中心捕获事件,然后切换它。

     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 - 在 iOS 的 webrtc 上启用立体声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35281569/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com