From 80af8305ecf038a3a2a38e9c962bbc2776d79a37 Mon Sep 17 00:00:00 2001 From: Leone Parise Date: Fri, 6 May 2016 16:50:56 -0500 Subject: [PATCH 1/3] Add flag to use device orientation only on capture --- LLSimpleCamera/LLSimpleCamera.h | 6 ++++++ LLSimpleCamera/LLSimpleCamera.m | 13 +++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/LLSimpleCamera/LLSimpleCamera.h b/LLSimpleCamera/LLSimpleCamera.h index 29262c0..c37e315 100644 --- a/LLSimpleCamera/LLSimpleCamera.h +++ b/LLSimpleCamera/LLSimpleCamera.h @@ -116,6 +116,12 @@ typedef enum : NSUInteger { */ @property (nonatomic) BOOL useDeviceOrientation; +/** + * Set YES if you your view controller does not allow autorotation, + * but you want to use the devide orientation on capture. Enabled by default. + */ +@property (nonatomic) BOOL useDeviceOrientationOnCapture; + /** * Use this method to request camera permission before initalizing LLSimpleCamera. */ diff --git a/LLSimpleCamera/LLSimpleCamera.m b/LLSimpleCamera/LLSimpleCamera.m index 04aea0a..19c0688 100644 --- a/LLSimpleCamera/LLSimpleCamera.m +++ b/LLSimpleCamera/LLSimpleCamera.m @@ -74,6 +74,7 @@ - (void)setupWithQuality:(NSString *)quality _fixOrientationAfterCapture = NO; _tapToFocus = YES; _useDeviceOrientation = NO; + _useDeviceOrientationOnCapture = YES; _flash = LLCameraFlashOff; _mirror = LLCameraMirrorAuto; _videoEnabled = videoEnabled; @@ -250,7 +251,7 @@ - (void)initialize if([self.session canAddInput:_videoDeviceInput]) { [self.session addInput:_videoDeviceInput]; - self.captureVideoPreviewLayer.connection.videoOrientation = [self orientationForConnection]; + self.captureVideoPreviewLayer.connection.videoOrientation = [self orientationForConnection:false]; } // add audio if video is enabled @@ -313,7 +314,7 @@ -(void)capture:(void (^)(LLSimpleCamera *camera, UIImage *image, NSDictionary *m // get connection and set orientation AVCaptureConnection *videoConnection = [self captureConnection]; - videoConnection.videoOrientation = [self orientationForConnection]; + videoConnection.videoOrientation = [self orientationForConnection:true]; // freeze the screen [self.captureVideoPreviewLayer.connection setEnabled:NO]; @@ -382,7 +383,7 @@ - (void)startRecordingWithOutputUrl:(NSURL *)url // get only the video media types if ([[port mediaType] isEqual:AVMediaTypeVideo]) { if([connection isVideoOrientationSupported]) { - [connection setVideoOrientation:[self orientationForConnection]]; + [connection setVideoOrientation:[self orientationForConnection:false]]; } } } @@ -846,14 +847,14 @@ - (void)viewWillLayoutSubviews self.captureVideoPreviewLayer.bounds = bounds; self.captureVideoPreviewLayer.position = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)); - self.captureVideoPreviewLayer.connection.videoOrientation = [self orientationForConnection]; + self.captureVideoPreviewLayer.connection.videoOrientation = [self orientationForConnection:false]; } -- (AVCaptureVideoOrientation)orientationForConnection +- (AVCaptureVideoOrientation)orientationForConnection: (BOOL) capture { AVCaptureVideoOrientation videoOrientation = AVCaptureVideoOrientationPortrait; - if(self.useDeviceOrientation) { + if(self.useDeviceOrientation || (self.useDeviceOrientationOnCapture && capture)) { switch ([UIDevice currentDevice].orientation) { case UIDeviceOrientationLandscapeLeft: // yes we to the right, this is not bug! From 7e4f7ca11519852618ab5fa3393d74081f110840 Mon Sep 17 00:00:00 2001 From: Leone Parise Date: Fri, 13 May 2016 17:56:35 -0500 Subject: [PATCH 2/3] Fix memory leak on capture image --- LLSimpleCamera/LLSimpleCamera.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/LLSimpleCamera/LLSimpleCamera.m b/LLSimpleCamera/LLSimpleCamera.m index 19c0688..8b9ccef 100644 --- a/LLSimpleCamera/LLSimpleCamera.m +++ b/LLSimpleCamera/LLSimpleCamera.m @@ -319,6 +319,7 @@ -(void)capture:(void (^)(LLSimpleCamera *camera, UIImage *image, NSDictionary *m // freeze the screen [self.captureVideoPreviewLayer.connection setEnabled:NO]; + __weak typeof(self) _self = self; [self.stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) { UIImage *image = nil; @@ -335,10 +336,10 @@ -(void)capture:(void (^)(LLSimpleCamera *camera, UIImage *image, NSDictionary *m image = [[UIImage alloc] initWithData:imageData]; if(exactSeenImage) { - image = [self cropImageUsingPreviewBounds:image]; + image = [_self cropImageUsingPreviewBounds:image]; } - if(self.fixOrientationAfterCapture) { + if(_self.fixOrientationAfterCapture) { image = [image fixOrientation]; } } @@ -346,7 +347,7 @@ -(void)capture:(void (^)(LLSimpleCamera *camera, UIImage *image, NSDictionary *m // trigger the block if(onCapture) { dispatch_async(dispatch_get_main_queue(), ^{ - onCapture(self, image, metadata, error); + onCapture(_self, image, metadata, error); }); } }]; From 0e4df8a02e584ea6c5b85661b665afaa3f45c5e8 Mon Sep 17 00:00:00 2001 From: Leone Parise Date: Sun, 15 May 2016 18:26:44 -0500 Subject: [PATCH 3/3] Disable by default orientation for capture and include it on recording --- LLSimpleCamera/LLSimpleCamera.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LLSimpleCamera/LLSimpleCamera.m b/LLSimpleCamera/LLSimpleCamera.m index 8b9ccef..78040b8 100644 --- a/LLSimpleCamera/LLSimpleCamera.m +++ b/LLSimpleCamera/LLSimpleCamera.m @@ -74,7 +74,7 @@ - (void)setupWithQuality:(NSString *)quality _fixOrientationAfterCapture = NO; _tapToFocus = YES; _useDeviceOrientation = NO; - _useDeviceOrientationOnCapture = YES; + _useDeviceOrientationOnCapture = NO; _flash = LLCameraFlashOff; _mirror = LLCameraMirrorAuto; _videoEnabled = videoEnabled; @@ -384,7 +384,7 @@ - (void)startRecordingWithOutputUrl:(NSURL *)url // get only the video media types if ([[port mediaType] isEqual:AVMediaTypeVideo]) { if([connection isVideoOrientationSupported]) { - [connection setVideoOrientation:[self orientationForConnection:false]]; + [connection setVideoOrientation:[self orientationForConnection:true]]; } } }