99#import " SCRecorder.h"
1010#import " SCRecordSession_Internal.h"
1111#define dispatch_handler (x ) if (x != nil ) dispatch_async(dispatch_get_main_queue(), x)
12- #define SCRecorderFocusContext ((void *)0x1 )
13- #define SCRecorderVideoEnabledContext ((void *)0x2 )
14- #define SCRecorderAudioEnabledContext ((void *)0x3 )
15- #define SCRecorderPhotoOptionsContext ((void *)0x3 )
1612#define kSCRecorderRecordSessionQueueKey " SCRecorderRecordSessionQueue"
1713#define kMinTimeBetweenAppend 0.004
1814
@@ -49,6 +45,12 @@ @interface SCRecorder() {
4945
5046@implementation SCRecorder
5147
48+ static char * SCRecorderFocusContext = " FocusContext" ;
49+ static char * SCRecorderExposureContext = " ExposureContext" ;
50+ static char * SCRecorderVideoEnabledContext = " VideoEnabledContext" ;
51+ static char * SCRecorderAudioEnabledContext = " AudioEnabledContext" ;
52+ static char * SCRecorderPhotoOptionsContext = " PhotoOptionsContext" ;
53+
5254- (id )init {
5355 self = [super init ];
5456
@@ -333,7 +335,11 @@ - (void)stopRunning {
333335}
334336
335337- (void )_subjectAreaDidChange {
336- [self focusCenter ];
338+ id <SCRecorderDelegate> delegate = self.delegate ;
339+
340+ if (![delegate respondsToSelector: @selector (recorderShouldAutomaticallyRefocus: )] || [delegate recorderShouldAutomaticallyRefocus: self ]) {
341+ [self focusCenter ];
342+ }
337343}
338344
339345- (UIImage *)_imageFromSampleBufferHolder : (SCSampleBufferHolder *)sampleBufferHolder {
@@ -875,6 +881,18 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
875881 } else {
876882 [self _focusDidComplete ];
877883 }
884+ } else if (context == SCRecorderExposureContext) {
885+ BOOL isAdjustingExposure = [[change objectForKey: NSKeyValueChangeNewKey ] boolValue ];
886+
887+ if (isAdjustingExposure) {
888+ if ([delegate respondsToSelector: @selector (recorderDidStartAdjustingExposure: )]) {
889+ [delegate recorderDidStartAdjustingExposure: self ];
890+ }
891+ } else {
892+ if ([delegate respondsToSelector: @selector (recorderDidEndAdjustingExposure: )]) {
893+ [delegate recorderDidEndAdjustingExposure: self ];
894+ }
895+ }
878896 } else if (context == SCRecorderAudioEnabledContext) {
879897 if ([NSThread isMainThread ]) {
880898 [self reconfigureVideoInput: NO audioInput: YES ];
@@ -898,10 +916,12 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
898916
899917- (void )addVideoObservers : (AVCaptureDevice*)videoDevice {
900918 [videoDevice addObserver: self forKeyPath: @" adjustingFocus" options: NSKeyValueObservingOptionNew context: SCRecorderFocusContext];
919+ [videoDevice addObserver: self forKeyPath: @" adjustingExposure" options: NSKeyValueObservingOptionNew context: SCRecorderExposureContext];
901920}
902921
903922- (void )removeVideoObservers : (AVCaptureDevice*)videoDevice {
904923 [videoDevice removeObserver: self forKeyPath: @" adjustingFocus" ];
924+ [videoDevice removeObserver: self forKeyPath: @" adjustingExposure" ];
905925}
906926
907927- (void )configureDevice : (AVCaptureDevice*)newDevice mediaType : (NSString *)mediaType error : (NSError **)error {
@@ -1070,6 +1090,7 @@ - (void)_applyPointOfInterest:(CGPoint)point continuousMode:(BOOL)continuousMode
10701090 NSError *error;
10711091 if ([device lockForConfiguration: &error]) {
10721092 BOOL focusing = NO ;
1093+ BOOL adjustingExposure = NO ;
10731094
10741095 if (device.isFocusPointOfInterestSupported ) {
10751096 device.focusPointOfInterest = point;
@@ -1085,6 +1106,7 @@ - (void)_applyPointOfInterest:(CGPoint)point continuousMode:(BOOL)continuousMode
10851106
10861107 if ([device isExposureModeSupported: exposureMode]) {
10871108 device.exposureMode = exposureMode;
1109+ adjustingExposure = YES ;
10881110 }
10891111
10901112 if ([device isWhiteBalanceModeSupported: whiteBalanceMode]) {
@@ -1093,14 +1115,20 @@ - (void)_applyPointOfInterest:(CGPoint)point continuousMode:(BOOL)continuousMode
10931115
10941116 [device unlockForConfiguration ];
10951117
1118+ id <SCRecorderDelegate> delegate = self.delegate ;
10961119 if (focusMode != AVCaptureFocusModeContinuousAutoFocus && focusing) {
1097- id <SCRecorderDelegate> delegate = self.delegate ;
10981120 if ([delegate respondsToSelector: @selector (recorderWillStartFocus: )]) {
10991121 [delegate recorderWillStartFocus: self ];
11001122 }
11011123
11021124 [self setAdjustingFocus: YES ];
11031125 }
1126+
1127+ if (exposureMode != AVCaptureExposureModeContinuousAutoExposure && adjustingExposure) {
1128+ if ([delegate respondsToSelector: @selector (recorderWillStartAdjustingExposure: )]) {
1129+ [delegate recorderWillStartAdjustingExposure: self ];
1130+ }
1131+ }
11041132 }
11051133}
11061134
@@ -1124,6 +1152,14 @@ - (void)refocus {
11241152 [self autoFocusAtPoint: self .focusPointOfInterest];
11251153}
11261154
1155+ - (CGPoint)exposurePointOfInterest {
1156+ return [self .currentVideoDeviceInput device ].exposurePointOfInterest ;
1157+ }
1158+
1159+ - (BOOL )exposureSupported {
1160+ return [self .currentVideoDeviceInput device ].isExposurePointOfInterestSupported ;
1161+ }
1162+
11271163- (CGPoint)focusPointOfInterest {
11281164 return [self .currentVideoDeviceInput device ].focusPointOfInterest ;
11291165}
0 commit comments