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.

67 lines
2.2 KiB

  1. //
  2. // SCManagedCaptureDeviceSubjectAreaHandler.m
  3. // Snapchat
  4. //
  5. // Created by Xiaokang Liu on 19/03/2018.
  6. //
  7. #import "SCManagedCaptureDeviceSubjectAreaHandler.h"
  8. #import "SCCameraTweaks.h"
  9. #import "SCCaptureResource.h"
  10. #import "SCCaptureWorker.h"
  11. #import "SCManagedCaptureDevice+SCManagedCapturer.h"
  12. #import "SCManagedCapturer.h"
  13. #import "SCManagedCapturerState.h"
  14. #import <SCFoundation/SCAssertWrapper.h>
  15. #import <SCFoundation/SCQueuePerformer.h>
  16. @interface SCManagedCaptureDeviceSubjectAreaHandler () {
  17. __weak SCCaptureResource *_captureResource;
  18. }
  19. @end
  20. @implementation SCManagedCaptureDeviceSubjectAreaHandler
  21. - (instancetype)initWithCaptureResource:(SCCaptureResource *)captureResource
  22. {
  23. self = [super init];
  24. if (self) {
  25. SCAssert(captureResource, @"");
  26. _captureResource = captureResource;
  27. }
  28. return self;
  29. }
  30. - (void)stopObserving
  31. {
  32. [[NSNotificationCenter defaultCenter] removeObserver:self
  33. name:AVCaptureDeviceSubjectAreaDidChangeNotification
  34. object:nil];
  35. }
  36. - (void)startObserving
  37. {
  38. [[NSNotificationCenter defaultCenter] addObserver:self
  39. selector:@selector(_subjectAreaDidChange:)
  40. name:AVCaptureDeviceSubjectAreaDidChangeNotification
  41. object:nil];
  42. }
  43. #pragma mark - Private methods
  44. - (void)_subjectAreaDidChange:(NSDictionary *)notification
  45. {
  46. [_captureResource.queuePerformer perform:^{
  47. if (_captureResource.device.isConnected && !_captureResource.state.arSessionActive) {
  48. // Reset to continuous autofocus when the subject area changed
  49. [_captureResource.device continuousAutofocus];
  50. [_captureResource.device setExposurePointOfInterest:CGPointMake(0.5, 0.5) fromUser:NO];
  51. if (SCCameraTweaksEnablePortraitModeAutofocus()) {
  52. [SCCaptureWorker setPortraitModePointOfInterestAsynchronously:CGPointMake(0.5, 0.5)
  53. completionHandler:nil
  54. resource:_captureResource];
  55. }
  56. }
  57. }];
  58. }
  59. @end