AVCaptureOutput didOutputSampleBuffer停止调用 [英] AVCaptureOutput didOutputSampleBuffer stops getting called

查看:1282
本文介绍了AVCaptureOutput didOutputSampleBuffer停止调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了委托方法的问题 didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection of AVCaptureOutput

I have an issue with the delegate method didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection of AVCaptureOutput.

当我将sampleBuffer添加到 CFArray 时,它会在一两秒内停止调用。如果我删除 CFArray 代码,则会继续调用委托方法,因此我不知道为什么 CFArray 代码是导致它停止。我很感激任何帮助。

It stops getting called within a second or two when I'm adding the sampleBuffer to a CFArray. If I remove the CFArray code, the delegate method continues to get called so I have no idea why the CFArray code is causing it to stop. I'd appreciate any help.

@property CFMutableArrayRef sampleBufferArray;

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
    NSLog(@"Called");

    if (!self.sampleBufferArray)
    {
        self.sampleBufferArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
        CFArrayAppendValue(self.sampleBufferArray, sampleBuffer);
    }
    else
    {
        CFArrayAppendValue(self.sampleBufferArray, sampleBuffer);
    }
}

控制台输出:

// Session start
2015-06-15 13:06:07.264 App[22467:5897858] Called
2015-06-15 13:06:07.286 App[22467:5897858] Called
2015-06-15 13:06:07.289 App[22467:5897858] Called
2015-06-15 13:06:07.315 App[22467:5897895] Called
2015-06-15 13:06:07.366 App[22467:5897895] Called
2015-06-15 13:06:07.384 App[22467:5897895] Called
2015-06-15 13:06:07.411 App[22467:5897895] Called
2015-06-15 13:06:07.449 App[22467:5897858] Called
2015-06-15 13:06:07.480 App[22467:5897858] Called
2015-06-15 13:06:07.513 App[22467:5897895] Called
2015-06-15 13:06:07.546 App[22467:5897895] Called
2015-06-15 13:06:07.579 App[22467:5897895] Called
2015-06-15 13:06:07.614 App[22467:5897895] Called
// No more calls after this point


推荐答案

您的问题实际上是在Docs ,具体而言;

Your problem is actually referenced in the Docs, Specifically;


如果您的应用程序通过保留
提供的CMSampleBufferRef对象太久而导致丢弃样本,但它需要访问
对于样本数据很长一段时间,考虑将
数据复制到一个新的缓冲区然后释放样本缓冲区(如果它是以前保留的
),以便它引用的内存可以重用。

If your application is causing samples to be dropped by retaining the provided CMSampleBufferRef objects for too long, but it needs access to the sample data for a long period of time, consider copying the data into a new buffer and then releasing the sample buffer (if it was previously retained) so that the memory it references can be reused.

基本上,您需要尽可能简单地保持回调操作,并且您是否需要对传递的帧执行进一步处理在回调中,您需要将其复制到新缓冲区并在后台执行处理。此外,请记住,必须明确保留和释放Core Foundation对象。

Essentially, you need to keep the callback operation as simple as possible, and should you need to perform further processing on the frame passed to you in the callback, you need to copy it to a new buffer and perform the processing in the background. Also, Keep in mind that Core Foundation object must explicitly be retained and released.

进一步考虑内存压力。框架包含大量数据,保留太多会导致您的应用程序崩溃。

A further consideration is memory pressure. Frames contain lots of data, retaining too many will cause your app to crash.

这篇关于AVCaptureOutput didOutputSampleBuffer停止调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆