iOS で webrtc オーディオ ストリーミング (libjingle_peerconnection) に Opus コーデックを使用しています。オーディオ再生用にステレオ サウンドを有効にするにはどうすればよいですか?
このブログ投稿 here からいくつかのアイデアを借りて、それが機能することを願っています。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
。しかし、まだステレオサウンドを機能させることはできません。
(そして、はい、 stringByReplaceingOccurrencesOfString が完全なハックであることは承知していますが、後で説明します)