gpt4 book ai didi

objective-c - 不能在带有 Objective-C++ 代码的 C++ 类中使用 dispatch_sync

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:04:02 26 4
gpt4 key购买 nike

我需要在继承的 C++ 类中使用 Objective-C++ 代码,该类处理来自 iPhone 摄像头的视频录制(通过其他 native-objective-c 类 Wrapper 获取 CMSampleBufferRef使用 CMSampleBufferDelegate)。

我的 AVCaptureVideoOutput 在它自己的 dispatch_queue_t callbackQueue 中工作,所以,当我想从我的 Wrapper 类中获取最后一帧时,我需要锁定 callbackQueue 让它等到复制完成。

据我所知,这是通过 dispatch_sync 完成的,同步 captureOutput.callbackQueue。但我无法让这段代码工作:

// .mm
frame_t MyCppClass::getLastFrame()
{
dispatch_sync(pCaptureVideoDataOutput.sampleBufferCallbackQueue, ^{ // error: no matching function for call to 'dispatch_sync'

CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(wrapperInstance->currentBuffer);
CVPixelBufferLockBaseAddress(imageBuffer,0);

// doing copying frame data from buffer...

CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
}); // error: control may reach end of non-void block

return frame;
}

// .h
@interface Wrapper : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate> {
CMSampleBufferRef currentBuffer;
}
@end

// .mm
@implementation Wrapper
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
// doing copying to currentBuffer
}
@end

编辑:

当我改成

dispatch_sync(pCaptureVideoDataOutput.sampleBufferCallbackQueue, (dispatch_block_t)^{

它修复了第一个错误,但第二个错误仍然存​​在..

遇到了这个问题.. 任何帮助都将不胜感激!

最佳答案

我想通了!

我在 block 中有一些紧急 return 语句。我以为它会返回函数,但它返回 block ...所以编译器是正确的。

关于objective-c - 不能在带有 Objective-C++ 代码的 C++ 类中使用 dispatch_sync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12821364/

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