1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include "OniFrameManager.h"
#include <XnOSCpp.h>
ONI_NAMESPACE_IMPLEMENTATION_BEGIN
FrameManager::FrameManager()
{
}
FrameManager::~FrameManager()
{
}
OniFrameInternal* FrameManager::acquireFrame()
{
OniFrameInternal* pFrame = m_frames.Acquire();
// reset all fields
pFrame->dataSize = 0;
pFrame->data = NULL;
pFrame->sensorType = (OniSensorType)0;
pFrame->timestamp = 0;
pFrame->frameIndex = 0;
pFrame->width = 0;
pFrame->height = 0;
pFrame->videoMode.pixelFormat = (OniPixelFormat)0;
pFrame->videoMode.resolutionX = 0;
pFrame->videoMode.resolutionY = 0;
pFrame->videoMode.fps = 0;
pFrame->croppingEnabled = FALSE;
pFrame->cropOriginX = 0;
pFrame->cropOriginY = 0;
pFrame->stride = 0;
pFrame->backToPoolFunc = NULL;
pFrame->backToPoolFuncCookie = NULL;
pFrame->refCount = 1; // this is the only reference
pFrame->freeBufferFunc = NULL;
pFrame->freeBufferFuncCookie = NULL;
return pFrame;
}
void FrameManager::addRef(OniFrame* pFrame)
{
OniFrameInternal* pInternal = (OniFrameInternal*)pFrame;
m_frames.Lock();
++pInternal->refCount;
m_frames.Unlock();
}
void FrameManager::release(OniFrame* pFrame)
{
OniFrameInternal* pInternal = (OniFrameInternal*)pFrame;
m_frames.Lock();
if (--pInternal->refCount == 0)
{
// notify frame is back to pool
if (pInternal->backToPoolFunc != NULL)
{
pInternal->backToPoolFunc(pInternal, pInternal->backToPoolFuncCookie);
}
// and return frame to pool
m_frames.Release(pInternal);
}
m_frames.Unlock();
}
ONI_NAMESPACE_IMPLEMENTATION_END
|