From 444e1855099872dbd6a9c4ff78f9123dd525ca04 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Thu, 26 Apr 2012 10:14:41 +0200 Subject: [PATCH] ipad: fix camera switch button --- Classes/MainScreenWithVideoPreview.m | 38 +++++++++++++++------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Classes/MainScreenWithVideoPreview.m b/Classes/MainScreenWithVideoPreview.m index 2947b85d0..118c6af0a 100644 --- a/Classes/MainScreenWithVideoPreview.m +++ b/Classes/MainScreenWithVideoPreview.m @@ -72,7 +72,6 @@ - (void)viewDidLoad { [super viewDidLoad]; - [phoneMainView.switchCamera addTarget:self action:@selector(switchCameraPressed) forControlEvents:UIControlEventTouchUpInside]; } -(void) switchCameraPressed { @@ -80,30 +79,32 @@ } -(void) useCameraAtIndex:(NSInteger)camIndex startSession:(BOOL)start { - [session stopRunning]; + @synchronized (self) { + [session stopRunning]; - if (input != nil) - [session removeInput:input]; + if (input != nil) + [session removeInput:input]; - NSError* error; + NSError* error; - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc]init]; - NSArray* array = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; - if ( [array count] == 0) { - ms_warning("No camera available (running on simulator ?"); - return; - } - currentCamera = camIndex % [array count]; - AVCaptureDevice* device = (AVCaptureDevice*) [array objectAtIndex:currentCamera]; - input = [[AVCaptureDeviceInput deviceInputWithDevice:device + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc]init]; + NSArray* array = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; + if ( [array count] == 0) { + ms_warning("No camera available (running on simulator ?"); + return; + } + currentCamera = camIndex % [array count]; + AVCaptureDevice* device = (AVCaptureDevice*) [array objectAtIndex:currentCamera]; + input = [[AVCaptureDeviceInput deviceInputWithDevice:device error:&error] retain]; - [session addInput:input]; + [session addInput:input]; - [pool drain]; + [pool drain]; - if (start) - [session startRunning]; + if (start) + [session startRunning]; + } } -(void) stopPreview:(id) a { @@ -151,6 +152,7 @@ -(void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; + [phoneMainView.switchCamera addTarget:self action:@selector(switchCameraPressed) forControlEvents:UIControlEventTouchUpInside]; } -(void) viewDidDisappear:(BOOL)animated {