开发者

addInput method of QTCaptureSession not returning

I have the following code:

BOOL success;

QTCaptureSession *session = [[QTCaptureSession alloc] init];
QTCaptureDevice  *device  = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeVideo];
success = [device open: &e];
if ( !success )
{
    NSLog(@"error opening input device: %@", e);
    return;
}

QTCaptureDeviceInput *input = [QTCaptureDeviceInput deviceInputWithDevice: device];
success = [session addInput: input error: &e];
if ( !success )
{
    NSLog(@"error adding input device to session: %@", e);
    return;
}

QTCaptureDecompressedVideoOutput *output = [[QTCaptureDecompressedVideoOutput alloc] init];
[output setDelegate: self];
success = [session addOutput: output error: &e];
if ( !success )
{
    NSLog(@"error adding output device to session: %@", e);
    return;
}

[session startRunning];

this is located in a bundle loaded during runtime and is part of a method that is the selector of a NSThread (aka. it runs in in a background thread and not the main thread).

开发者_如何学GoMy problem is, that the call to #addInput:error: never returns. What am I missing here?


The problem was, that the main thread of the application was not using the Run Loop normally provided by NSApplicationMain() in Cocoa applications. Instead I was handling events within my own while loop.

The solution was calling:

CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, YES);

This thread on Apple's QuickTime mailing list for a more detailed explanation of the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜