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.

66 lines
1.9 KiB

  1. //
  2. // SCCaptureResource.m
  3. // Snapchat
  4. //
  5. // Created by Lin Jia on 10/19/17.
  6. //
  7. //
  8. #import "SCCaptureResource.h"
  9. #import "SCBlackCameraDetector.h"
  10. #import "SCManagedCapturerState.h"
  11. #import "SCManagedFrontFlashController.h"
  12. #import "SCManagedVideoCapturer.h"
  13. #import <SCFoundation/SCAssertWrapper.h>
  14. #import <SCFoundation/SCQueuePerformer.h>
  15. #import <SCFoundation/SCTraceODPCompatible.h>
  16. #import <FBKVOController/FBKVOController.h>
  17. @interface SCCaptureResource () {
  18. FBKVOController *_previewHiddenKVO;
  19. }
  20. @end
  21. @implementation SCCaptureResource
  22. - (SCManagedFrontFlashController *)frontFlashController
  23. {
  24. SCTraceODPCompatibleStart(2);
  25. SCAssert([self.queuePerformer isCurrentPerformer], @"");
  26. if (!_frontFlashController) {
  27. _frontFlashController = [[SCManagedFrontFlashController alloc] init];
  28. }
  29. return _frontFlashController;
  30. }
  31. - (void)setVideoPreviewLayer:(AVCaptureVideoPreviewLayer *)layer
  32. {
  33. SC_GUARD_ELSE_RETURN(layer != _videoPreviewLayer);
  34. if (_videoPreviewLayer) {
  35. [_previewHiddenKVO unobserve:_videoPreviewLayer];
  36. }
  37. _videoPreviewLayer = layer;
  38. SC_GUARD_ELSE_RETURN(_videoPreviewLayer);
  39. if (!_previewHiddenKVO) {
  40. _previewHiddenKVO = [[FBKVOController alloc] initWithObserver:self];
  41. }
  42. [_previewHiddenKVO observe:_videoPreviewLayer
  43. keyPath:@keypath(_videoPreviewLayer.hidden)
  44. options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
  45. block:^(id observer, id object, NSDictionary *change) {
  46. BOOL oldValue = [change[NSKeyValueChangeOldKey] boolValue];
  47. BOOL newValue = [change[NSKeyValueChangeNewKey] boolValue];
  48. if (oldValue != newValue) {
  49. [_blackCameraDetector capturePreviewDidBecomeVisible:!newValue];
  50. }
  51. }];
  52. }
  53. @end