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.

85 lines
3.0 KiB

  1. //
  2. // SCManagedStillImageCapturerHandler.m
  3. // Snapchat
  4. //
  5. // Created by Jingtian Yang on 11/12/2017.
  6. //
  7. #import "SCManagedStillImageCapturerHandler.h"
  8. #import "SCCaptureResource.h"
  9. #import "SCManagedCaptureDevice+SCManagedCapturer.h"
  10. #import "SCManagedCapturer.h"
  11. #import "SCManagedCapturerLogging.h"
  12. #import "SCManagedCapturerSampleMetadata.h"
  13. #import "SCManagedCapturerState.h"
  14. #import <SCFoundation/SCAssertWrapper.h>
  15. #import <SCFoundation/SCQueuePerformer.h>
  16. #import <SCFoundation/SCThreadHelpers.h>
  17. #import <SCFoundation/SCTraceODPCompatible.h>
  18. @interface SCManagedStillImageCapturerHandler () {
  19. __weak SCCaptureResource *_captureResource;
  20. }
  21. @end
  22. @implementation SCManagedStillImageCapturerHandler
  23. - (instancetype)initWithCaptureResource:(SCCaptureResource *)captureResource
  24. {
  25. self = [super init];
  26. if (self) {
  27. SCAssert(captureResource, @"");
  28. _captureResource = captureResource;
  29. }
  30. return self;
  31. }
  32. - (void)managedStillImageCapturerWillCapturePhoto:(SCManagedStillImageCapturer *)managedStillImageCapturer
  33. {
  34. SCTraceODPCompatibleStart(2);
  35. SCLogCapturerInfo(@"Will capture photo. stillImageCapturer:%@", _captureResource.stillImageCapturer);
  36. [_captureResource.queuePerformer performImmediatelyIfCurrentPerformer:^{
  37. SCTraceStart();
  38. if (_captureResource.stillImageCapturer) {
  39. SCManagedCapturerState *state = [_captureResource.state copy];
  40. SCManagedCapturerSampleMetadata *sampleMetadata = [[SCManagedCapturerSampleMetadata alloc]
  41. initWithPresentationTimestamp:kCMTimeZero
  42. fieldOfView:_captureResource.device.fieldOfView];
  43. runOnMainThreadAsynchronously(^{
  44. [_captureResource.announcer managedCapturer:[SCManagedCapturer sharedInstance]
  45. willCapturePhoto:state
  46. sampleMetadata:sampleMetadata];
  47. });
  48. }
  49. }];
  50. }
  51. - (void)managedStillImageCapturerDidCapturePhoto:(SCManagedStillImageCapturer *)managedStillImageCapturer
  52. {
  53. SCTraceODPCompatibleStart(2);
  54. SCLogCapturerInfo(@"Did capture photo. stillImageCapturer:%@", _captureResource.stillImageCapturer);
  55. [_captureResource.queuePerformer performImmediatelyIfCurrentPerformer:^{
  56. SCTraceStart();
  57. if (_captureResource.stillImageCapturer) {
  58. SCManagedCapturerState *state = [_captureResource.state copy];
  59. runOnMainThreadAsynchronously(^{
  60. [_captureResource.announcer managedCapturer:[SCManagedCapturer sharedInstance] didCapturePhoto:state];
  61. });
  62. }
  63. }];
  64. }
  65. - (BOOL)managedStillImageCapturerIsUnderDeviceMotion:(SCManagedStillImageCapturer *)managedStillImageCapturer
  66. {
  67. return _captureResource.deviceMotionProvider.isUnderDeviceMotion;
  68. }
  69. - (BOOL)managedStillImageCapturerShouldProcessFileInput:(SCManagedStillImageCapturer *)managedStillImageCapturer
  70. {
  71. return _captureResource.fileInputDecider.shouldProcessFileInput;
  72. }
  73. @end