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.

103 lines
4.5 KiB

  1. //
  2. // SCCaptureBaseState.h
  3. // Snapchat
  4. //
  5. // Created by Lin Jia on 10/19/17.
  6. //
  7. //
  8. #import "SCCaptureCommon.h"
  9. #import "SCCaptureStateDelegate.h"
  10. #import "SCCaptureStateMachineBookKeeper.h"
  11. #import "SCCaptureStateUtil.h"
  12. #import "SCCaptureWorker.h"
  13. #import "SCManagedCaptureDevice.h"
  14. #import "SCManagedCapturerState.h"
  15. #import "SCStateTransitionPayload.h"
  16. #import <Foundation/Foundation.h>
  17. @class SCCaptureResource;
  18. @class SCCapturerToken;
  19. @class SCAudioConfiguration;
  20. @class SCQueuePerformer;
  21. /*
  22. Every state machine state needs to inherent SCCaptureBaseState to have the APIs. State machine state in general will
  23. only implement APIs which are legal for itself. If illegal APIs are invoked, SCCaptureBaseState will handle it.
  24. The intended behavior:
  25. 1) crash using SCAssert in Debug build,
  26. 2) ignore api call, and log the call, for alpha/master/production.
  27. 3) in the future, we will introduce dangerous API call concept, and restart camera in such case, to avoid bad state.
  28. Every state machine state is going to be built to follow functional programming as more as possible. The shared
  29. resources between them will be passed into the API via SCCaptureResource.
  30. */
  31. @interface SCCaptureBaseState : NSObject
  32. - (instancetype)init NS_UNAVAILABLE;
  33. - (instancetype)initWithPerformer:(SCQueuePerformer *)performer
  34. bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
  35. delegate:(id<SCCaptureStateDelegate>)delegate;
  36. /* The following API will be invoked at the moment state context promote the state to be current state. State use this
  37. * chance to do something, such as start recording for recording state.
  38. */
  39. - (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
  40. resource:(SCCaptureResource *)resource
  41. context:(NSString *)context;
  42. - (SCCaptureStateMachineStateId)stateId;
  43. - (void)initializeCaptureWithDevicePosition:(SCManagedCaptureDevicePosition)devicePosition
  44. resource:(SCCaptureResource *)resource
  45. completionHandler:(dispatch_block_t)completionHandler
  46. context:(NSString *)context;
  47. - (void)startRunningWithCapturerToken:(SCCapturerToken *)token
  48. resource:(SCCaptureResource *)resource
  49. completionHandler:(dispatch_block_t)completionHandler
  50. context:(NSString *)context;
  51. - (void)stopRunningWithCapturerToken:(SCCapturerToken *)token
  52. resource:(SCCaptureResource *)resource
  53. completionHandler:(sc_managed_capturer_stop_running_completion_handler_t)completionHandler
  54. context:(NSString *)context;
  55. - (void)prepareForRecordingWithResource:(SCCaptureResource *)resource
  56. audioConfiguration:(SCAudioConfiguration *)configuration
  57. context:(NSString *)context;
  58. - (void)startRecordingWithResource:(SCCaptureResource *)resource
  59. audioConfiguration:(SCAudioConfiguration *)configuration
  60. outputSettings:(SCManagedVideoCapturerOutputSettings *)outputSettings
  61. maxDuration:(NSTimeInterval)maxDuration
  62. fileURL:(NSURL *)fileURL
  63. captureSessionID:(NSString *)captureSessionID
  64. completionHandler:(sc_managed_capturer_start_recording_completion_handler_t)completionHandler
  65. context:(NSString *)context;
  66. - (void)stopRecordingWithResource:(SCCaptureResource *)resource context:(NSString *)context;
  67. - (void)cancelRecordingWithResource:(SCCaptureResource *)resource context:(NSString *)context;
  68. - (void)captureStillImageWithResource:(SCCaptureResource *)resource
  69. aspectRatio:(CGFloat)aspectRatio
  70. captureSessionID:(NSString *)captureSessionID
  71. completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)completionHandler
  72. context:(NSString *)context;
  73. - (void)startScanWithScanConfiguration:(SCScanConfiguration *)configuration
  74. resource:(SCCaptureResource *)resource
  75. context:(NSString *)context;
  76. - (void)stopScanWithCompletionHandler:(dispatch_block_t)completionHandler
  77. resource:(SCCaptureResource *)resource
  78. context:(NSString *)context;
  79. @property (nonatomic, strong, readonly) SCCaptureStateMachineBookKeeper *bookKeeper;
  80. @end