objective-cmacoscocoaqtkit

QTCaptureSession:startRunning is blocking thread


Let me first start by saying that I'm a total objective-c newbie, and I'm picking up an existing codebase, so I'm trying to frantically read about NSRunLoop, etc. but I would love some extra help.

Basically, I have inherited code that looks like:

[[NSRunLoop mainRunLoop] runUntilDate:[NSDate distantFuture]];
[_captureSession startRunning];
return [NSNumber numberWithInt:0];

in a function that's supposed to return, but instead blocks forever on startRunning. I need this to return, and I'm not sure why it's blocking. Some more code scattered about that may be helpful:

_captureDecompressedVideoOutput = [[QTCaptureDecompressedVideoOutput alloc]
                                    init];
[_captureDecompressedVideoOutput setDelegate:self];
[_captureDecompressedVideoOutput performSelectorOnMainThread:@selector(setPixelBufferAttributes:) withObject:captureDictionary waitUntilDone:NO];

any idea what's going on?


Solution

  • well, I stuck [_captureSession startRunning] in a separate function, then replaced the call with

    self performSelectorInBackground:@selector(backgroundCapture) withObject:nil];
    

    so it ran in a thread. not only did the blocking not interfere with the method returning (since it was on a separate thread) but the call didn't even block now that it was running on it's own thread. Bizarre.