61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
/*
|
|
*******************************************************************************
|
|
* INCLUDE
|
|
*******************************************************************************
|
|
*/
|
|
#include "CodecCapabilityManager.h"
|
|
|
|
namespace Video
|
|
{
|
|
namespace Core
|
|
{
|
|
/*
|
|
*******************************************************************************
|
|
* CLASS DEFINE
|
|
*******************************************************************************
|
|
*/
|
|
const int CodecCapabilityManager::INVALID_HANDLE = -1;
|
|
|
|
CodecCapabilityManager::CodecCapabilityManager(uint64_t total): _total(total), _handles(1024)
|
|
{
|
|
}
|
|
|
|
CodecCapabilityManager::Handle CodecCapabilityManager::alloc(uint32_t width, uint32_t height, uint32_t frameRate)
|
|
{
|
|
uint64_t v = width * height * frameRate;
|
|
Poco::FastMutex::ScopedLock lock(_lock);
|
|
if (v <= _total)
|
|
{
|
|
try
|
|
{
|
|
Handle h = _handles.allocHandle();
|
|
_allocRecord[h] = v;
|
|
_total -= v;
|
|
return h;
|
|
}
|
|
catch (...)
|
|
{
|
|
}
|
|
}
|
|
|
|
return INVALID_HANDLE;
|
|
}
|
|
|
|
void CodecCapabilityManager::free(Handle handle)
|
|
{
|
|
if (handle != INVALID_HANDLE)
|
|
{
|
|
Poco::FastMutex::ScopedLock lock(_lock);
|
|
try
|
|
{
|
|
_handles.freeHandle(handle);
|
|
_total += _allocRecord[handle];
|
|
_allocRecord.erase(handle);
|
|
}
|
|
catch (...)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|