Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVFoundation: isExposureModeSupported returns FALSE for AVCaptureExposureModeAutoExpose

I am working on building a custom camera using AVFoundation. Everything works great with the exception of setExposurePointOfInterest.

I am testing on an iPhone 5, and AVCaptureDevice is telling me that the BackCamera does not support AVCaptureExposureModeAutoExpose.

How do I then implement tap to adjust exposure?

Here's my code:

- (void)didTapCameraPreview:(UITapGestureRecognizer *)recognizer {

CGPoint point = [recognizer locationInView:self.view];
CGRect screenRect = [self.view bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
double focus_x = point.x/screenWidth;
double focus_y = point.y/screenHeight;

CGPoint touchPoint = CGPointMake(focus_x, focus_y);

AVCaptureDevice *device = (self.captureSession.inputs[0] == self.backCamera) ? self.backCamera.device : self.frontCamera.device;

if (device.isFocusPointOfInterestSupported) {
    NSError *error;
    if ([device lockForConfiguration:&error]) {
        [device setFocusPointOfInterest:touchPoint];
        [device setExposurePointOfInterest:touchPoint];

        [device setFocusMode:AVCaptureFocusModeAutoFocus];
        if ([device isExposureModeSupported:AVCaptureExposureModeAutoExpose]){
            [device setExposureMode:AVCaptureExposureModeAutoExpose];
        }
        [device unlockForConfiguration];
    }
}

}

like image 720
chrysb Avatar asked Oct 02 '22 07:10

chrysb


1 Answers

I was questioning the similar question in Apple Developer forum and got answered by Brad Ford (Core Media Engineering), the speaker of Camera Capture with AV Foundation in Apple's WWDC.

Here's his answer:

Correct. AVCaptureExposureModeAutoExpose, while defined in the header, is not currently implemented on any iOS device.

You can however implement it in your own code by setting your desired point of interest, then calling setExposureMode:AVCaptureExposureModeContinuousAutoExposure, and then listen (key-value observe) the "isAdjustingExposure" property of AVCaptureDevice to know when the exposure finishes adjusting. As soon as it does, setExposureMode to AVCaptureExposureModeLocked.

Hope it clarifies and helps!

like image 120
yonasstephen Avatar answered Oct 13 '22 10:10

yonasstephen