委托回调中的CMSampleBufferRef参数为空

时间:2015-11-22 19:35:28

标签: objective-c macos avfoundation screen-capture cmsamplebufferref

我正在使用此代码来创建AVCaptureSession,但是当调用-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection时,sampleBuffer大小为0

- (BOOL)createCaptureSession:(NSError **)outError{
/* Create a capture session. */
self.captureSession = [[AVCaptureSession alloc] init];
if ([self.captureSession canSetSessionPreset:AVCaptureSessionPresetHigh])
{
    /* Specifies capture settings suitable for high quality video and audio output. */
    [self.captureSession setSessionPreset:AVCaptureSessionPresetHigh];
}

/* Add the main display as a capture input. */
display = CGMainDisplayID();
self.captureScreenInput = [[AVCaptureScreenInput alloc] initWithDisplayID:display];
if ([self.captureSession canAddInput:self.captureScreenInput])
{
    [self.captureSession addInput:self.captureScreenInput];
}
else
{   NSLog(@"nevyslo");
    return NO;
}

/* Register for notifications of errors during the capture session so we can display an alert. */
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(captureSessionRuntimeErrorDidOccur:) name:AVCaptureSessionRuntimeErrorNotification object:self.captureSession];


AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
[self.captureSession addOutput:output];

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

[self.captureSession startRunning];
    return YES;
}

我的方法有什么问题吗?错误可能在其他地方吗? 我正在使用ARC。

修改 缓冲区不是空的,但它已被解除分配。通过保留缓冲区解决。感谢

0 个答案:

没有答案