QTCaptureSession:startRunning是阻塞线程

时间:2012-08-14 20:07:15

标签: objective-c macos cocoa qtkit

首先我要说的是,我是一个完全客观的新手,而且我正在寻找现有的代码库,所以我试图疯狂地阅读有关NSRunLoop等等但我会更喜欢一些额外的帮助

基本上,我继承了类似的代码:

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

在一个应该返回的函数中,而是在startRunning上永远阻塞。我需要这个回来,我不确定它为什么会阻塞。有些代码可能会有所帮助:

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

知道发生了什么事吗?

1 个答案:

答案 0 :(得分:0)

好吧,我把[_captureSession startRunning]卡在一个单独的函数中,然后用

替换了调用
self performSelectorInBackground:@selector(backgroundCapture) withObject:nil];

所以它在一个线程中运行。不仅阻塞不会干扰返回的方法(因为它是在一个单独的线程上),但是调用甚至没有阻止它现在运行在它自己的线程上。奇异。