如何在 swift 中将麦克风和应用内音频 CMSampleBuffer 发送到 webRTC?



我正在研究屏幕上的广播应用程序。我想在WebRTC服务器上发送我的屏幕录像。

override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) {
//if source!.isSocketConnected {
switch sampleBufferType {
case RPSampleBufferType.video:
// Handle video sample buffer
source?.processVideoSampleBuffer(sampleBuffer)
break
case RPSampleBufferType.audioApp:
// Handle audio sample buffer for app audio
source?.processInAppAudioSampleBuffer(sampleBuffer)
break
case RPSampleBufferType.audioMic:
// Handle audio sample buffer for mic audio
source?.processAudioSampleBuffer(sampleBuffer)
break
@unknown default:
break
}
}

// VideoBuffer Sending Method
func startCaptureLocalVideo(sampleBuffer: CMSampleBuffer) {
let _pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
if let pixelBuffer = _pixelBuffer {
let rtcPixelBuffer = RTCCVPixelBuffer(pixelBuffer: pixelBuffer)
let timeStampNs = CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) * 1000000000
let rtcVideoFrame = RTCVideoFrame(buffer: rtcPixelBuffer, rotation: RTCVideoRotation._90, timeStampNs: Int64(timeStampNs))
localVideoSource!.capturer(videoCapturer!, didCapture: rtcVideoFrame)
}
}

我成功地在WebRTC上发送了视频样本缓冲区,但我被困在音频部分。

我没有找到任何如何将音频缓冲区发送到WebRTC的方法。

非常感谢您的回答。

我找到了解决方案,只需访问此链接并遵循指南: https://github.com/pixiv/webrtc/blob/branch-heads/pixiv-m78/README.pixiv.md

WebRTC团队不再支持原生框架,所以我们需要修改WebRTC源代码并重新构建它以在另一个应用程序中使用。

幸运的是,我找到了从WebRTC项目中分叉源代码的人,他更新了将CMSampleBuffer从广播扩展传递到RTCPeerConnection的函数。

最新更新