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.

85 lines
3.0 KiB

  1. //
  2. // SCCaptureImageWhileRecordingState.m
  3. // Snapchat
  4. //
  5. // Created by Sun Lei on 22/02/2018.
  6. //
  7. #import "SCCaptureImageWhileRecordingState.h"
  8. #import "SCCaptureImageWhileRecordingStateTransitionPayload.h"
  9. #import "SCManagedCapturerV1_Private.h"
  10. #import <SCFoundation/SCAssertWrapper.h>
  11. #import <SCFoundation/SCQueuePerformer.h>
  12. @interface SCCaptureImageWhileRecordingState () {
  13. __weak id<SCCaptureStateDelegate> _delegate;
  14. SCQueuePerformer *_performer;
  15. }
  16. @end
  17. @implementation SCCaptureImageWhileRecordingState
  18. - (instancetype)initWithPerformer:(SCQueuePerformer *)performer
  19. bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
  20. delegate:(id<SCCaptureStateDelegate>)delegate
  21. {
  22. self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
  23. if (self) {
  24. _delegate = delegate;
  25. _performer = performer;
  26. }
  27. return self;
  28. }
  29. - (SCCaptureStateMachineStateId)stateId
  30. {
  31. return SCCaptureImageWhileRecordingStateId;
  32. }
  33. - (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
  34. resource:(SCCaptureResource *)resource
  35. context:(NSString *)context
  36. {
  37. SCAssertPerformer(_performer);
  38. SCAssert(payload.fromState == SCCaptureRecordingStateId, @"");
  39. SCAssert(payload.toState == [self stateId], @"");
  40. SCAssert([payload isKindOfClass:[SCCaptureImageWhileRecordingStateTransitionPayload class]], @"");
  41. ;
  42. SCCaptureImageWhileRecordingStateTransitionPayload *captureImagePayload =
  43. (SCCaptureImageWhileRecordingStateTransitionPayload *)payload;
  44. @weakify(self);
  45. sc_managed_capturer_capture_still_image_completion_handler_t block =
  46. ^(UIImage *fullScreenImage, NSDictionary *metadata, NSError *error, SCManagedCapturerState *state) {
  47. captureImagePayload.block(fullScreenImage, metadata, error, state);
  48. [_performer perform:^{
  49. @strongify(self);
  50. [self _cancelRecordingWithContext:context resource:resource];
  51. }];
  52. };
  53. [SCCaptureWorker
  54. captureStillImageWithCaptureResource:resource
  55. aspectRatio:captureImagePayload.aspectRatio
  56. captureSessionID:captureImagePayload.captureSessionID
  57. shouldCaptureFromVideo:[SCCaptureWorker shouldCaptureImageFromVideoWithResource:resource]
  58. completionHandler:block
  59. context:context];
  60. [_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
  61. }
  62. - (void)_cancelRecordingWithContext:(NSString *)context resource:(SCCaptureResource *)resource
  63. {
  64. SCTraceODPCompatibleStart(2);
  65. SCAssertPerformer(_performer);
  66. [SCCaptureWorker cancelRecordingWithCaptureResource:resource];
  67. NSString *apiName =
  68. [NSString sc_stringWithFormat:@"%@/%@", NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
  69. [self.bookKeeper logAPICalled:apiName context:context];
  70. }
  71. @end