gpt4 book ai didi

ios - AVCaptureOutput didOutputSampleBuffer 停止被调用

转载 作者:可可西里 更新时间:2023-11-01 04:18:05 24 4
gpt4 key购买 nike

AVCaptureOutput 的委托(delegate)方法 didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection 有问题。

当我将 sampleBuffer 添加到 CFArray 时,它会在一两秒内停止调用。如果我删除 CFArray 代码,委托(delegate)方法将继续被调用,所以我不知道为什么 CFArray 代码导致它停止。如果有任何帮助,我将不胜感激。

@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 中被引用, 具体来说;

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 对象必须显式保留和释放。

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

关于ios - AVCaptureOutput didOutputSampleBuffer 停止被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30850676/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com