2014 snapchat source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB

  1. //
  2. // SCExposureState.m
  3. // Snapchat
  4. //
  5. // Created by Derek Peirce on 4/10/17.
  6. // Copyright © 2017 Snapchat, Inc. All rights reserved.
  7. //
  8. #import "SCExposureState.h"
  9. #import "AVCaptureDevice+ConfigurationLock.h"
  10. #import <SCBase/SCMacros.h>
  11. @import AVFoundation;
  12. @implementation SCExposureState {
  13. float _ISO;
  14. CMTime _exposureDuration;
  15. }
  16. - (instancetype)initWithDevice:(AVCaptureDevice *)device
  17. {
  18. if (self = [super init]) {
  19. _ISO = device.ISO;
  20. _exposureDuration = device.exposureDuration;
  21. }
  22. return self;
  23. }
  24. - (void)applyISOAndExposureDurationToDevice:(AVCaptureDevice *)device
  25. {
  26. if ([device isExposureModeSupported:AVCaptureExposureModeCustom]) {
  27. [device runTask:@"set prior exposure"
  28. withLockedConfiguration:^() {
  29. CMTime exposureDuration =
  30. CMTimeClampToRange(_exposureDuration, CMTimeRangeMake(device.activeFormat.minExposureDuration,
  31. device.activeFormat.maxExposureDuration));
  32. [device setExposureModeCustomWithDuration:exposureDuration
  33. ISO:SC_CLAMP(_ISO, device.activeFormat.minISO,
  34. device.activeFormat.maxISO)
  35. completionHandler:nil];
  36. }];
  37. }
  38. }
  39. @end