Skip to content

Commit db988df

Browse files
committed
fix(ios): camera live processing not working
1 parent f327950 commit db988df

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

packages/ui-cameraview/platforms/ios/src/NSCameraView.swift

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
5151
self.nextLevel?.previewLayer.frame = self.bounds
5252
}
5353
}
54-
55-
54+
55+
5656
public var videoGravity: String {
5757
get {
5858
return (self.nextLevel?.previewLayer.videoGravity ?? AVLayerVideoGravity.resizeAspectFill).rawValue
@@ -119,7 +119,7 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
119119

120120
// audio configuration
121121
// for now disable audio
122-
nextLevel.captureMode = NextLevelCaptureMode.photo
122+
nextLevel.captureMode = NextLevelCaptureMode.videoWithoutAudio
123123
// nextLevel.audioConfiguration.bitRate = 96000
124124
// nextLevel.disableAudioInputDevice()
125125
// metadata objects configuration
@@ -149,7 +149,7 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
149149
public func focusAtAdjustedPointOfInterest(_ adjustedPoint: CGPoint){
150150
self.nextLevel?.focusAtAdjustedPointOfInterest(adjustedPoint: adjustedPoint)
151151
}
152-
152+
153153
public var canCapturePhoto: Bool {
154154
get {
155155
return self.nextLevel?.canCapturePhoto ?? false
@@ -174,7 +174,7 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
174174
}
175175
public func capturePhotoFromVideo() {
176176
if let nextLevel = self.nextLevel , self.canCaptureVideo {
177-
if ( nextLevel.captureMode == NextLevelCaptureMode.videoWithoutAudio || nextLevel.captureMode == NextLevelCaptureMode.video) {
177+
if ( nextLevel.captureMode == NextLevelCaptureMode.videoWithoutAudio || nextLevel.captureMode == NextLevelCaptureMode.video) {
178178
nextLevel.capturePhotoFromVideo()
179179
} else {
180180
captureModeCompletionHandler = {
@@ -186,7 +186,7 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
186186
}
187187

188188
// MARK: NextLevelDelegate
189-
189+
190190
public func nextLevel(_ nextLevel: NextLevel, didUpdateVideoConfiguration videoConfiguration: NextLevelVideoConfiguration) {
191191

192192
}
@@ -221,11 +221,11 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
221221
}
222222

223223
public func nextLevelCaptureModeDidChange(_ nextLevel: NextLevel) {
224-
captureModeCompletionHandler?()
224+
captureModeCompletionHandler?()
225225
}
226226

227227
// MARK: NextLevelPhotoDelegate
228-
228+
229229
public func nextLevel(_ nextLevel: NextLevel, willProcessRawVideoSampleBuffer sampleBuffer: CMSampleBuffer, onQueue queue: DispatchQueue) {
230230
self.processingDelegate?.cameraView(self, willProcessRawVideoSampleBuffer: sampleBuffer, onQueue: queue)
231231
}
@@ -287,9 +287,9 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
287287
}
288288

289289
public func nextLevel(_ nextLevel: NextLevel, didCompletePhotoCaptureFromVideoFrame photoDict: [String : Any]?) {
290-
self.videoDelegate?.cameraView(self, didCompletePhotoCaptureFromVideoFrame: photoDict)
290+
self.videoDelegate?.cameraView(self, didCompletePhotoCaptureFromVideoFrame: photoDict)
291291
}
292-
292+
293293
// MARK: NextLevelPhotoDelegate
294294

295295
public func nextLevel(_ nextLevel: NextLevel, output: AVCapturePhotoOutput, willBeginCaptureFor resolvedSettings: AVCaptureResolvedPhotoSettings, photoConfiguration: NextLevelPhotoConfiguration) {
@@ -307,52 +307,52 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
307307
let photoMetadata = photo.metadata
308308
// Returns corresponting NSCFNumber. It seems to specify the origin of the image
309309
// print("Metadata orientation: ",photoMetadata["Orientation"])
310-
310+
311311
// Returns corresponting NSCFNumber. It seems to specify the origin of the image
312312
print("Metadata orientation with key: ",photoMetadata[String(kCGImagePropertyOrientation)] as Any)
313-
313+
314314
guard let imageData = photo.fileDataRepresentation() else {
315-
print("Error while generating image from photo capture data.");
316-
return
315+
print("Error while generating image from photo capture data.");
316+
return
317317
}
318-
318+
319319
guard let uiImage = UIImage(data: imageData) else {
320-
print("Unable to generate UIImage from image data.");
321-
return
320+
print("Unable to generate UIImage from image data.");
321+
return
322322
}
323-
323+
324324
// generate a corresponding CGImage
325325
guard let cgImage = uiImage.cgImage else {
326-
print("Error generating CGImage")
327-
return
326+
print("Error generating CGImage")
327+
return
328328
}
329-
329+
330330
guard let deviceOrientationOnCapture = self.deviceOrientationOnCapture else {
331-
print("Error retrieving orientation on capture")
332-
return
331+
print("Error retrieving orientation on capture")
332+
return
333333
}
334-
335-
var image = UIImage(cgImage: cgImage, scale: 1.0, orientation: deviceOrientationOnCapture.getUIImageOrientationFromDevice())
336-
334+
335+
let image = UIImage(cgImage: cgImage, scale: 1.0, orientation: deviceOrientationOnCapture.getUIImageOrientationFromDevice())
336+
337337
self.photoDelegate?.cameraView(self, didFinishProcessingPhoto: image, photoDict: photoDict, photoConfiguration: NSCameraViewPhotoConfiguration(configuration: photoConfiguration))
338338
}
339339

340340
public func nextLevelDidCompletePhotoCapture(_ nextLevel: NextLevel) {
341-
341+
342342
}
343343

344344
}
345345

346346
extension UIDeviceOrientation {
347-
func getUIImageOrientationFromDevice() -> UIImage.Orientation {
348-
// return CGImagePropertyOrientation based on Device Orientation
349-
// This extented function has been determined based on experimentation with how an UIImage gets displayed.
350-
switch self {
351-
case UIDeviceOrientation.portrait, .faceUp: return UIImage.Orientation.right
352-
case UIDeviceOrientation.portraitUpsideDown, .faceDown: return UIImage.Orientation.left
353-
case UIDeviceOrientation.landscapeLeft: return UIImage.Orientation.up // this is the base orientation
354-
case UIDeviceOrientation.landscapeRight: return UIImage.Orientation.down
355-
case UIDeviceOrientation.unknown: return UIImage.Orientation.up
356-
}
347+
func getUIImageOrientationFromDevice() -> UIImage.Orientation {
348+
// return CGImagePropertyOrientation based on Device Orientation
349+
// This extented function has been determined based on experimentation with how an UIImage gets displayed.
350+
switch self {
351+
case UIDeviceOrientation.portrait, .faceUp: return UIImage.Orientation.right
352+
case UIDeviceOrientation.portraitUpsideDown, .faceDown: return UIImage.Orientation.left
353+
case UIDeviceOrientation.landscapeLeft: return UIImage.Orientation.up // this is the base orientation
354+
case UIDeviceOrientation.landscapeRight: return UIImage.Orientation.down
355+
case UIDeviceOrientation.unknown: return UIImage.Orientation.up
357356
}
357+
}
358358
}

0 commit comments

Comments
 (0)