无论如何在后台线程上有 captureOutput 回调?

发布于 2024-12-09 20:31:53 字数 811 浏览 0 评论 0原文

无论如何,操作系统是否可以

         - (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)psampleBuffer fromConnection:(AVCaptureConnection *)pconnection

在后台线程而不是主线程上回调委托?问题是复制数据所需的时间会影响 UI。这似乎必须在主线程上完成,因为如果尝试在后台线程中复制 captureOutput 似乎会消失,等等......我在这里遗漏了一些东西吗?

        CMFormatDescriptionRef format;
        format = CMSampleBufferGetFormatDescription(sampleBuffer);
        bufSize = CMSampleBufferGetNumSamples(sampleBuffer);
        sampleSize = CMSampleBufferGetSampleSize(sampleBuffer,0);
        sampleLength = CMSampleBufferGetTotalSampleSize(sampleBuffer);
        blockbuff = CMSampleBufferGetDataBuffer(sampleBuffer);

        CMBlockBufferCopyDataBytes(blockbuff, 0, tocopy*_depth, buffInUse+(offset*2));

Is there anyway to have the OS callback the delegate

         - (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)psampleBuffer fromConnection:(AVCaptureConnection *)pconnection

on a background thread instead of the main thread? The issue is the time that it is taking to copy off the data is affecting the UI. This seems to have to be done on the main thread since the captureOutput seems to be gone if trying to copy it in a background thread, etc... Am I missing something here?

        CMFormatDescriptionRef format;
        format = CMSampleBufferGetFormatDescription(sampleBuffer);
        bufSize = CMSampleBufferGetNumSamples(sampleBuffer);
        sampleSize = CMSampleBufferGetSampleSize(sampleBuffer,0);
        sampleLength = CMSampleBufferGetTotalSampleSize(sampleBuffer);
        blockbuff = CMSampleBufferGetDataBuffer(sampleBuffer);

        CMBlockBufferCopyDataBytes(blockbuff, 0, tocopy*_depth, buffInUse+(offset*2));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌伤浅笑 2024-12-16 20:31:53

我使用 CVPixelBuffer 函数来锁定/解锁缓冲区并获取图像格式信息。我使用memcpy复制数据(当缓冲区被锁定时)并调用performSelectorInBackground来处理数据。

I use CVPixelBuffer functions to lock/unlock the buffer and get image format information. I use memcpy to copy the data (while the buffer is locked) and call performSelectorInBackground to process the data.

不美如何 2024-12-16 20:31:53

对于一个好的答案,这似乎获得修复回调线程的位置

     [audioOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];

只需要更改队列。

For a good answer, this seems to get the location to fix the callback thread

     [audioOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];

Just need to change the queue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文