Objective c QTCaptureOutput.delegate captureOutput:didOutputVideoFrame:。。。从未打过电话 来源

Objective c QTCaptureOutput.delegate captureOutput:didOutputVideoFrame:。。。从未打过电话 来源,objective-c,cocoa,delegates,callback,qtkit,Objective C,Cocoa,Delegates,Callback,Qtkit,因此,我设置了一个QTCaptureSession: //Setup Camera cameraSession = [[QTCaptureSession alloc] init]; QTCaptureDevice *camera = [QTCaptureDevice deviceWithUniqueID: cameraID]; BOOL success = [camera open: &error]; if (!success || er

因此,我设置了一个
QTCaptureSession

    //Setup Camera
    cameraSession = [[QTCaptureSession alloc] init];
    QTCaptureDevice *camera = [QTCaptureDevice deviceWithUniqueID: cameraID];
    
    BOOL success = [camera open: &error];
    if (!success || error)
    {
        NSLog(@"Could not open device %@.", cameraID);
        NSLog(@"Error: %@", [error localizedDescription]);
        return nil;
    }
    
    //Setup Input Session
    QTCaptureDeviceInput *cameraInput = [[QTCaptureDeviceInput alloc] initWithDevice: camera];
    
    success = [cameraSession addInput: cameraInput error: &error];
    if (!success || error)
    {
        NSLog(@"Could not initialize input session.");
        NSLog(@"Error: %@", [error localizedDescription]);
        return nil;
    }
    
    //Setup Output
    QTCaptureDecompressedVideoOutput *cameraOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
    [cameraOutput setDelegate: self];
    
    success = [cameraSession addOutput: cameraOutput error: &error];
    if (!success || error)
    {
        NSLog(@"Could not initialize output session.");
        NSLog(@"Error: %@", [error localizedDescription]);
        return nil;
    }
QTCaptureDecompressedDVideOutput
代理的
captureOutput:didOutputVideoFrame:WithSampleBuffer:fromConnection:
从而:

- (void)captureOutput:(QTCaptureOutput *)captureOutput didOutputVideoFrame:(CVImageBufferRef)videoFrame withSampleBuffer:(QTSampleBuffer *)sampleBuffer fromConnection:(QTCaptureConnection *)connection
{
    NSLog(@"starting convert\n");
}
然后,我使用以下命令启动捕获处理:

    [cameraSession startRunning];
所有变量初始化良好,会话启动良好,但从未调用
captureOutput:didOutputVideoFrame:withSampleBuffer:fromConnection:

上下文 这是一个命令行应用程序,使用GCC编译。它与以下框架相关联:

  • 基础
  • 可可粉
  • QTKit
  • 石英砂
相关杂项
帧不太可能会下降,因为
captureOutput:didDropVideoFrameWithSampleBuffer:fromConnection:
也没有被调用。

因此,在Mike Ash的帮助下,我设法发现我的程序立即终止,没有等待代理回调(根据苹果的
QTKit
docs,这可能发生在一个单独的线程上)

我的解决方案是将
BOOL
属性添加到名为
captureissfinished
的对象中,然后将其添加到
main()
函数中:

    //Wait Until Capture is Finished
    while (![snap captureIsFinished])
    {
        [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
    }
它有效地使应用程序的运行循环持续1秒,检查捕获是否完成,然后再运行一秒钟