swift - 如何快速将麦克风和 InApp Audio 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 上发送 VIDEO Sample Buffer,但我陷入了 AUDIO 部分。
我没有找到如何将音频缓冲区发送到 WebRTC 的任何方法。
非常感谢您的回答。
解决方案
我找到了解决方案,只需访问此链接并遵循指南: https ://github.com/pixiv/webrtc/blob/branch-heads/pixiv-m78/README.pixiv.md
WebRTC 团队不再支持原生框架,因此我们需要修改 WebRTC 源代码并重新构建它以在另一个应用程序中使用。
幸运的是,我找到了从 WebRTC 项目派生源代码的人,他更新了将 CMSampleBuffer 从广播扩展传递到 RTCPeerConnection 的函数。
推荐阅读
- python-3.x - 尝试使用 kaggle API 时出现“-bash: command not found”
- c# - 如何从 ContentDisposition 获取扩展
- javascript - 将函数限制为仅使用“new”运算符调用
- node.js - 共享会话 Socket.io Express
- vba - 宏按钮在 Excel 中添加行(带有下面行中的公式),同时保持标题
- arrays - 在已知片段中拆分数组
- c++ - UWP:在 TreeNode 中将文本设置为粗体
- vba - 发现重复值时,VBA 计数并打印每个单元格地址
- awk - 如何增加文本文件中的时间戳
- ios - 避免与 clang-formatter 混合使用意图?