Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8607871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:28:09+00:00 2026-06-12T03:28:09+00:00

I need to selectively (and reliably) turn off processing of sampleBuffers in my captureOutput:didOutputSampleBuffer:fromConnection:

  • 0

I need to selectively (and reliably) turn off processing of sampleBuffers in my captureOutput:didOutputSampleBuffer:fromConnection: method. As you know it’s called from a GCD queue and not on the main thread… but I’m taking user input from a UIButton (on the main thread of course) and telling my camera object to halt all processing by setting a BOOL flag.

However, sometimes I’m seeing 1 extra frame slip through the cracks after processing was supposedly stopped. Is there any way I can be absolutely sure that nothing will be processed after the button is pressed? Right now I’m doing a trivial test:

// in ViewController:
- (IBAction)tappedStop:(id)sender {
    NSLog("stop processing!");
    _camera.capturing = NO;
}

// in my camera obj:
- (void)captureOutput:(AVCaptureOutput *)captureOutput did... {
    if (!capturing) {
        return;
    }
    NSLog(@"processing!");
}

I’ve tried using @synchronized, a static BOOL, and using a semaphore, but to no avail… sometimes that extra frame still sneaks in. Anyone have and ideas? There’s probably some GCD method that does what I want but I’m not sure how to go about it.

Here’s how the results (sometimes) look in my debug console (shortened to make it more readable):

2012-09-29 23:29:01.869 __33-_block_invoke_0 [Line 322] processing!
2012-09-29 23:29:01.910 __33-_block_invoke_0 [Line 322] processing!
2012-09-29 23:29:01.953 __33-_block_invoke_0 [Line 322] processing!
2012-09-29 23:29:01.994 __33-_block_invoke_0 [Line 322] processing!
2012-09-29 23:29:02.047 __33-_block_invoke_0 [Line 322] processing!
2012-09-29 23:29:02.078 __33-_block_invoke_0 [Line 322] processing!
2012-09-29 23:29:02.121 __33-_block_invoke_0 [Line 322] processing!
2012-09-29 23:29:02.166 -[ViewController tappedButton:] [Line 913] stop processing!
2012-09-29 23:29:02.161 __33-_block_invoke_0 [Line 322] processing!
...

But usually (about 4 out of 5 times) my console looks like:

2012-09-29 23:29:01.869 __33-_block_invoke_0 [Line 322] processing!
2012-09-29 23:29:01.910 __33-_block_invoke_0 [Line 322] processing!
2012-09-29 23:29:01.953 __33-_block_invoke_0 [Line 322] processing!
2012-09-29 23:29:01.994 __33-_block_invoke_0 [Line 322] processing!
2012-09-29 23:29:02.047 __33-_block_invoke_0 [Line 322] processing!
2012-09-29 23:29:02.078 __33-_block_invoke_0 [Line 322] processing!
2012-09-29 23:29:02.121 __33-_block_invoke_0 [Line 322] processing!
2012-09-29 23:29:02.166 -[ViewController tappedButton:] [Line 913] stop processing!

I should probably also mention that I don’t have access to the original queue that’s calling captureOutput:didOutput... since it’s in a superClass of a framework that I can’t control.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:28:11+00:00Added an answer on June 12, 2026 at 3:28 am

    I dunno why I didn’t think of this sooner, but if I wrap my entire captureOutput:didOutput… method in an async call to the main thread, even though it seems kind of non-ideal, turning off sampleBuffer processing works as expected. I guess it makes sense; my touch event always comes from the main thread, and since I don’t have a handle on which thread was used in my buffer output queue, the only way (that I can see) to reliably check isRecording is to do so from the main thread too.

    - (void)captureOutput:(AVCaptureOutput *)captureOutput did... {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (!isRecording) {
                return;
            }
    
            NSLog(@"processing!");
    
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
                // do actual processing
            });
        });
    }
    

    If anyone has any other suggestions though I’d love to hear ’em. Thanks!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help in string processing in CSH/TCSH script. I know basic processing, but
For an application we are developing we need to read n rows from a
I'm having trouble getting my data from fetchAll to print selectively. In normal mysql
I need to selectively revert a few lines in a massive file (to be
How do you take a live video feed from a webcam and selectively extract
I need to selectively flatten an array in PHP, but do it selectively. If
I need to iterate through a large XML file (~2GB) and selectively copy certain
I am trying to selectively display several columns from a db table(see sample below)
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
Need a map reduce function by mongo in php This my mongo structure [_id]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.