Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Blackmagic Design DisplayVideoFrameSync memory leaks problem

  • DisplayVideoFrameSync memory leaks problem

    Posted by Mauro Gattari on January 9, 2012 at 2:59 pm

    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
    #include

    IDeckLink* 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 * minutes

    int 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; // AARRGGBB

    publicDisplayVideoFrameSync();
    }

    usleep(1000000/fps);
    }

    getchar();

    cleanUp();

    return 0;
    }

    Mauro Gattari replied 14 years, 6 months ago 2 Members · 2 Replies
  • 2 Replies
  • Joshua Helling

    January 16, 2012 at 7:28 pm

    Might be best to contact developer@blackmagic-design.com to get help with this issue.

    Sincerely,

    Joshua
    Director of Support
    Blackmagic Design Inc.

  • Mauro Gattari

    January 16, 2012 at 7:30 pm

    Yes,
    I already contacted the developers and they acknowledged the issue. They are working on it, I’m waiting for the fix release.
    Thanks

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy