-
DisplayVideoFrameSync memory leaks problem
Hi,
I’m trying to write a small C program that outputs frames to the card, but I’m experiencing memory leaks problems.The program is very simple, after having enabled video output:
deckLinkOutput->EnableVideoOutput(bmdModeHD720p50, bmdVideoOutputFlagDefault);
It starts outputting frames at 50fps within a loop in which:
1. create an output video frame:
deckLinkOutput->CreateVideoFrame(
1280, 720, 1280*4,
bmdFormat8BitBGRA, bmdFrameFlagDefault,
&videoFrame);
2. write raw data within the frame (just a pattern of RED or GREEN pixels)
3. display the frame:
deckLinkOutput->DisplayVideoFrameSync(videoFrame);
4. release the frame:
videoFrame->Release();
videoFrame = NULL;
The program works, but memory consumption grows fast (1MB per second) and I can’t understand why since I think I’m correctly releasing a video frame before creating a new one.
Can anybody give me any help?
Thanks!Linux Ubuntu 11.10
DeckLink Studio
Drivers 9.0——————————————————————–
This is the whole source code:#include "simple.h"
#include "DeckLinkAPI.h"
#include
#include
#includeIDeckLink* deckLink = NULL;
IDeckLinkOutput* deckLinkOutput = NULL;
IDeckLinkMutableVideoFrame* videoFrame = NULL;unsigned char* publicCreateOutputVideoFrame()
{
unsigned char* outBytes = NULL;HRESULT result = deckLinkOutput->CreateVideoFrame(
1280, 720, 1280*4,
bmdFormat8BitBGRA, bmdFrameFlagDefault,
&videoFrame);if (result != S_OK)
return NULL;result = videoFrame->GetBytes((void**)&outBytes);
return outBytes;
}void publicDisplayVideoFrameSync()
{
deckLinkOutput->DisplayVideoFrameSync(videoFrame);
/* ULONG refCount = */ videoFrame->Release();
videoFrame = NULL;
}void cleanUp()
{
if (deckLinkOutput != NULL)
{
deckLinkOutput->DisableVideoOutput();
deckLinkOutput = NULL;
}
if (deckLink != NULL)
{
deckLink->Release();
deckLink = NULL;
}
}int setUp()
{
IDeckLinkIterator* deckLinkIterator;
HRESULT result;deckLinkIterator = CreateDeckLinkIteratorInstance();
if (deckLinkIterator == NULL)
{
fprintf(stderr, "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.n");
return 1;
}// Get the first DeckLinkCard
result = deckLinkIterator->Next(&deckLink);
if (result != S_OK)
{
fprintf(stderr, "Could not obtain the IDeckLink interface - result = %08dn", result);
goto bail;
}result = deckLink->QueryInterface(IID_IDeckLinkOutput, (void**)&deckLinkOutput);
if (result != S_OK)
{
fprintf(stderr, "Could not obtain the IDeckLinkOutput interface - result = %08dn", result);
goto bail;
}deckLinkOutput->EnableVideoOutput(bmdModeHD720p50, bmdVideoOutputFlagDefault);
bail:
deckLinkIterator->Release();
deckLinkIterator = NULL;return 0;
}int main()
{
const int fps = 50;
const int nrOfFramse = fps*60*1; // fps * seconds * minutesint i,j;
unsigned int pattern;setUp();
for(j=0; j nrOfFramse; j++)
{
unsigned char* frame = publicCreateOutputVideoFrame();if (frame != NULL)
{
if ((j/fps)%2==0)
pattern = 0x0000ff00;
else
pattern = 0x000000ff;for(i=0; i<1280*720; i++)
((unsigned int *)frame)[i] = pattern; // AARRGGBBpublicDisplayVideoFrameSync();
}usleep(1000000/fps);
}getchar();
cleanUp();
return 0;
}