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.

77 lines
2.7 KiB

  1. //
  2. // SCManagedCaptureDeviceHandler.m
  3. // Snapchat
  4. //
  5. // Created by Jiyang Zhu on 3/8/18.
  6. // Copyright © 2018 Snapchat, Inc. All rights reserved.
  7. //
  8. #import "SCManagedCaptureDeviceHandler.h"
  9. #import "SCCaptureResource.h"
  10. #import "SCManagedCapturer.h"
  11. #import "SCManagedCapturerLogging.h"
  12. #import "SCManagedCapturerState.h"
  13. #import "SCManagedCapturerStateBuilder.h"
  14. #import <SCFoundation/SCAssertWrapper.h>
  15. #import <SCFoundation/SCQueuePerformer.h>
  16. #import <SCFoundation/SCThreadHelpers.h>
  17. #import <SCFoundation/SCTraceODPCompatible.h>
  18. @interface SCManagedCaptureDeviceHandler ()
  19. @property (nonatomic, weak) SCCaptureResource *captureResource;
  20. @end
  21. @implementation SCManagedCaptureDeviceHandler
  22. - (instancetype)initWithCaptureResource:(SCCaptureResource *)captureResource
  23. {
  24. self = [super init];
  25. if (self) {
  26. SCAssert(captureResource, @"SCCaptureResource should not be nil.");
  27. _captureResource = captureResource;
  28. }
  29. return self;
  30. }
  31. - (void)managedCaptureDevice:(SCManagedCaptureDevice *)device didChangeAdjustingExposure:(BOOL)adjustingExposure
  32. {
  33. SC_GUARD_ELSE_RETURN(device == _captureResource.device);
  34. SCTraceODPCompatibleStart(2);
  35. SCLogCapturerInfo(@"KVO Changes adjustingExposure %d", adjustingExposure);
  36. [_captureResource.queuePerformer perform:^{
  37. _captureResource.state = [[[SCManagedCapturerStateBuilder withManagedCapturerState:_captureResource.state]
  38. setAdjustingExposure:adjustingExposure] build];
  39. SCManagedCapturerState *state = [_captureResource.state copy];
  40. runOnMainThreadAsynchronously(^{
  41. [_captureResource.announcer managedCapturer:[SCManagedCapturer sharedInstance] didChangeState:state];
  42. [_captureResource.announcer managedCapturer:[SCManagedCapturer sharedInstance]
  43. didChangeAdjustingExposure:state];
  44. });
  45. }];
  46. }
  47. - (void)managedCaptureDevice:(SCManagedCaptureDevice *)device didChangeExposurePoint:(CGPoint)exposurePoint
  48. {
  49. SC_GUARD_ELSE_RETURN(device == self.captureResource.device);
  50. SCTraceODPCompatibleStart(2);
  51. runOnMainThreadAsynchronously(^{
  52. [self.captureResource.announcer managedCapturer:[SCManagedCapturer sharedInstance]
  53. didChangeExposurePoint:exposurePoint];
  54. });
  55. }
  56. - (void)managedCaptureDevice:(SCManagedCaptureDevice *)device didChangeFocusPoint:(CGPoint)focusPoint
  57. {
  58. SC_GUARD_ELSE_RETURN(device == self.captureResource.device);
  59. SCTraceODPCompatibleStart(2);
  60. runOnMainThreadAsynchronously(^{
  61. [self.captureResource.announcer managedCapturer:[SCManagedCapturer sharedInstance]
  62. didChangeFocusPoint:focusPoint];
  63. });
  64. }
  65. @end