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.

233 lines
7.5 KiB

  1. //
  2. // SCCaptureResource.h
  3. // Snapchat
  4. //
  5. // Created by Lin Jia on 10/19/17.
  6. //
  7. //
  8. #import "SCManagedCapturerLensAPI.h"
  9. #import "SCManagedCapturerListenerAnnouncer.h"
  10. #import "SCSnapCreationTriggers.h"
  11. #import <SCCameraFoundation/SCManagedVideoDataSource.h>
  12. #import <FBKVOController/FBKVOController.h>
  13. #import <Foundation/Foundation.h>
  14. /*
  15. In general, the function of SCCapturer is to use some resources (such as SCManagedCapturerListenerAnnouncer), to do
  16. something (such as announce an event).
  17. SCCaptureResource abstract away the "resources" part of SCCapturer. It has no APIs itself, it is used to be the
  18. resource which gets passed arround for capturer V2 state machine.
  19. */
  20. @class SCManagedDeviceCapacityAnalyzer;
  21. @class SCManagedCapturePreviewLayerController;
  22. @class ARSession;
  23. @class SCManagedVideoScanner;
  24. @class LSAGLView;
  25. @protocol SCManagedCapturerLSAComponentTrackerAPI;
  26. @class SCManagedStillImageCapturer;
  27. @class SCManagedVideoCapturer;
  28. @class SCQueuePerformer;
  29. @class SCManagedVideoFrameSampler;
  30. @class SCManagedDroppedFramesReporter;
  31. @class SCManagedVideoStreamReporter;
  32. @protocol SCManagedCapturerGLViewManagerAPI;
  33. @class SCCapturerToken;
  34. @class SCSingleFrameStreamCapturer;
  35. @class SCManagedFrontFlashController;
  36. @class SCManagedVideoCapturerHandler;
  37. @class SCManagedStillImageCapturerHandler;
  38. @class SCManagedDeviceCapacityAnalyzerHandler;
  39. @class SCManagedCaptureDeviceDefaultZoomHandler;
  40. @class SCManagedCaptureDeviceHandler;
  41. @class SCBlackCameraNoOutputDetector;
  42. @class SCCaptureSessionFixer;
  43. @protocol SCCaptureFaceDetector;
  44. @protocol SCManagedCapturerLensAPI;
  45. @protocol SCManagedCapturerARImageCaptureProvider;
  46. @class SCManagedCapturerARSessionHandler;
  47. @class SCManagedCaptureDeviceSubjectAreaHandler;
  48. @class SCManagedCaptureSession;
  49. @class SCBlackCameraDetector;
  50. @protocol SCLensProcessingCore;
  51. @protocol SCManagedCapturerLensAPI;
  52. @protocol SCManagedCapturePreviewLayerControllerDelegate;
  53. typedef enum : NSUInteger {
  54. SCManagedCapturerStatusUnknown = 0,
  55. SCManagedCapturerStatusReady,
  56. SCManagedCapturerStatusRunning,
  57. } SCManagedCapturerStatus;
  58. @protocol SCDeviceMotionProvider
  59. @property (nonatomic, readonly) BOOL isUnderDeviceMotion;
  60. @end
  61. @protocol SCFileInputDecider
  62. @property (nonatomic, readonly) BOOL shouldProcessFileInput;
  63. @property (nonatomic, readonly) NSURL *fileURL;
  64. @end
  65. @interface SCCaptureResource : NSObject
  66. @property (nonatomic, readwrite, assign) SCManagedCapturerStatus status;
  67. @property (nonatomic, readwrite, strong) SCManagedCapturerState *state;
  68. @property (nonatomic, readwrite, strong) SCManagedCaptureDevice *device;
  69. @property (nonatomic, readwrite, strong) id<SCManagedCapturerLensAPI> lensProcessingCore;
  70. @property (nonatomic, readwrite, strong) id<SCManagedCapturerLensAPIProvider> lensAPIProvider;
  71. @property (nonatomic, readwrite, strong) ARSession *arSession NS_AVAILABLE_IOS(11_0);
  72. @property (nonatomic, readwrite, strong) SCManagedStillImageCapturer *arImageCapturer NS_AVAILABLE_IOS(11_0);
  73. @property (nonatomic, readwrite, strong) SCManagedCaptureSession *managedSession;
  74. @property (nonatomic, readwrite, strong) id<SCManagedVideoDataSource> videoDataSource;
  75. @property (nonatomic, readwrite, strong) SCManagedDeviceCapacityAnalyzer *deviceCapacityAnalyzer;
  76. @property (nonatomic, readwrite, strong) SCManagedVideoScanner *videoScanner;
  77. @property (nonatomic, readwrite, strong) SCManagedCapturerListenerAnnouncer *announcer;
  78. @property (nonatomic, readwrite, strong) AVCaptureVideoPreviewLayer *videoPreviewLayer;
  79. @property (nonatomic, readwrite, strong) id<SCManagedCapturerGLViewManagerAPI> videoPreviewGLViewManager;
  80. @property (nonatomic, readwrite, strong) SCManagedStillImageCapturer *stillImageCapturer;
  81. @property (nonatomic, readwrite, strong) SCManagedVideoCapturer *videoCapturer;
  82. @property (nonatomic, readwrite, strong) SCQueuePerformer *queuePerformer;
  83. @property (nonatomic, readwrite, strong) SCManagedVideoFrameSampler *videoFrameSampler;
  84. @property (nonatomic, readwrite, strong) SCManagedDroppedFramesReporter *droppedFramesReporter;
  85. @property (nonatomic, readwrite, strong) SCManagedVideoStreamReporter *videoStreamReporter; // INTERNAL USE ONLY
  86. @property (nonatomic, readwrite, strong) SCManagedFrontFlashController *frontFlashController;
  87. @property (nonatomic, readwrite, strong) SCManagedVideoCapturerHandler *videoCapturerHandler;
  88. @property (nonatomic, readwrite, strong) SCManagedStillImageCapturerHandler *stillImageCapturerHandler;
  89. @property (nonatomic, readwrite, strong) SCManagedDeviceCapacityAnalyzerHandler *deviceCapacityAnalyzerHandler;
  90. @property (nonatomic, readwrite, strong) SCManagedCaptureDeviceDefaultZoomHandler *deviceZoomHandler;
  91. @property (nonatomic, readwrite, strong) SCManagedCaptureDeviceHandler *captureDeviceHandler;
  92. @property (nonatomic, readwrite, strong) id<SCCaptureFaceDetector> captureFaceDetector;
  93. @property (nonatomic, readwrite, strong) FBKVOController *kvoController;
  94. @property (nonatomic, readwrite, strong) id<SCManagedCapturerLSAComponentTrackerAPI> lsaTrackingComponentHandler;
  95. @property (nonatomic, readwrite, strong) SCManagedCapturerARSessionHandler *arSessionHandler;
  96. @property (nonatomic, assign) SEL completeARSessionShutdown;
  97. @property (nonatomic, assign) SEL handleAVSessionStatusChange;
  98. @property (nonatomic, assign) BOOL videoRecording;
  99. @property (nonatomic, assign) NSInteger numRetriesFixAVCaptureSessionWithCurrentSession;
  100. @property (nonatomic, assign) BOOL appInBackground;
  101. @property (nonatomic, assign) NSUInteger streamingSequence;
  102. @property (nonatomic, assign) BOOL stillImageCapturing;
  103. @property (nonatomic, readwrite, strong) NSTimer *livenessTimer;
  104. @property (nonatomic, readwrite, strong) NSMutableSet<SCCapturerToken *> *tokenSet;
  105. @property (nonatomic, readwrite, strong) SCSingleFrameStreamCapturer *frameCap;
  106. @property (nonatomic, readwrite, strong) id<SCManagedSampleBufferDisplayController> sampleBufferDisplayController;
  107. @property (nonatomic, readwrite, strong) SCSnapCreationTriggers *snapCreationTriggers;
  108. // Different from most properties above, following are main thread properties.
  109. @property (nonatomic, assign) BOOL allowsZoom;
  110. @property (nonatomic, assign) NSUInteger numRetriesFixInconsistencyWithCurrentSession;
  111. @property (nonatomic, readwrite, strong) NSMutableDictionary *debugInfoDict;
  112. @property (nonatomic, assign) BOOL notificationRegistered;
  113. @property (nonatomic, readwrite, strong) SCManagedCaptureDeviceSubjectAreaHandler *deviceSubjectAreaHandler;
  114. @property (nonatomic, assign) SEL sessionRuntimeError;
  115. @property (nonatomic, assign) SEL livenessConsistency;
  116. // TODO: these properties will be refactored into SCCaptureSessionFixer class
  117. // The refactor will be in a separate PR
  118. // Timestamp when _fixAVSessionIfNecessary is called
  119. @property (nonatomic, assign) NSTimeInterval lastFixSessionTimestamp;
  120. // Timestamp when session runtime error is handled
  121. @property (nonatomic, assign) NSTimeInterval lastSessionRuntimeErrorTime;
  122. // Wether we schedule fix of creating session already
  123. @property (nonatomic, assign) BOOL isRecreateSessionFixScheduled;
  124. @property (nonatomic, readwrite, strong) SCCaptureSessionFixer *captureSessionFixer;
  125. @property (nonatomic, readwrite, strong) SCBlackCameraDetector *blackCameraDetector;
  126. @property (nonatomic, readwrite, strong) id<SCDeviceMotionProvider> deviceMotionProvider;
  127. @property (nonatomic, readwrite, strong) id<SCManagedCapturerARImageCaptureProvider> arImageCaptureProvider;
  128. @property (nonatomic, readwrite, strong) id<SCFileInputDecider> fileInputDecider;
  129. @property (nonatomic, readwrite, strong)
  130. id<SCManagedCapturePreviewLayerControllerDelegate> previewLayerControllerDelegate;
  131. @end