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.

225 lines
11 KiB

  1. //
  2. // SCManagedCapturer.h
  3. // Snapchat
  4. //
  5. // Created by Liu Liu on 4/20/15.
  6. // Copyright (c) 2015 Liu Liu. All rights reserved.
  7. //
  8. #import "SCCaptureCommon.h"
  9. #import "SCSnapCreationTriggers.h"
  10. #import <SCAudio/SCAudioConfiguration.h>
  11. #import <AVFoundation/AVFoundation.h>
  12. #import <Foundation/Foundation.h>
  13. #define SCCapturerContext [NSString sc_stringWithFormat:@"%s/%d", __FUNCTION__, __LINE__]
  14. @class SCBlackCameraDetector;
  15. @protocol SCManagedCapturerListener
  16. , SCManagedCapturerLensAPI, SCDeviceMotionProvider, SCFileInputDecider, SCManagedCapturerARImageCaptureProvider,
  17. SCManagedCapturerGLViewManagerAPI, SCManagedCapturerLensAPIProvider, SCManagedCapturerLSAComponentTrackerAPI,
  18. SCManagedCapturePreviewLayerControllerDelegate;
  19. @protocol SCCapturer <NSObject>
  20. @property (nonatomic, readonly) SCBlackCameraDetector *blackCameraDetector;
  21. /**
  22. * Returns id<SCLensProcessingCore> for the current capturer.
  23. */
  24. - (id<SCManagedCapturerLensAPI>)lensProcessingCore;
  25. - (CMTime)firstWrittenAudioBufferDelay;
  26. - (BOOL)audioQueueStarted;
  27. - (BOOL)isLensApplied;
  28. - (BOOL)isVideoMirrored;
  29. - (SCVideoCaptureSessionInfo)activeSession;
  30. #pragma mark - Outside resources
  31. - (void)setBlackCameraDetector:(SCBlackCameraDetector *)blackCameraDetector
  32. deviceMotionProvider:(id<SCDeviceMotionProvider>)deviceMotionProvider
  33. fileInputDecider:(id<SCFileInputDecider>)fileInputDecider
  34. arImageCaptureProvider:(id<SCManagedCapturerARImageCaptureProvider>)arImageCaptureProvider
  35. glviewManager:(id<SCManagedCapturerGLViewManagerAPI>)glViewManager
  36. lensAPIProvider:(id<SCManagedCapturerLensAPIProvider>)lensAPIProvider
  37. lsaComponentTracker:(id<SCManagedCapturerLSAComponentTrackerAPI>)lsaComponentTracker
  38. managedCapturerPreviewLayerControllerDelegate:
  39. (id<SCManagedCapturePreviewLayerControllerDelegate>)previewLayerControllerDelegate;
  40. #pragma mark - Setup, Start & Stop
  41. // setupWithDevicePositionAsynchronously will be called on the main thread, executed off the main thread, exactly once
  42. - (void)setupWithDevicePositionAsynchronously:(SCManagedCaptureDevicePosition)devicePosition
  43. completionHandler:(dispatch_block_t)completionHandler
  44. context:(NSString *)context;
  45. /**
  46. * Important: Remember to call stopRunningAsynchronously to stop the capture session. Dismissing the view is not enough
  47. * @param identifier is for knowing the callsite. Pass in the classname of the callsite is generally suggested.
  48. * Currently it is used for debugging purposes. In other words the capture session will work without it.
  49. */
  50. - (SCCapturerToken *)startRunningAsynchronouslyWithCompletionHandler:(dispatch_block_t)completionHandler
  51. context:(NSString *)context;
  52. - (void)stopRunningAsynchronously:(SCCapturerToken *)token
  53. completionHandler:(sc_managed_capturer_stop_running_completion_handler_t)completionHandler
  54. context:(NSString *)context;
  55. - (void)stopRunningAsynchronously:(SCCapturerToken *)token
  56. completionHandler:(sc_managed_capturer_stop_running_completion_handler_t)completionHandler
  57. after:(NSTimeInterval)delay
  58. context:(NSString *)context;
  59. - (void)startStreamingAsynchronouslyWithCompletionHandler:(dispatch_block_t)completionHandler
  60. context:(NSString *)context;
  61. - (void)addSampleBufferDisplayController:(id<SCManagedSampleBufferDisplayController>)sampleBufferDisplayController
  62. context:(NSString *)context;
  63. #pragma mark - Recording / Capture
  64. - (void)captureStillImageAsynchronouslyWithAspectRatio:(CGFloat)aspectRatio
  65. captureSessionID:(NSString *)captureSessionID
  66. completionHandler:
  67. (sc_managed_capturer_capture_still_image_completion_handler_t)completionHandler
  68. context:(NSString *)context;
  69. /**
  70. * Unlike captureStillImageAsynchronouslyWithAspectRatio, this captures a single frame from the ongoing video
  71. * stream. This should be faster but lower quality (and smaller size), and does not play the shutter sound.
  72. */
  73. - (void)captureSingleVideoFrameAsynchronouslyWithCompletionHandler:
  74. (sc_managed_capturer_capture_video_frame_completion_handler_t)completionHandler
  75. context:(NSString *)context;
  76. - (void)prepareForRecordingAsynchronouslyWithContext:(NSString *)context
  77. audioConfiguration:(SCAudioConfiguration *)configuration;
  78. - (void)startRecordingAsynchronouslyWithOutputSettings:(SCManagedVideoCapturerOutputSettings *)outputSettings
  79. audioConfiguration:(SCAudioConfiguration *)configuration
  80. maxDuration:(NSTimeInterval)maxDuration
  81. fileURL:(NSURL *)fileURL
  82. captureSessionID:(NSString *)captureSessionID
  83. completionHandler:
  84. (sc_managed_capturer_start_recording_completion_handler_t)completionHandler
  85. context:(NSString *)context;
  86. - (void)stopRecordingAsynchronouslyWithContext:(NSString *)context;
  87. - (void)cancelRecordingAsynchronouslyWithContext:(NSString *)context;
  88. - (void)startScanAsynchronouslyWithScanConfiguration:(SCScanConfiguration *)configuration context:(NSString *)context;
  89. - (void)stopScanAsynchronouslyWithCompletionHandler:(dispatch_block_t)completionHandler context:(NSString *)context;
  90. - (void)sampleFrameWithCompletionHandler:(void (^)(UIImage *frame, CMTime presentationTime))completionHandler
  91. context:(NSString *)context;
  92. // AddTimedTask will schedule a task to run, it is thread safe API. Your task will run on main thread, so it is not
  93. // recommended to add large amount of tasks which all have the same task target time.
  94. - (void)addTimedTask:(SCTimedTask *)task context:(NSString *)context;
  95. // clearTimedTasks will cancel the tasks, it is thread safe API.
  96. - (void)clearTimedTasksWithContext:(NSString *)context;
  97. #pragma mark - Utilities
  98. - (void)convertViewCoordinates:(CGPoint)viewCoordinates
  99. completionHandler:(sc_managed_capturer_convert_view_coordniates_completion_handler_t)completionHandler
  100. context:(NSString *)context;
  101. - (void)detectLensCategoryOnNextFrame:(CGPoint)point
  102. lenses:(NSArray<SCLens *> *)lenses
  103. completion:(sc_managed_lenses_processor_category_point_completion_handler_t)completion
  104. context:(NSString *)context;
  105. #pragma mark - Configurations
  106. - (void)setDevicePositionAsynchronously:(SCManagedCaptureDevicePosition)devicePosition
  107. completionHandler:(dispatch_block_t)completionHandler
  108. context:(NSString *)context;
  109. - (void)setFlashActive:(BOOL)flashActive
  110. completionHandler:(dispatch_block_t)completionHandler
  111. context:(NSString *)context;
  112. - (void)setLensesActive:(BOOL)lensesActive
  113. completionHandler:(dispatch_block_t)completionHandler
  114. context:(NSString *)context;
  115. - (void)setLensesActive:(BOOL)lensesActive
  116. filterFactory:(SCLookseryFilterFactory *)filterFactory
  117. completionHandler:(dispatch_block_t)completionHandler
  118. context:(NSString *)context;
  119. - (void)setLensesInTalkActive:(BOOL)lensesActive
  120. completionHandler:(dispatch_block_t)completionHandler
  121. context:(NSString *)context;
  122. - (void)setTorchActiveAsynchronously:(BOOL)torchActive
  123. completionHandler:(dispatch_block_t)completionHandler
  124. context:(NSString *)context;
  125. - (void)setNightModeActiveAsynchronously:(BOOL)active
  126. completionHandler:(dispatch_block_t)completionHandler
  127. context:(NSString *)context;
  128. - (void)lockZoomWithContext:(NSString *)context;
  129. - (void)unlockZoomWithContext:(NSString *)context;
  130. - (void)setZoomFactorAsynchronously:(CGFloat)zoomFactor context:(NSString *)context;
  131. - (void)resetZoomFactorAsynchronously:(CGFloat)zoomFactor
  132. devicePosition:(SCManagedCaptureDevicePosition)devicePosition
  133. context:(NSString *)context;
  134. - (void)setExposurePointOfInterestAsynchronously:(CGPoint)pointOfInterest
  135. fromUser:(BOOL)fromUser
  136. completionHandler:(dispatch_block_t)completionHandler
  137. context:(NSString *)context;
  138. - (void)setAutofocusPointOfInterestAsynchronously:(CGPoint)pointOfInterest
  139. completionHandler:(dispatch_block_t)completionHandler
  140. context:(NSString *)context;
  141. - (void)setPortraitModePointOfInterestAsynchronously:(CGPoint)pointOfInterest
  142. completionHandler:(dispatch_block_t)completionHandler
  143. context:(NSString *)context;
  144. - (void)continuousAutofocusAndExposureAsynchronouslyWithCompletionHandler:(dispatch_block_t)completionHandler
  145. context:(NSString *)context;
  146. // I need to call these three methods from SCAppDelegate explicitly so that I get the latest information.
  147. - (void)applicationDidEnterBackground;
  148. - (void)applicationWillEnterForeground;
  149. - (void)applicationDidBecomeActive;
  150. - (void)applicationWillResignActive;
  151. - (void)mediaServicesWereReset;
  152. - (void)mediaServicesWereLost;
  153. #pragma mark - Add / Remove Listener
  154. - (void)addListener:(id<SCManagedCapturerListener>)listener;
  155. - (void)removeListener:(id<SCManagedCapturerListener>)listener;
  156. - (void)addVideoDataSourceListener:(id<SCManagedVideoDataSourceListener>)listener;
  157. - (void)removeVideoDataSourceListener:(id<SCManagedVideoDataSourceListener>)listener;
  158. - (void)addDeviceCapacityAnalyzerListener:(id<SCManagedDeviceCapacityAnalyzerListener>)listener;
  159. - (void)removeDeviceCapacityAnalyzerListener:(id<SCManagedDeviceCapacityAnalyzerListener>)listener;
  160. - (NSString *)debugInfo;
  161. - (id<SCManagedVideoDataSource>)currentVideoDataSource;
  162. - (void)checkRestrictedCamera:(void (^)(BOOL, BOOL, AVAuthorizationStatus))callback;
  163. // Need to be visible so that classes like SCCaptureSessionFixer can manage capture session
  164. - (void)recreateAVCaptureSession;
  165. #pragma mark - Snap Creation triggers
  166. - (SCSnapCreationTriggers *)snapCreationTriggers;
  167. @optional
  168. - (BOOL)authorizedForVideoCapture;
  169. - (void)preloadVideoCaptureAuthorization;
  170. @end