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.

74 lines
1.5 KiB

  1. //
  2. // SCManagedCaptureSession.m
  3. // Snapchat
  4. //
  5. // Created by Derek Wang on 02/03/2018.
  6. //
  7. #import "SCManagedCaptureSession.h"
  8. #import "SCBlackCameraDetector.h"
  9. #import <SCFoundation/SCTraceODPCompatible.h>
  10. @interface SCManagedCaptureSession () {
  11. SCBlackCameraDetector *_blackCameraDetector;
  12. }
  13. @end
  14. @implementation SCManagedCaptureSession
  15. - (instancetype)initWithBlackCameraDetector:(SCBlackCameraDetector *)detector
  16. {
  17. self = [super init];
  18. if (self) {
  19. _avSession = [[AVCaptureSession alloc] init];
  20. _blackCameraDetector = detector;
  21. }
  22. return self;
  23. }
  24. - (void)startRunning
  25. {
  26. SCTraceODPCompatibleStart(2);
  27. [_blackCameraDetector sessionWillCallStartRunning];
  28. [_avSession startRunning];
  29. [_blackCameraDetector sessionDidCallStartRunning];
  30. }
  31. - (void)stopRunning
  32. {
  33. SCTraceODPCompatibleStart(2);
  34. [_blackCameraDetector sessionWillCallStopRunning];
  35. [_avSession stopRunning];
  36. [_blackCameraDetector sessionDidCallStopRunning];
  37. }
  38. - (void)performConfiguration:(nonnull void (^)(void))block
  39. {
  40. SC_GUARD_ELSE_RETURN(block);
  41. [self beginConfiguration];
  42. block();
  43. [self commitConfiguration];
  44. }
  45. - (void)beginConfiguration
  46. {
  47. [_avSession beginConfiguration];
  48. }
  49. - (void)commitConfiguration
  50. {
  51. SCTraceODPCompatibleStart(2);
  52. [_blackCameraDetector sessionWillCommitConfiguration];
  53. [_avSession commitConfiguration];
  54. [_blackCameraDetector sessionDidCommitConfiguration];
  55. }
  56. - (BOOL)isRunning
  57. {
  58. return _avSession.isRunning;
  59. }
  60. @end