1

I'm receiving the cmsamplebuffer from broadcast upload extension and I need to send it to the main app so that it can be sent via webrtc. Webrtc strictly needs to be in the main app. In order to send the cmsamplebuffer to the main app, I need to convert it to Data first and then convert it back to cmsamplebuffer once received in the main app. This is my code to convert it to data:

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))

Now, I can't find how can I convert the data back to cmsamplebuffer.

FH-
  • 133
  • 1
  • 9

0 Answers0