Skip to content

Commit

Permalink
fix: Use CMSampleBuffer for now again
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jun 4, 2024
1 parent e299e3b commit 0791862
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions package/ios/Core/CameraSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ class CameraSession: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate, AVC
// Call Frame Processor (delegate) for every Video Frame
if captureOutput is AVCaptureVideoDataOutput {
let orientation = connection.orientation
let frame = Frame(buffer: sampleBuffer, orientation: orientation.imageOrientation)
delegate?.onFrame(frame: frame)
delegate?.onFrame(sampleBuffer: sampleBuffer, orientation: orientation)
}

// Record Video Frame/Audio Sample to File in custom `RecordingSession` (AVAssetWriter)
Expand Down
2 changes: 1 addition & 1 deletion package/ios/Core/CameraSessionDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protocol CameraSessionDelegate: AnyObject {
/**
Called for every frame (if video or frameProcessor is enabled)
*/
func onFrame(frame: Frame)
func onFrame(sampleBuffer: CMSampleBuffer, orientation: Orientation)
/**
Called whenever a QR/Barcode has been scanned. Only if the CodeScanner Output is enabled
*/
Expand Down
3 changes: 1 addition & 2 deletions package/ios/React/CameraView+TakeSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ extension CameraView {
}

// Add a listener to the onFrame callbacks which will get called later if video is enabled.
snapshotOnFrameListeners.append { frame in
snapshotOnFrameListeners.append { buffer in
if promise.didResolve {
// capture was already aborted (timed out)
return
}

self.onCaptureShutter(shutterType: .snapshot)

let buffer = frame.buffer
guard let imageBuffer = CMSampleBufferGetImageBuffer(buffer) else {
promise.reject(error: .capture(.imageDataAccessError))
return
Expand Down
7 changes: 4 additions & 3 deletions package/ios/React/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public final class CameraView: UIView, CameraSessionDelegate, FpsSampleCollector
// CameraView+Zoom
var pinchGestureRecognizer: UIPinchGestureRecognizer?
var pinchScaleOffset: CGFloat = 1.0
var snapshotOnFrameListeners: [(_: Frame) -> Void] = []
var snapshotOnFrameListeners: [(_: CMSampleBuffer) -> Void] = []
private var currentConfigureCall: DispatchTime?
private let fpsSampleCollector = FpsSampleCollector()

Expand Down Expand Up @@ -346,18 +346,19 @@ public final class CameraView: UIView, CameraSessionDelegate, FpsSampleCollector
])
}

func onFrame(frame: Frame) {
func onFrame(sampleBuffer: CMSampleBuffer, orientation: Orientation) {
fpsSampleCollector.onTick()

#if VISION_CAMERA_ENABLE_FRAME_PROCESSORS
if let frameProcessor = frameProcessor {
// Call Frame Processor
let frame = Frame(buffer: sampleBuffer, orientation: orientation.imageOrientation)
frameProcessor.call(frame)
}
#endif

for callback in snapshotOnFrameListeners {
callback(frame)
callback(sampleBuffer)
}
snapshotOnFrameListeners.removeAll()
}
Expand Down

0 comments on commit 0791862

Please sign in to comment.