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.

114 lines
4.7 KiB

  1. //
  2. // SCCaptureRecordingState.m
  3. // Snapchat
  4. //
  5. // Created by Jingtian Yang on 12/01/2018.
  6. //
  7. #import "SCCaptureRecordingState.h"
  8. #import "SCCaptureImageWhileRecordingStateTransitionPayload.h"
  9. #import "SCCaptureRecordingStateTransitionPayload.h"
  10. #import "SCManagedCapturerV1_Private.h"
  11. #import "SCStateTransitionPayload.h"
  12. #import <SCFoundation/SCAssertWrapper.h>
  13. #import <SCFoundation/SCQueuePerformer.h>
  14. @interface SCCaptureRecordingState () {
  15. __weak id<SCCaptureStateDelegate> _delegate;
  16. SCQueuePerformer *_performer;
  17. }
  18. @end
  19. @implementation SCCaptureRecordingState
  20. - (instancetype)initWithPerformer:(SCQueuePerformer *)performer
  21. bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
  22. delegate:(id<SCCaptureStateDelegate>)delegate
  23. {
  24. self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
  25. if (self) {
  26. _delegate = delegate;
  27. _performer = performer;
  28. }
  29. return self;
  30. }
  31. - (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
  32. resource:(SCCaptureResource *)resource
  33. context:(NSString *)context
  34. {
  35. SCAssertPerformer(resource.queuePerformer);
  36. SCAssert(payload.toState == [self stateId], @"");
  37. if (![payload isKindOfClass:[SCCaptureRecordingStateTransitionPayload class]]) {
  38. SCAssertFail(@"wrong payload pass in");
  39. [_delegate currentState:self requestToTransferToNewState:payload.fromState payload:nil context:context];
  40. return;
  41. }
  42. SCCaptureRecordingStateTransitionPayload *recordingPayload = (SCCaptureRecordingStateTransitionPayload *)payload;
  43. [SCCaptureWorker startRecordingWithCaptureResource:resource
  44. outputSettings:recordingPayload.outputSettings
  45. audioConfiguration:recordingPayload.configuration
  46. maxDuration:recordingPayload.maxDuration
  47. fileURL:recordingPayload.fileURL
  48. captureSessionID:recordingPayload.captureSessionID
  49. completionHandler:recordingPayload.block];
  50. }
  51. - (void)stopRecordingWithResource:(SCCaptureResource *)resource context:(NSString *)context
  52. {
  53. SCTraceODPCompatibleStart(2);
  54. SCAssertPerformer(_performer);
  55. [SCCaptureWorker stopRecordingWithCaptureResource:resource];
  56. [_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
  57. NSString *apiName =
  58. [NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
  59. [self.bookKeeper logAPICalled:apiName context:context];
  60. }
  61. - (void)cancelRecordingWithResource:(SCCaptureResource *)resource context:(NSString *)context
  62. {
  63. SCTraceODPCompatibleStart(2);
  64. SCAssertPerformer(_performer);
  65. [SCCaptureWorker cancelRecordingWithCaptureResource:resource];
  66. [_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
  67. NSString *apiName =
  68. [NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
  69. [self.bookKeeper logAPICalled:apiName context:context];
  70. }
  71. - (SCCaptureStateMachineStateId)stateId
  72. {
  73. return SCCaptureRecordingStateId;
  74. }
  75. - (void)captureStillImageWithResource:(SCCaptureResource *)resource
  76. aspectRatio:(CGFloat)aspectRatio
  77. captureSessionID:(NSString *)captureSessionID
  78. completionHandler:(sc_managed_capturer_capture_still_image_completion_handler_t)completionHandler
  79. context:(NSString *)context
  80. {
  81. SCAssertPerformer(_performer);
  82. SCCaptureImageWhileRecordingStateTransitionPayload *payload = [
  83. [SCCaptureImageWhileRecordingStateTransitionPayload alloc] initWithFromState:SCCaptureRecordingStateId
  84. toState:SCCaptureImageWhileRecordingStateId
  85. captureSessionId:captureSessionID
  86. aspectRatio:aspectRatio
  87. completionHandler:completionHandler];
  88. [_delegate currentState:self
  89. requestToTransferToNewState:SCCaptureImageWhileRecordingStateId
  90. payload:payload
  91. context:context];
  92. NSString *apiName =
  93. [NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
  94. [self.bookKeeper logAPICalled:apiName context:context];
  95. }
  96. @end