我需要在继承的 C++ 类中使用 Objective-C++ 代码,该类与 iPhone 摄像头的视频录制一起工作(CMSampleBufferRef
通过另一个 native-objective-c 类Wrapper
)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)^{
它修复了第一个错误,但第二个仍然在这里..
被困住了..任何帮助表示赞赏!