SHARE
TWEET

Untitled

a guest Jan 17th, 2019 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // in ViewController:
  2. - (IBAction)tappedStop:(id)sender {
  3.     NSLog("stop processing!");
  4.     _camera.capturing = NO;
  5. }
  6.  
  7. // in my camera obj:
  8. - (void)captureOutput:(AVCaptureOutput *)captureOutput did... {
  9.     if (!capturing) {
  10.         return;
  11.     }
  12.     NSLog(@"processing!");
  13. }
  14.    
  15. 2012-09-29 23:29:01.869 __33-_block_invoke_0 [Line 322] processing!
  16. 2012-09-29 23:29:01.910 __33-_block_invoke_0 [Line 322] processing!
  17. 2012-09-29 23:29:01.953 __33-_block_invoke_0 [Line 322] processing!
  18. 2012-09-29 23:29:01.994 __33-_block_invoke_0 [Line 322] processing!
  19. 2012-09-29 23:29:02.047 __33-_block_invoke_0 [Line 322] processing!
  20. 2012-09-29 23:29:02.078 __33-_block_invoke_0 [Line 322] processing!
  21. 2012-09-29 23:29:02.121 __33-_block_invoke_0 [Line 322] processing!
  22. 2012-09-29 23:29:02.166 -[ViewController tappedButton:] [Line 913] stop processing!
  23. 2012-09-29 23:29:02.161 __33-_block_invoke_0 [Line 322] processing!
  24. ...
  25.    
  26. 2012-09-29 23:29:01.869 __33-_block_invoke_0 [Line 322] processing!
  27. 2012-09-29 23:29:01.910 __33-_block_invoke_0 [Line 322] processing!
  28. 2012-09-29 23:29:01.953 __33-_block_invoke_0 [Line 322] processing!
  29. 2012-09-29 23:29:01.994 __33-_block_invoke_0 [Line 322] processing!
  30. 2012-09-29 23:29:02.047 __33-_block_invoke_0 [Line 322] processing!
  31. 2012-09-29 23:29:02.078 __33-_block_invoke_0 [Line 322] processing!
  32. 2012-09-29 23:29:02.121 __33-_block_invoke_0 [Line 322] processing!
  33. 2012-09-29 23:29:02.166 -[ViewController tappedButton:] [Line 913] stop processing!
  34.    
  35. - (void)captureOutput:(AVCaptureOutput *)captureOutput did... {
  36.     dispatch_async(dispatch_get_main_queue(), ^{
  37.         if (!isRecording) {
  38.             return;
  39.         }
  40.  
  41.         NSLog(@"processing!");
  42.  
  43.         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
  44.             // do actual processing
  45.         });
  46.     });
  47. }
  48.    
  49. @interface Camera : NSObject
  50.  
  51. @property (nonatomic,getter = isCapturing) BOOL capturing;
  52.  
  53. @end
  54.    
  55. #define CALLBACK_INTERVAL (1.0/60.0)
  56.  
  57. @implementation Camera {
  58.     dispatch_queue_t _sync_queue;
  59.     BOOL _capturing;
  60. }
  61.  
  62. - (id)init
  63. {
  64.     if (self = [super init])
  65.     {
  66.         _capturing = YES;
  67.         _sync_queue = dispatch_queue_create("com.mycompany.whatever", NULL);
  68.         [self performSelector:@selector(triggerCallback) withObject:nil afterDelay:CALLBACK_INTERVAL];
  69.     }
  70.  
  71.     return self;
  72. }
  73.  
  74.  
  75. - (void)setCapturing:(BOOL)capturing
  76. {
  77.     dispatch_async(_sync_queue, ^{
  78.         _capturing = capturing;
  79.         if (!_capturing)
  80.             NSLog(@"STOP");
  81.     });
  82. }
  83.  
  84. - (void)repeatingCallback
  85. {
  86.     dispatch_async(_sync_queue, ^{
  87.         if (!_capturing)
  88.             return;
  89.         NSLog(@"WORKING");
  90.     });
  91. }
  92.  
  93. - (void)triggerCallback
  94. {
  95.     [NSObject cancelPreviousPerformRequestsWithTarget:self];
  96.     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  97.         [self repeatingCallback];
  98.     });
  99.     [self performSelector:@selector(triggerCallback) withObject:nil afterDelay:CALLBACK_INTERVAL];
  100. }
  101.  
  102. @end
  103.    
  104. - (IBAction)stopCapturing:(id)sender
  105. {
  106.     self.camera.capturing = NO;
  107. }
  108.    
  109. // in ViewController:
  110. - (IBAction)tappedStop:(id)sender {
  111.     NSLog("stop processing!");
  112.     dispatch_async(capture_dispatch_queue, ^{_camera.capturing = NO;});
  113. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top