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

dre*_*zor 2 objective-c objective-c++ grand-central-dispatch ios avcapture

我需要在继承C++类,这与iPhone摄像头视频录制(获得作品使用的Objective-C++代码CMSampleBufferRef通过其他本地Objective-C类WrapperCMSampleBufferDelegate).

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
Run Code Online (Sandbox Code Playgroud)

编辑:

当我改为

dispatch_sync(pCaptureVideoDataOutput.sampleBufferCallbackQueue, (dispatch_block_t)^{
Run Code Online (Sandbox Code Playgroud)

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

坚持这个...任何帮助表示赞赏!

dre*_*zor 5

我想到了!

return在街区内有一些紧急声明.我认为它将返回该函数,但它返回块...所以编译器是正确的.