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.

176 lines
7.7 KiB

  1. //
  2. // SCCaptureRunningState.m
  3. // Snapchat
  4. //
  5. // Created by Jingtian Yang on 08/01/2018.
  6. //
  7. #import "SCCaptureRunningState.h"
  8. #import "SCCaptureImageStateTransitionPayload.h"
  9. #import "SCCaptureRecordingStateTransitionPayload.h"
  10. #import "SCCaptureWorker.h"
  11. #import "SCManagedCapturerLogging.h"
  12. #import "SCManagedCapturerV1_Private.h"
  13. #import "SCScanConfiguration.h"
  14. #import <SCFoundation/SCAssertWrapper.h>
  15. #import <SCFoundation/SCQueuePerformer.h>
  16. #import <SCFoundation/SCTraceODPCompatible.h>
  17. @interface SCCaptureRunningState () {
  18. __weak id<SCCaptureStateDelegate> _delegate;
  19. SCQueuePerformer *_performer;
  20. }
  21. @end
  22. @implementation SCCaptureRunningState
  23. - (instancetype)initWithPerformer:(SCQueuePerformer *)performer
  24. bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
  25. delegate:(id<SCCaptureStateDelegate>)delegate
  26. {
  27. self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
  28. if (self) {
  29. _delegate = delegate;
  30. _performer = performer;
  31. }
  32. return self;
  33. }
  34. - (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
  35. resource:(SCCaptureResource *)resource
  36. context:(NSString *)context
  37. {
  38. // No op.
  39. }
  40. - (void)captureStillImageWithResource:(SCCaptureResource *)resource
  41. aspectRatio:(CGFloat)aspectRatio
  42. captureSessionID:(NSString *)captureSessionID
  43. completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)completionHandler
  44. context:(NSString *)context
  45. {
  46. SCAssertPerformer(_performer);
  47. SCCaptureImageStateTransitionPayload *payload =
  48. [[SCCaptureImageStateTransitionPayload alloc] initWithFromState:SCCaptureRunningStateId
  49. toState:SCCaptureImageStateId
  50. captureSessionId:captureSessionID
  51. aspectRatio:aspectRatio
  52. completionHandler:completionHandler];
  53. [_delegate currentState:self requestToTransferToNewState:SCCaptureImageStateId payload:payload context:context];
  54. NSString *apiName =
  55. [NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
  56. [self.bookKeeper logAPICalled:apiName context:context];
  57. }
  58. - (SCCaptureStateMachineStateId)stateId
  59. {
  60. return SCCaptureRunningStateId;
  61. }
  62. - (void)startRunningWithCapturerToken:(SCCapturerToken *)token
  63. resource:(SCCaptureResource *)resource
  64. completionHandler:(dispatch_block_t)completionHandler
  65. context:(NSString *)context
  66. {
  67. SCAssertPerformer(_performer);
  68. SCTraceODPCompatibleStart(2);
  69. SCLogCapturerInfo(@"startRunningAsynchronouslyWithCompletionHandler called. token: %@", token);
  70. [SCCaptureWorker startRunningWithCaptureResource:resource token:token completionHandler:completionHandler];
  71. NSString *apiName =
  72. [NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
  73. [self.bookKeeper logAPICalled:apiName context:context];
  74. }
  75. - (void)stopRunningWithCapturerToken:(SCCapturerToken *)token
  76. resource:(SCCaptureResource *)resource
  77. completionHandler:(sc_managed_capturer_stop_running_completion_handler_t)completionHandler
  78. context:(NSString *)context
  79. {
  80. SCTraceODPCompatibleStart(2);
  81. SCAssertPerformer(_performer);
  82. SCLogCapturerInfo(@"Stop running asynchronously. token:%@", token);
  83. if ([[SCManagedCapturerV1 sharedInstance] stopRunningWithCaptureToken:token
  84. completionHandler:completionHandler
  85. context:context]) {
  86. [_delegate currentState:self
  87. requestToTransferToNewState:SCCaptureInitializedStateId
  88. payload:nil
  89. context:context];
  90. }
  91. NSString *apiName =
  92. [NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
  93. [self.bookKeeper logAPICalled:apiName context:context];
  94. }
  95. - (void)startScanWithScanConfiguration:(SCScanConfiguration *)configuration
  96. resource:(SCCaptureResource *)resource
  97. context:(NSString *)context
  98. {
  99. SCTraceODPCompatibleStart(2);
  100. SCLogCapturerInfo(@"Start scan on preview asynchronously. configuration:%@", configuration);
  101. SCAssertPerformer(_performer);
  102. [SCCaptureWorker startScanWithScanConfiguration:configuration resource:resource];
  103. [_delegate currentState:self requestToTransferToNewState:SCCaptureScanningStateId payload:nil context:context];
  104. NSString *apiName =
  105. [NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
  106. [self.bookKeeper logAPICalled:apiName context:context];
  107. }
  108. - (void)prepareForRecordingWithResource:(SCCaptureResource *)resource
  109. audioConfiguration:(SCAudioConfiguration *)configuration
  110. context:(NSString *)context
  111. {
  112. SCAssertPerformer(_performer);
  113. SCTraceODPCompatibleStart(2);
  114. [SCCaptureWorker prepareForRecordingWithAudioConfiguration:configuration resource:resource];
  115. NSString *apiName =
  116. [NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
  117. [self.bookKeeper logAPICalled:apiName context:context];
  118. }
  119. - (void)startRecordingWithResource:(SCCaptureResource *)resource
  120. audioConfiguration:(SCAudioConfiguration *)configuration
  121. outputSettings:(SCManagedVideoCapturerOutputSettings *)outputSettings
  122. maxDuration:(NSTimeInterval)maxDuration
  123. fileURL:(NSURL *)fileURL
  124. captureSessionID:(NSString *)captureSessionID
  125. completionHandler:(sc_managed_capturer_start_recording_completion_handler_t)completionHandler
  126. context:(NSString *)context
  127. {
  128. SCTraceODPCompatibleStart(2);
  129. SCAssertPerformer(_performer);
  130. SCCaptureRecordingStateTransitionPayload *payload =
  131. [[SCCaptureRecordingStateTransitionPayload alloc] initWithFromState:SCCaptureRunningStateId
  132. toState:SCCaptureRecordingStateId
  133. outputSettings:outputSettings
  134. audioConfiguration:configuration
  135. maxDuration:maxDuration
  136. fileURL:fileURL
  137. captureSessionID:captureSessionID
  138. completionHandler:completionHandler];
  139. [_delegate currentState:self requestToTransferToNewState:SCCaptureRecordingStateId payload:payload context:context];
  140. NSString *apiName =
  141. [NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
  142. [self.bookKeeper logAPICalled:apiName context:context];
  143. }
  144. - (void)cancelRecordingWithResource:(SCCaptureResource *)resource context:(NSString *)context
  145. {
  146. // Intentionally No Op, this will be removed once CCAM-13851 gets resolved.
  147. NSString *apiName =
  148. [NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
  149. [self.bookKeeper logAPICalled:apiName context:context];
  150. }
  151. @end