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.

83 lines
2.3 KiB

  1. //
  2. // SCSnapCreationTriggers.m
  3. // Snapchat
  4. //
  5. // Created by Cheng Jiang on 3/30/18.
  6. //
  7. #import "SCSnapCreationTriggers.h"
  8. #import "SCContextAwareSnapCreationThrottleRequest.h"
  9. #import <SCBase/SCMacros.h>
  10. #import <SCFoundation/SCContextAwareThrottleRequester.h>
  11. #import <SCFoundation/SCLog.h>
  12. #import <SCFoundation/SCQueuePerformer.h>
  13. @implementation SCSnapCreationTriggers {
  14. BOOL _snapCreationStarted;
  15. BOOL _previewAnimationFinished;
  16. BOOL _previewImageSetupFinished;
  17. BOOL _previewVideoFirstFrameRendered;
  18. }
  19. - (void)markSnapCreationStart
  20. {
  21. SC_GUARD_ELSE_RUN_AND_RETURN(
  22. !_snapCreationStarted,
  23. SCLogCoreCameraWarning(@"markSnapCreationStart skipped because previous SnapCreation session is not complete"));
  24. @synchronized(self)
  25. {
  26. _snapCreationStarted = YES;
  27. }
  28. [[SCContextAwareThrottleRequester shared] submitSuspendRequest:[SCContextAwareSnapCreationThrottleRequest new]];
  29. }
  30. - (void)markSnapCreationPreviewAnimationFinish
  31. {
  32. @synchronized(self)
  33. {
  34. _previewAnimationFinished = YES;
  35. if (_previewImageSetupFinished || _previewVideoFirstFrameRendered) {
  36. [self markSnapCreationEndWithContext:@"markSnapCreationPreviewAnimationFinish"];
  37. }
  38. }
  39. }
  40. - (void)markSnapCreationPreviewImageSetupFinish
  41. {
  42. @synchronized(self)
  43. {
  44. _previewImageSetupFinished = YES;
  45. if (_previewAnimationFinished) {
  46. [self markSnapCreationEndWithContext:@"markSnapCreationPreviewImageSetupFinish"];
  47. }
  48. }
  49. }
  50. - (void)markSnapCreationPreviewVideoFirstFrameRenderFinish
  51. {
  52. @synchronized(self)
  53. {
  54. _previewVideoFirstFrameRendered = YES;
  55. if (_previewAnimationFinished) {
  56. [self markSnapCreationEndWithContext:@"markSnapCreationPreviewVideoFirstFrameRenderFinish"];
  57. }
  58. }
  59. }
  60. - (void)markSnapCreationEndWithContext:(NSString *)context
  61. {
  62. SC_GUARD_ELSE_RETURN(_snapCreationStarted);
  63. SCLogCoreCameraInfo(@"markSnapCreationEnd triggered with context: %@", context);
  64. @synchronized(self)
  65. {
  66. _snapCreationStarted = NO;
  67. _previewAnimationFinished = NO;
  68. _previewImageSetupFinished = NO;
  69. _previewVideoFirstFrameRendered = NO;
  70. }
  71. [[SCContextAwareThrottleRequester shared] submitResumeRequest:[SCContextAwareSnapCreationThrottleRequest new]];
  72. }
  73. @end