0

我从广播上传扩展接收 cmsamplebuffer,我需要将它发送到主应用程序,以便它可以通过 webrtc 发送。Webrtc 严格需要在主应用程序中。为了将 cmsamplebuffer 发送到主应用程序,我需要先将其转换为 Data,然后在主应用程序中收到后将其转换回 cmsamplebuffer。这是我将其转换为数据的代码:

let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
CVPixelBufferLockBaseAddress(imageBuffer!, CVPixelBufferLockFlags(rawValue: 0))
let bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer!)
let height = CVPixelBufferGetHeight(imageBuffer!)
let src_buff = CVPixelBufferGetBaseAddress(imageBuffer!)
let data = NSData(bytes: src_buff, length: bytesPerRow * height)
CVPixelBufferUnlockBaseAddress(imageBuffer, CVPixelBufferLockFlags(rawValue: 0))

现在,我找不到如何将数据转换回 cmsamplebuffer。

4

0 回答 0