perf: Avoid expensive CMSampleBuffer copy (#235)

* Don't copy CMSampleBuffer

* Update CameraView+RecordVideo.swift

* Update Podfile.lock
This commit is contained in:
Marc Rousavy
2021-07-06 09:25:11 +02:00
committed by GitHub
parent cd7235c7a2
commit 7d3b352155
2 changed files with 8 additions and 18 deletions

View File

@@ -215,23 +215,13 @@ extension CameraView: AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureAud
if diff > UInt64(nanosecondsPerFrame) {
if !isRunningFrameProcessor {
// we're not in the middle of executing the Frame Processor, so prepare for next call.
var bufferCopy: CMSampleBuffer?
CMSampleBufferCreateCopy(allocator: kCFAllocatorDefault,
sampleBuffer: sampleBuffer,
sampleBufferOut: &bufferCopy)
if let bufferCopy = bufferCopy {
// successfully copied buffer, dispatch frame processor call.
CameraQueues.frameProcessorQueue.async {
self.isRunningFrameProcessor = true
let frame = Frame(buffer: bufferCopy, orientation: self.bufferOrientation)
frameProcessor(frame)
self.isRunningFrameProcessor = false
}
lastFrameProcessorCall = DispatchTime.now()
} else {
// failed to create a buffer copy.
ReactLogger.log(level: .error, message: "Failed to copy buffer! Frame Processor cannot be called.", alsoLogToJS: true)
CameraQueues.frameProcessorQueue.async {
self.isRunningFrameProcessor = true
let frame = Frame(buffer: sampleBuffer, orientation: self.bufferOrientation)
frameProcessor(frame)
self.isRunningFrameProcessor = false
}
lastFrameProcessorCall = DispatchTime.now()
} else {
// we're still in the middle of executing a Frame Processor for a previous frame, notify user about dropped frame.
if !hasLoggedFrameProcessorFrameDropWarning {