在 iOS 上使用 RTCAudioSource 捕获 CMSampleBuffer

问题描述

我正在尝试在 iOS 上使用 WebRTC 流式传输 CMSampleBuffer 视频/音频组合,但在尝试捕获音频时遇到了麻烦。视频效果很好:

guard let pixelBuffer = CMSampleBufferGetimageBuffer(sampleBuffer) else {
    print("Couldn't get image from buffer :~(")
    
    return
}
        
let rtcPixelBuffer = RTCCVPixelBuffer(pixelBuffer: pixelBuffer)
let rtcVideoFrame = RTCVideoFrame(buffer: rtcPixelBuffer,rotation: ._0,timeStampNs: timeStampNs)

videoSource.capturer(videoCapturer,didCapture: rtcVideoFrame)

说到音频,我在 RTCAudioSource 类上看不到任何方法来捕获音频,任何帮助将不胜感激!

解决方法

我发现了 WebRTC 代码库的一个分支,它通过添加一种由 RTCAudioDeviceModule 捕获音频样本的方法来解决这个问题:

https://github.com/pixiv/webrtc/blob/87.0.4280.142-pixiv0/README.pixiv.en.md