Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions LFLiveKit/LFLiveSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ typedef NS_ENUM(NSInteger,LFLiveCaptureTypeMask) {
/** The torch control capture flash is on or off */
@property (nonatomic, assign) BOOL torch;

/** The continuousAutoFocus control continuousAutoFocus is on or off */
@property (nonatomic, assign) BOOL continuousAutoFocus;

/** The continuousAutoExposure control continuousAutoExposure is on or off */
@property (nonatomic, assign) BOOL continuousAutoExposure;


/** The mirror control mirror of front camera is on or off */
@property (nonatomic, assign) BOOL mirror;

Expand Down
20 changes: 20 additions & 0 deletions LFLiveKit/LFLiveSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,26 @@ - (BOOL)torch {
return self.videoCaptureSource.torch;
}

- (void)setContinuousAutoFocus:(BOOL)continuousAutoFocus {
[self willChangeValueForKey:@"continuousAutoFocus"];
[self.videoCaptureSource setContinuousAutoFocus:continuousAutoFocus];
[self didChangeValueForKey:@"continuousAutoFocus"];
}

- (BOOL)continuousAutoFocus {
return self.videoCaptureSource.continuousAutoFocus;
}

- (void)setContinuousAutoExposure:(BOOL)continuousAutoExposure {
[self willChangeValueForKey:@"continuousAutoExposure"];
[self.videoCaptureSource setContinuousAutoExposure:continuousAutoExposure];
[self didChangeValueForKey:@"continuousAutoExposure"];
}

- (BOOL)continuousAutoExposure {
return self.videoCaptureSource.continuousAutoExposure;
}

- (void)setMirror:(BOOL)mirror {
[self willChangeValueForKey:@"mirror"];
[self.videoCaptureSource setMirror:mirror];
Expand Down
7 changes: 7 additions & 0 deletions LFLiveKit/capture/LFVideoCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
/** The torch control capture flash is on or off */
@property (nonatomic, assign) BOOL torch;

/** The continuousAutoFocus control continuousAutoFocus is on or off */
@property (nonatomic, assign) BOOL continuousAutoFocus;

/** The continuousAutoExposure control continuousAutoExposure is on or off */
@property (nonatomic, assign) BOOL continuousAutoExposure;


/** The mirror control mirror of front camera is on or off */
@property (nonatomic, assign) BOOL mirror;

Expand Down
54 changes: 54 additions & 0 deletions LFLiveKit/capture/LFVideoCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ @implementation LFVideoCapture
@synthesize beautyLevel = _beautyLevel;
@synthesize brightLevel = _brightLevel;
@synthesize zoomScale = _zoomScale;
@synthesize continuousAutoFocus = _continuousAutoFocus;
@synthesize continuousAutoExposure = _continuousAutoExposure;

#pragma mark -- LifeCycle
- (instancetype)initWithVideoConfiguration:(LFLiveVideoConfiguration *)configuration {
Expand Down Expand Up @@ -158,6 +160,58 @@ - (BOOL)torch {
return self.videoCamera.inputCamera.torchMode;
}

- (void)setContinuousAutoFocus:(BOOL)continuousAutoFocus {
bool ret = false;

if (!self.videoCamera.captureSession) return;
AVCaptureFocusMode newMode = continuousAutoFocus ? AVCaptureFocusModeContinuousAutoFocus : AVCaptureFocusModeAutoFocus;
AVCaptureSession *session = (AVCaptureSession *)self.videoCamera.captureSession;
[session beginConfiguration];
if (self.videoCamera.inputCamera) {
if ([self.videoCamera.inputCamera isFocusModeSupported:newMode]) {
NSError *err = nil;
if ([self.videoCamera.inputCamera lockForConfiguration:&err]) {
self.videoCamera.inputCamera.focusMode = newMode;
[self.videoCamera.inputCamera unlockForConfiguration];
ret = true;
} else {
NSLog(@"Error while locking device for auto focus: %@", err);
ret = false;
}
} else {
NSLog(@"Auto focus not available in current camera input");
}
}
[session commitConfiguration];
_continuousAutoFocus = ret;
}

- (void)setContinuousAutoExposure:(BOOL)continuousAutoExposure {
bool ret = false;

if (!self.videoCamera.captureSession) return;
AVCaptureExposureMode newMode = continuousAutoExposure ? AVCaptureExposureModeContinuousAutoExposure : AVCaptureExposureModeAutoExpose;
AVCaptureSession *session = (AVCaptureSession *)self.videoCamera.captureSession;
[session beginConfiguration];
if (self.videoCamera.inputCamera) {
if ([self.videoCamera.inputCamera isExposureModeSupported: newMode]) {
NSError *err = nil;
if ([self.videoCamera.inputCamera lockForConfiguration:&err]) {
self.videoCamera.inputCamera.exposureMode = newMode;
[self.videoCamera.inputCamera unlockForConfiguration];
ret = true;
} else {
NSLog(@"Error while locking device for auto exposure: %@", err);
ret = false;
}
} else {
NSLog(@"Auto exposure not available in current camera input");
}
}
[session commitConfiguration];
continuousAutoExposure = ret;
}

- (void)setMirror:(BOOL)mirror {
_mirror = mirror;
}
Expand Down