Storing CVImageBufferRef
My C is a little rusty, so I apologize if this question seems too basic, but I've been banging my head against the desk for three days on this one...
I need to store a rolling buffer of video frames.
I'm using QTKit for the capture session, and CoreVideo to grab the frames (based on example in http://developer.apple.com/documentation/QuickTime/Conceptual/QTKitCaptureProgrammingGuide/CreatingStopMotionApplication/CreatingStopMotionApplication.html#//apple_ref/doc/uid/TP40004574-CH6-DontLinkElementID_12)
The part I'm having trouble with is storing the CVImageBufferRef's in a pointer array. According to CV docs, a CVImageBufferRef is just a pointer to a struct, right?
So, what am I doing wrong?
// from AppController.h
/////////////////////////
#define FRAME_BUFFER_SIZE 10
int frameBufferCount;
int *frameBuffer;
// from AppController.m
/////////////////////////
- (void)awakeFromNib {
frameBufferCount = 0;
frameBuffer = malloc(sizeof(int) * FRAME_BUFFER_SIZE);
}
- (void)captureOutput:(QTCaptureOutput *)captureOutput didOutputVideoFrame:(CVImageBufferRef)videoFrame withSampleBuffer:(QTSampleBuffer *)sampleBuffer fromConnection:(QTCaptureConnection *)connection
{
int i;
CVImageBufferRef imageBufferToRelease;
if (frameBufferCount < FRAME_BUFFER_SIZE)
{
// add new frame to buffer
frameBuffer[frameBufferCount] = videoFrame;
frameBufferCount ++;
} else {
// Push first frame out of buffer, and append new one
imageBufferToRelease = frameBuffer[0];
for (i = 1; i < EA_FRAME_AVERAGE; i++)
{
frameBuffer[i - 1] = frameBuffer[i];
}
frameBuffer[FRAME_BUFFER_SIZE - 1] = videoFrame;
}
}