I need to use Objective-C++ code in inherited C++ class which works with video recording from iPhone camera (getting CMSampleBufferRef
through an other native-objective-c class Wrapper
with CMSampleBufferDelegate
).
The AVCaptureVideoOutput
that i have works in its own dispatch_queue_t callbackQueue
, so, when i want to get the last frame from my Wrapper
class, I need to lock the callbackQueue
to make it wait till the copying will be done.
As i know, it's done with dispatch_sync
, syncing the captureOutput.callbackQueue
. But i can't get this code working:
// .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
EDIT:
When i changed to
dispatch_sync(pCaptureVideoDataOutput.sampleBufferCallbackQueue, (dispatch_block_t)^{
it fixed the first error, but the second is still here..
Got stuck with this.. any help is appreciated!
The error:
error: no matching function for call to 'dispatch_sync'
indicates that the function prototype may not be visible. Make sure you are including the header for libdispatch in your .mm file...
#include <dispatch/dispatch.h>
The second error:
error: control may reach end of non-void block
is because your function is declared to return a frame_t
but it has no return statement.