Do you get error logs? If not, you need to fix the code above and see what they say. What version of AVCam are you using? They recently upgraded the project to version 1.2, which is much more efficient and uses blocks.
In my experience, you should not create and recreate a session, you can just leave it. You may need to structure your application a little differently. What exactly is your application about? Maybe we can help you. If your application is centered around the camera, then itโs easier to leave the session turned on, if your video is only a video, then perhaps using AVCam will be redundant.
Your real problem, for me, sounds like AVCaptureDeviceInput. Download the original AVCam package and see if any retention or security indicators have changed if the statements. If there is another code, send a message.
UPDATE: can you change
} else if (error) { NSLog(@"%@",[error localizedDescription]); }
to
} if (error) { NSLog(@"%@",[error localizedDescription]); }
and tell me if there is an error?
Also, before releasing the view controller that owns the session, make sure you stop the session and set the capture manager to zero.
UPDATE 2: Try this switch code. This is what I used. AVCamMirringMode is the following structure:
enum { AVCamMirroringOff = 1, AVCamMirroringOn = 2, AVCamMirroringAuto = 3 }; typedef NSInteger AVCamMirroringMode; - (BOOL) toggleCamera { BOOL success = NO; if ([self cameraCount] > 1) { NSError *error; AVCaptureDeviceInput *newVideoInput; AVCaptureDevicePosition position = [[videoInput device] position]; BOOL mirror; if (position == AVCaptureDevicePositionBack){ newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self frontFacingCamera] error:&error]; switch ([self mirroringMode]) { case AVCamMirroringOff: mirror = NO; break; case AVCamMirroringOn: mirror = YES; break; case AVCamMirroringAuto: default: mirror = YES; break; } } else if (position == AVCaptureDevicePositionFront){ newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self backFacingCamera] error:&error]; switch ([self mirroringMode]) { case AVCamMirroringOff: mirror = NO; break; case AVCamMirroringOn: mirror = YES; break; case AVCamMirroringAuto: default: mirror = NO; break; } } else goto bail; if (newVideoInput != nil) { [[self session] beginConfiguration]; [[self session] removeInput:[self videoInput]]; if ([[self session] canAddInput:newVideoInput]) { [[self session] addInput:newVideoInput]; AVCaptureConnection *connection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]]; if ([connection isVideoMirroringSupported]) { [connection setVideoMirrored:mirror]; } [self setVideoInput:newVideoInput]; } else { [[self session] addInput:[self videoInput]]; } [[self session] commitConfiguration]; success = YES; [newVideoInput release]; } else if (error) { if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)]) { [[self delegate] captureManager:self didFailWithError:error]; } } } bail: return success; }
source share