0

我正在开发 OSX 上的 Cocoa 应用程序,它以伪实时方式捕获屏幕。

出于某种原因,屏幕捕获回调如下所示:

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection

在显示器进入睡眠状态(系统偏好设置 -> 节能器)并且显示器已被用户再次退出“睡眠模式”后不被调用。这有什么原因吗?以及如何防止它(即修复它!)???

我是这样设置的:

/****** This code snippet is used to set up the capture callbacks********************** */
    /* Create a capture session. */
    captureSession = [[AVCaptureSession alloc] init];
    if ([captureSession canSetSessionPreset:AVCaptureSessionPresetHigh])
    {
        /* Specifies capture settings suitable for high quality video and audio output. */
        [captureSession setSessionPreset:AVCaptureSessionPresetHigh];
    }

    /* Add display as a capture input. */
    // selectedDisplayId is defined prior to calling this code snippet */
    captureScreenInput = [[AVCaptureScreenInput alloc] initWithDisplayID:selectedDisplayId];
    if ([captureSession canAddInput:captureScreenInput])
    {
        [captureSession addInput:captureScreenInput];
    }
    else
    {
        NSLog(@"Could not add main display to capture input\n");
    }

    AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];

    [captureSession addOutput:output];

    dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL);
    [output setSampleBufferDelegate:self queue:queue];

    output.alwaysDiscardsLateVideoFrames = TRUE;

    output.videoSettings = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];

    /* Start the capture session. */
    printf("*** Start capture session ***\n");
    [captureSession startRunning];
    /****** ********* This code snippet is used to set up the capture callbacks **********************/

所以简而言之,屏幕捕获回调在显示打开时按预期重复调用。当显示器进入睡眠状态并且用户再次使显示器退出“睡眠模式”时,回调不会继续被调用。我该如何解决?

谢谢

我在 MAC OSX 10.8.5

4

0 回答 0