Manage DeckLink cards' footprint

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

PedroReis

  • Posts: 2
  • Joined: Wed Dec 17, 2014 10:47 am

Manage DeckLink cards' footprint

PostWed Dec 17, 2014 1:41 pm

Hi,

As anyone successfully managed the footprint size that a DeckLink board occupies in the RAM?
Eg. If I'm recording PAL signals, I don't need support for 4k, so the extra buffer space is to be avoided.
Offline

stanislav.petkov

  • Posts: 3
  • Joined: Thu Jan 08, 2015 8:36 am

Re: Manage DeckLink cards' footprint

PostThu Jan 08, 2015 10:35 am

If you are using the low level API create you own BMDAllocator and use SetVideoOutputFrameMemoryAllocator or SetVideoInputFrameMemoryAllocator ... and you decide how many buffers you will allow to be used
Offline

PedroReis

  • Posts: 2
  • Joined: Wed Dec 17, 2014 10:47 am

Re: Manage DeckLink cards' footprint

PostFri Jan 09, 2015 5:25 pm

Thanks for the response,

I'm using, as BMDAllocator, a ripped version of BMD's LoopThroughWithOpenGLCompositing sample.
But I don't think I can control the allocated buffer.

Code follows:

Code: Select all
DeckLinkMemoryAllocator::DeckLinkMemoryAllocator(unsigned cacheSize) :
mRefCount(1),
mFrameCacheSize(cacheSize)      // large cache size will keep more memory pinned and may result in out of memory errors
{
}

DeckLinkMemoryAllocator::~DeckLinkMemoryAllocator()
{
}

// IUnknown methods
HRESULT STDMETHODCALLTYPE   DeckLinkMemoryAllocator::QueryInterface(REFIID /*iid*/, LPVOID* /*ppv*/)
{
    return E_NOTIMPL;
}

ULONG STDMETHODCALLTYPE      DeckLinkMemoryAllocator::AddRef(void)
{
    return InterlockedIncrement(&mRefCount);
}

ULONG STDMETHODCALLTYPE      DeckLinkMemoryAllocator::Release(void)
{
    int newCount = InterlockedDecrement(&mRefCount);
    if (newCount == 0)
        delete this;
    return newCount;
}

// IDeckLinkMemoryAllocator methods
HRESULT STDMETHODCALLTYPE   DeckLinkMemoryAllocator::AllocateBuffer (unsigned long bufferSize, void* *allocatedBuffer)
{
    if (mFrameCache.empty())
    {
        // Allocate memory on a page boundary
        *allocatedBuffer = VirtualAlloc(NULL, bufferSize, MEM_COMMIT | MEM_RESERVE | MEM_WRITE_WATCH | MEM_TOP_DOWN, PAGE_READWRITE);

        if (! *allocatedBuffer)
            return E_OUTOFMEMORY;

        mAllocatedSize[*allocatedBuffer] = bufferSize;
    }
    else
    {
        // Re-use most recently ReleaseBuffer'd address
        *allocatedBuffer = mFrameCache.back();
        mFrameCache.pop_back();
    }
    return S_OK;
}

HRESULT STDMETHODCALLTYPE   DeckLinkMemoryAllocator::ReleaseBuffer (void* buffer)
{
    if (mFrameCache.size() < mFrameCacheSize)
    {
        mFrameCache.push_back(buffer);
    }
    else
    {
        // No room left in cache, so free this buffer
        VirtualFree(buffer, 0, MEM_RELEASE);

        mAllocatedSize.erase(buffer);
    }
    return S_OK;
}

HRESULT STDMETHODCALLTYPE   DeckLinkMemoryAllocator::Commit ()
{
    return S_OK;
}

HRESULT STDMETHODCALLTYPE   DeckLinkMemoryAllocator::Decommit ()
{
    while (! mFrameCache.empty())
    {
        // Cleanup any frames allocated in AllocateBuffer() but not freed in ReleaseBuffer()
        VirtualFree(mFrameCache.back(), 0, MEM_RELEASE);
        mFrameCache.pop_back();
    }
    return S_OK;
}

Return to Software Developers

Who is online

Users browsing this forum: sjatinder19 and 30 guests