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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 18 deletions

View File

@ -322,7 +322,7 @@ PODS:
- React
- RNVectorIcons (8.1.0):
- React-Core
- VisionCamera (2.4.2-beta.3):
- VisionCamera (2.4.2-beta.7):
- React
- React-callinvoker
- React-Core
@ -490,7 +490,7 @@ SPEC CHECKSUMS:
RNReanimated: 9c13c86454bfd54dab7505c1a054470bfecd2563
RNStaticSafeAreaInsets: 6103cf09647fa427186d30f67b0f5163c1ae8252
RNVectorIcons: 31cebfcf94e8cf8686eb5303ae0357da64d7a5a4
VisionCamera: 33eb4044a1bee72eac4e1ad26a64b30b5ffe41a6
VisionCamera: d65c038e7a538fbd719f3ff3e7511a2c71111e3a
Yoga: 575c581c63e0d35c9a83f4b46d01d63abc1100ac
PODFILE CHECKSUM: 4b093c1d474775c2eac3268011e4b0b80929d3a2

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)
let frame = Frame(buffer: sampleBuffer, 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)
}
} else {
// we're still in the middle of executing a Frame Processor for a previous frame, notify user about dropped frame.
if !hasLoggedFrameProcessorFrameDropWarning {