Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
update flash api use
Browse files Browse the repository at this point in the history
  • Loading branch information
piemonte committed Dec 18, 2018
1 parent f3965ed commit 3c46436
Showing 1 changed file with 13 additions and 37 deletions.
50 changes: 13 additions & 37 deletions Source/PBJVision.m
Expand Up @@ -547,17 +547,11 @@ - (void)setFlashMode:(PBJFlashMode)flashMode forceUpdate:(BOOL)forceUpdate {
switch (_cameraMode) {
case PBJCameraModePhoto:
{
if ([_currentDevice isFlashModeSupported:(AVCaptureFlashMode)_flashMode]) {
[_currentDevice setFlashMode:(AVCaptureFlashMode)_flashMode];
}
// set at capture
break;
}
case PBJCameraModeVideo:
{
if ([_currentDevice isFlashModeSupported:(AVCaptureFlashMode)_flashMode]) {
[_currentDevice setFlashMode:AVCaptureFlashModeOff];
}

if ([_currentDevice isTorchModeSupported:(AVCaptureTorchMode)_flashMode]) {
[_currentDevice setTorchMode:(AVCaptureTorchMode)_flashMode];
}
Expand Down Expand Up @@ -636,29 +630,20 @@ - (void)setVideoFrameRate:(NSInteger)videoFrameRate

- (NSInteger)videoFrameRate
{
if (!_currentDevice)
if (!_currentDevice) {
return 0;
}

return _currentDevice.activeVideoMaxFrameDuration.timescale;
}

- (BOOL)supportsVideoFrameRate:(NSInteger)videoFrameRate
{
AVCaptureDevice *videoDevice = nil;
NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
NSPredicate *predicate = nil;
if (self.cameraDevice == PBJCameraDeviceBack) {
predicate = [NSPredicate predicateWithFormat:@"position == %i", AVCaptureDevicePositionBack];
} else {
predicate = [NSPredicate predicateWithFormat:@"position == %i", AVCaptureDevicePositionFront];
}
NSArray *filteredDevices = [videoDevices filteredArrayUsingPredicate:predicate];
if (filteredDevices.count > 0) {
videoDevice = filteredDevices.firstObject;
} else {
if (!_currentDevice) {
return NO;
}
NSArray *formats = [videoDevice formats];

NSArray *formats = [_currentDevice formats];
for (AVCaptureDeviceFormat *format in formats) {
NSArray *videoSupportedFrameRateRanges = [format videoSupportedFrameRateRanges];
for (AVFrameRateRange *frameRateRange in videoSupportedFrameRateRanges) {
Expand Down Expand Up @@ -1661,14 +1646,7 @@ - (void)_processImageWithPhotoSampleBuffer:(CMSampleBufferRef)photoSampleBuffer
DLog(@"failed to generate metadata for photo");
}

NSData *jpegData = nil;
if ([AVCapturePhotoOutput class]) {
jpegData = [AVCapturePhotoOutput JPEGPhotoDataRepresentationForJPEGSampleBuffer:photoSampleBuffer previewPhotoSampleBuffer:previewSampleBuffer];
}
else {
jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:photoSampleBuffer];
}

NSData *jpegData = [AVCapturePhotoOutput JPEGPhotoDataRepresentationForJPEGSampleBuffer:photoSampleBuffer previewPhotoSampleBuffer:previewSampleBuffer];
if (jpegData) {
// add JPEG
photoDict[PBJVisionPhotoJPEGKey] = jpegData;
Expand Down Expand Up @@ -1710,20 +1688,18 @@ - (void)capturePhoto
AVCaptureConnection *connection = [_currentOutput connectionWithMediaType:AVMediaTypeVideo];
[self _setOrientationForConnection:connection];

if ([AVCapturePhotoOutput class]) {
AVCapturePhotoSettings *settings = [AVCapturePhotoSettings photoSettingsWithFormat:@{AVVideoCodecKey : AVVideoCodecJPEG}];
settings.highResolutionPhotoEnabled = YES;
settings.flashMode = [self isFlashAvailable] ? (AVCaptureFlashMode)self.flashMode : AVCaptureFlashModeOff;

[_captureOutputPhoto capturePhotoWithSettings:settings delegate:self];
}
AVCapturePhotoSettings *settings = [AVCapturePhotoSettings photoSettingsWithFormat:@{AVVideoCodecKey : AVVideoCodecJPEG}];
settings.highResolutionPhotoEnabled = YES;
settings.flashMode = [self isFlashAvailable] ? (AVCaptureFlashMode)self.flashMode : AVCaptureFlashModeOff;

[_captureOutputPhoto capturePhotoWithSettings:settings delegate:self];
}

#pragma mark - video

- (BOOL)supportsVideoCapture
{
return ([[AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo] count] > 0);
return [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] != NULL;
}

- (BOOL)canCaptureVideo
Expand Down

0 comments on commit 3c46436

Please sign in to comment.