@carviz/capacitor-camera-preview 7.1.1 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,6 +43,7 @@ class CameraController: NSObject {
43
43
  var captureSession: AVCaptureSession?
44
44
 
45
45
  var photoOutput = AVCapturePhotoOutput()
46
+ var videoDataOutput = AVCaptureVideoDataOutput()
46
47
  var photoCaptureCompletionBlock: ((UIImage?, Error?) -> Void)?
47
48
  var sampleBufferCaptureCompletionBlock: ((UIImage?, Error?) -> Void)?
48
49
 
@@ -91,6 +92,13 @@ class CameraController: NSObject {
91
92
  captureSession.addOutput(self.photoOutput)
92
93
  }
93
94
 
95
+ // Configure video data output for sample capture
96
+ self.videoDataOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "videoQueue"))
97
+ self.videoDataOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)]
98
+ if captureSession.canAddOutput(self.videoDataOutput) {
99
+ captureSession.addOutput(self.videoDataOutput)
100
+ }
101
+
94
102
  captureSession.startRunning()
95
103
 
96
104
  // Lastly setting the video zoom factor
@@ -293,6 +301,7 @@ class CameraController: NSObject {
293
301
  return
294
302
  }
295
303
 
304
+ // Store the completion block to be called when we receive the next video frame
296
305
  self.sampleBufferCaptureCompletionBlock = completion
297
306
  }
298
307
 
@@ -517,6 +526,41 @@ extension CameraController: AVCapturePhotoCaptureDelegate {
517
526
  }
518
527
  }
519
528
 
529
+ extension CameraController: AVCaptureVideoDataOutputSampleBufferDelegate {
530
+ func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
531
+ // Only process if we have a pending sample capture request
532
+ guard let completion = self.sampleBufferCaptureCompletionBlock else { return }
533
+
534
+ // Clear the completion block to avoid capturing multiple frames for one request
535
+ self.sampleBufferCaptureCompletionBlock = nil
536
+
537
+ // Convert sample buffer to UIImage
538
+ guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
539
+ DispatchQueue.main.async {
540
+ completion(nil, CameraControllerError.unknown)
541
+ }
542
+ return
543
+ }
544
+
545
+ let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
546
+ let context = CIContext()
547
+
548
+ guard let cgImage = context.createCGImage(ciImage, from: ciImage.extent) else {
549
+ DispatchQueue.main.async {
550
+ completion(nil, CameraControllerError.unknown)
551
+ }
552
+ return
553
+ }
554
+
555
+ let image = UIImage(cgImage: cgImage)
556
+
557
+ // Call completion on main queue
558
+ DispatchQueue.main.async {
559
+ completion(image, nil)
560
+ }
561
+ }
562
+ }
563
+
520
564
  extension CameraController: UIGestureRecognizerDelegate {
521
565
  func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
522
566
  return true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carviz/capacitor-camera-preview",
3
- "version": "7.1.1",
3
+ "version": "7.2.0",
4
4
  "description": "Fork of the capacitor-community/camera-preview plugin focusing on high resolution photos without bloating up the code.",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.cjs.js",