With current set of APIs, the brightness sampling is only done at the start of the recording. So AVCaptureTorchModeAuto does not work as you expect.
Now about the use case discussed in the question:
Possibility 1:
Use Rear camera for brightness detection:
Once torch comes up, analysis of the captured stream will not tell the current situation of room brightness, as Torch will cause cosmetic brightness.
So in order to get the real brightness value would have to require to switch on-off on timely basis, which is not very generic and convenient in most of the cases.
Getting brightness value to decide enabling of Torch or not.
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
CFDictionaryRef metadataDict = CMCopyDictionaryOfAttachments(NULL,
sampleBuffer, kCMAttachmentMode_ShouldPropagate);
NSDictionary *metadata = [[NSMutableDictionary alloc]
initWithDictionary:(__bridge NSDictionary*)metadataDict];
CFRelease(metadataDict);
NSDictionary *exifMetadata = [[metadata
objectForKey:(NSString *)kCGImagePropertyExifDictionary] mutableCopy];
float brightnessValue = [[exifMetadata
objectForKey:(NSString *)kCGImagePropertyExifBrightnessValue] floatValue];
}
Possibility 2:
Use Front Camera for brightness detection:
Torch is not permitted with front camera.