I tried to save the CMSampleBuffer from didOutputSampleBuffer, as the iOS developer docs, I copy it in CFArrayRetainCallBack like blow:
static const void * ObjectRetainCallBack(CFAllocatorRef allocator, const void *value) {
CMSampleBufferRef buffer = (CMSampleBufferRef)value;
if (buffer) {
CMSampleBufferRef new = NULL;
OSStatus status = CMSampleBufferCreateCopy(kCFAllocatorDefault, buffer, &new);
if (status == noErr) {
return new;
}
return NULL;
}
return NULL;
}
static void ObjectReleaseCallBack(CFAllocatorRef allocator, const void *value) {
if (value) {
CFRelease(value);
}
}
CFMutableArrayRef CreateDispatchHoldingArray() {
CFArrayCallBacks callBacks = {
0,
ObjectRetainCallBack,
ObjectReleaseCallBack,
NULL,
NULL
};
return CFArrayCreateMutable(kCFAllocatorDefault, 0, &callBacks);
}
I use the array like below:
- (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
CFArrayAppendValue(_pixelArray, sampleBuffer);
}
Somebody has better way to do this or any suggestion?
Thanks a lot.