【发布时间】:2012-09-28 14:27:42
【问题描述】:
我试图更好地理解 AVFoundation 框架以及各种 Core xxxx 框架,因此我决定尝试一个简单的视频捕获,看看是否可以将图像作为图像输出到 UI。我查看了 rosyWriter 代码和文档,但没有任何答案。所以:
我有标准的捕获会话代码来添加输入和输出。以下与问题相关:
//moving the buffer processing off the main queue
dispatch_queue_t bufferProcessingQueue=dispatch_queue_create("theBufferQueue", NULL);
[self.theOutput setSampleBufferDelegate:self queue:bufferProcessingQueue];
dispatch_release(bufferProcessingQueue);
然后是委托:
-(void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
CVPixelBufferRef pb = CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pb];
CGImageRef ref = [self.theContext createCGImage:ciImage fromRect:ciImage.extent];
dispatch_async(dispatch_get_main_queue(), ^{
self.testBufferImage.image= [UIImage imageWithCGImage:ref scale:1.0 orientation:UIImageOrientationRight];
});
}
问题:
1- 我猜想就像我在上面所做的那样,我们应该始终将委托设置为在单独的队列上运行,就像我在上面所做的那样,而不是在主队列上运行。对吗?
2- 在委托方法中,任何处理 UI 的调用都必须像我一样放回主队列。对吗?
3- 当我运行此代码时,大约 5-10 秒后,我收到“收到内存警告”错误并且应用程序关闭。这是什么原因造成的?
【问题讨论】:
标签: ios avfoundation objective-c-blocks avcapturesession