2
我正在为Cocoa环境中不存在的程序编写程序插件(想想C++命令行程序)。如果有兴趣,这是v8节点附加系统。我想这个插件来记录画面,从而利用AVCaptureSession的,等等。所以基本上,像这样:从非Cocoa应用调用基础,我需要NSRunLoop吗?
void start(/*entry*/)
{
// No run loop is *necessarily* present.
AVCaptureSession * session = ...
}
void stop (/*entry*/)
{
// etc..
}
实际上,我很可能会开始新的并行线程做这个东西,在这样没有任何阻碍。我的问题是,我需要建立多少周围的基础设施基础设施。我几乎可以肯定需要一个@autoreleasepool {},但我应该真的开始了我自己的默认NSRunLoop在线程中运行,如果不是我得到的印象是,在AVCapture等任何trickiness可能失败:
BOOL isStillRecording = YES;
void start(/*entry*/)
{
// setup avcapture and what have you.
NSRunLoop *theRL = [NSRunLoop new];
while (isStillRecording && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
}
void stop(/**entry**/)
{
// kill avcapture, maybe through async_dispatch to not stop on the start up.
isStillRecording = NO;
}