9
9
#import " SCRecorder.h"
10
10
#import " SCRecordSession_Internal.h"
11
11
#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 )
16
12
#define kSCRecorderRecordSessionQueueKey " SCRecorderRecordSessionQueue"
17
13
#define kMinTimeBetweenAppend 0.004
18
14
@@ -49,6 +45,12 @@ @interface SCRecorder() {
49
45
50
46
@implementation SCRecorder
51
47
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
+
52
54
- (id )init {
53
55
self = [super init ];
54
56
@@ -333,7 +335,11 @@ - (void)stopRunning {
333
335
}
334
336
335
337
- (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
+ }
337
343
}
338
344
339
345
- (UIImage *)_imageFromSampleBufferHolder : (SCSampleBufferHolder *)sampleBufferHolder {
@@ -875,6 +881,18 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
875
881
} else {
876
882
[self _focusDidComplete ];
877
883
}
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
+ }
878
896
} else if (context == SCRecorderAudioEnabledContext) {
879
897
if ([NSThread isMainThread ]) {
880
898
[self reconfigureVideoInput: NO audioInput: YES ];
@@ -898,10 +916,12 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
898
916
899
917
- (void )addVideoObservers : (AVCaptureDevice*)videoDevice {
900
918
[videoDevice addObserver: self forKeyPath: @" adjustingFocus" options: NSKeyValueObservingOptionNew context: SCRecorderFocusContext];
919
+ [videoDevice addObserver: self forKeyPath: @" adjustingExposure" options: NSKeyValueObservingOptionNew context: SCRecorderExposureContext];
901
920
}
902
921
903
922
- (void )removeVideoObservers : (AVCaptureDevice*)videoDevice {
904
923
[videoDevice removeObserver: self forKeyPath: @" adjustingFocus" ];
924
+ [videoDevice removeObserver: self forKeyPath: @" adjustingExposure" ];
905
925
}
906
926
907
927
- (void )configureDevice : (AVCaptureDevice*)newDevice mediaType : (NSString *)mediaType error : (NSError **)error {
@@ -1070,6 +1090,7 @@ - (void)_applyPointOfInterest:(CGPoint)point continuousMode:(BOOL)continuousMode
1070
1090
NSError *error;
1071
1091
if ([device lockForConfiguration: &error]) {
1072
1092
BOOL focusing = NO ;
1093
+ BOOL adjustingExposure = NO ;
1073
1094
1074
1095
if (device.isFocusPointOfInterestSupported ) {
1075
1096
device.focusPointOfInterest = point;
@@ -1085,6 +1106,7 @@ - (void)_applyPointOfInterest:(CGPoint)point continuousMode:(BOOL)continuousMode
1085
1106
1086
1107
if ([device isExposureModeSupported: exposureMode]) {
1087
1108
device.exposureMode = exposureMode;
1109
+ adjustingExposure = YES ;
1088
1110
}
1089
1111
1090
1112
if ([device isWhiteBalanceModeSupported: whiteBalanceMode]) {
@@ -1093,14 +1115,20 @@ - (void)_applyPointOfInterest:(CGPoint)point continuousMode:(BOOL)continuousMode
1093
1115
1094
1116
[device unlockForConfiguration ];
1095
1117
1118
+ id <SCRecorderDelegate> delegate = self.delegate ;
1096
1119
if (focusMode != AVCaptureFocusModeContinuousAutoFocus && focusing) {
1097
- id <SCRecorderDelegate> delegate = self.delegate ;
1098
1120
if ([delegate respondsToSelector: @selector (recorderWillStartFocus: )]) {
1099
1121
[delegate recorderWillStartFocus: self ];
1100
1122
}
1101
1123
1102
1124
[self setAdjustingFocus: YES ];
1103
1125
}
1126
+
1127
+ if (exposureMode != AVCaptureExposureModeContinuousAutoExposure && adjustingExposure) {
1128
+ if ([delegate respondsToSelector: @selector (recorderWillStartAdjustingExposure: )]) {
1129
+ [delegate recorderWillStartAdjustingExposure: self ];
1130
+ }
1131
+ }
1104
1132
}
1105
1133
}
1106
1134
@@ -1124,6 +1152,14 @@ - (void)refocus {
1124
1152
[self autoFocusAtPoint: self .focusPointOfInterest];
1125
1153
}
1126
1154
1155
+ - (CGPoint)exposurePointOfInterest {
1156
+ return [self .currentVideoDeviceInput device ].exposurePointOfInterest ;
1157
+ }
1158
+
1159
+ - (BOOL )exposureSupported {
1160
+ return [self .currentVideoDeviceInput device ].isExposurePointOfInterestSupported ;
1161
+ }
1162
+
1127
1163
- (CGPoint)focusPointOfInterest {
1128
1164
return [self .currentVideoDeviceInput device ].focusPointOfInterest ;
1129
1165
}
0 commit comments