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.

65 lines
2.2 KiB

  1. //
  2. // SCCaptureImageState.m
  3. // Snapchat
  4. //
  5. // Created by Lin Jia on 1/8/18.
  6. //
  7. #import "SCCaptureImageState.h"
  8. #import "SCCaptureImageStateTransitionPayload.h"
  9. #import "SCManagedCapturerV1_Private.h"
  10. #import "SCStateTransitionPayload.h"
  11. #import <SCFoundation/SCAssertWrapper.h>
  12. #import <SCFoundation/SCQueuePerformer.h>
  13. @interface SCCaptureImageState () {
  14. __weak id<SCCaptureStateDelegate> _delegate;
  15. SCQueuePerformer *_performer;
  16. }
  17. @end
  18. @implementation SCCaptureImageState
  19. - (instancetype)initWithPerformer:(SCQueuePerformer *)performer
  20. bookKeeper:(SCCaptureStateMachineBookKeeper *)bookKeeper
  21. delegate:(id<SCCaptureStateDelegate>)delegate
  22. {
  23. self = [super initWithPerformer:performer bookKeeper:bookKeeper delegate:delegate];
  24. if (self) {
  25. _delegate = delegate;
  26. _performer = performer;
  27. }
  28. return self;
  29. }
  30. - (void)didBecomeCurrentState:(SCStateTransitionPayload *)payload
  31. resource:(SCCaptureResource *)resource
  32. context:(NSString *)context
  33. {
  34. SCAssertPerformer(_performer);
  35. SCAssert(payload.toState == [self stateId], @"");
  36. if (![payload isKindOfClass:[SCCaptureImageStateTransitionPayload class]]) {
  37. SCAssertFail(@"wrong payload pass in");
  38. [_delegate currentState:self requestToTransferToNewState:payload.fromState payload:nil context:context];
  39. return;
  40. }
  41. SCCaptureImageStateTransitionPayload *captureImagePayload = (SCCaptureImageStateTransitionPayload *)payload;
  42. [SCCaptureWorker
  43. captureStillImageWithCaptureResource:resource
  44. aspectRatio:captureImagePayload.aspectRatio
  45. captureSessionID:captureImagePayload.captureSessionID
  46. shouldCaptureFromVideo:[SCCaptureWorker shouldCaptureImageFromVideoWithResource:resource]
  47. completionHandler:captureImagePayload.block
  48. context:context];
  49. [_delegate currentState:self requestToTransferToNewState:SCCaptureRunningStateId payload:nil context:context];
  50. }
  51. - (SCCaptureStateMachineStateId)stateId
  52. {
  53. return SCCaptureImageStateId;
  54. }
  55. @end