Skip to content

Commit 79b318c

Browse files
committed
Added adjusting exposures message in delegate.
1 parent 829b1ce commit 79b318c

File tree

4 files changed

+82
-7
lines changed

4 files changed

+82
-7
lines changed

Library/Sources/SCRecorder.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@
189189
*/
190190
@property (assign, nonatomic) BOOL keepMirroringOnWrite;
191191

192+
/**
193+
Whether adjusting exposure is supported on the current camera device
194+
*/
195+
@property (readonly, nonatomic) BOOL exposureSupported;
196+
197+
/**
198+
The current exposure point of interest
199+
*/
200+
@property (readonly, nonatomic) CGPoint exposurePointOfInterest;
201+
192202
/**
193203
Whether the focus is supported on the current camera device
194204
*/

Library/Sources/SCRecorder.m

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
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
}

Library/Sources/SCRecorderDelegate.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ typedef NS_ENUM(NSInteger, SCFlashMode) {
3838
*/
3939
- (void)recorder:(SCRecorder *__nonnull)recorder didChangeFlashMode:(SCFlashMode)flashMode error:(NSError *__nullable)error;
4040

41+
/**
42+
Called when the recorder has lost the focus. Returning true will make the recorder
43+
automatically refocus at the center.
44+
*/
45+
- (BOOL)recorderShouldAutomaticallyRefocus:(SCRecorder *__nonnull)recorder;
46+
4147
/**
4248
Called before the recorder will start focusing
4349
*/
@@ -53,6 +59,21 @@ typedef NS_ENUM(NSInteger, SCFlashMode) {
5359
*/
5460
- (void)recorderDidEndFocus:(SCRecorder *__nonnull)recorder;
5561

62+
/**
63+
Called before the recorder will start adjusting exposure
64+
*/
65+
- (void)recorderWillStartAdjustingExposure:(SCRecorder *__nonnull)recorder;
66+
67+
/**
68+
Called when the recorder has started adjusting exposure
69+
*/
70+
- (void)recorderDidStartAdjustingExposure:(SCRecorder *__nonnull)recorder;
71+
72+
/**
73+
Called when the recorder has finished adjusting exposure
74+
*/
75+
- (void)recorderDidEndAdjustingExposure:(SCRecorder *__nonnull)recorder;
76+
5677
/**
5778
Called when the recorder has initialized the audio in a session
5879
*/

Library/Sources/SCRecorderToolsView.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@ - (void)layoutSubviews {
9696
}
9797

9898
- (void)adjustFocusView {
99-
CGPoint currentFocusPoint = [self.recorder convertPointOfInterestToViewCoordinates:self.recorder.focusPointOfInterest];
99+
CGPoint currentFocusPoint = CGPointMake(0.5, 0.5);
100+
101+
if (self.recorder.focusSupported) {
102+
currentFocusPoint = self.recorder.focusPointOfInterest;
103+
} else if (self.recorder.exposureSupported) {
104+
currentFocusPoint = self.recorder.exposurePointOfInterest;
105+
}
106+
107+
[self.recorder convertPointOfInterestToViewCoordinates:currentFocusPoint];
100108
currentFocusPoint = [self convertPoint:currentFocusPoint fromView:self.recorder.previewView];
101109
self.cameraFocusTargetView.center = currentFocusPoint;
102110
}

0 commit comments

Comments
 (0)