Commit c459eafc authored by ahoms's avatar ahoms
Browse files

* using HwFrameCallbackGen for common buffer frame callback management

* added very simple implementation of SoftBufferMgr


git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@19 45c4679d-1946-429d-baad-37912b19538b
parent f4f103d1
......@@ -363,6 +363,7 @@ inline bool operator !=(const Roi& r1, const Roi& r2)
class FrameDim
{
public:
FrameDim();
FrameDim(const Size& size, ImageType type);
FrameDim(int width, int height, ImageType type);
......@@ -375,25 +376,27 @@ class FrameDim
static int getImageTypeDepth(ImageType type);
private:
FrameDim();
Size m_size;
ImageType m_type;
int m_depth;
};
inline FrameDim::FrameDim()
: m_size(), m_type(Bpp8)
{
m_depth = getImageTypeDepth(m_type);
}
inline FrameDim::FrameDim(const Size& size, ImageType type)
: m_size(size), m_type(type)
{
m_size = size;
m_type = type;
m_depth = getImageTypeDepth(type);
m_depth = getImageTypeDepth(m_type);
}
inline FrameDim::FrameDim(int width, int height, ImageType type)
: m_size(Size(width, height)), m_type(type)
{
m_size = Size(width, height);
m_type = type;
m_depth = getImageTypeDepth(type);
m_depth = getImageTypeDepth(m_type);
}
inline const Size& FrameDim::getSize() const
......
......@@ -6,12 +6,15 @@
namespace lima
{
class HwBufferCtrlObj
class HwBufferCtrlObj : public HwFrameCallbackGen
{
public:
HwBufferCtrlObj();
virtual ~HwBufferCtrlObj();
virtual void setFrameDim(const FrameDim& frame_dim) = 0;
virtual void getFramedim( FrameDim& frame_dim) = 0;
virtual void setNbBuffers(int nb_buffers) = 0;
virtual void getNbBuffers(int& nb_buffers) = 0;
......@@ -30,8 +33,6 @@ public:
virtual void *getBufferPtr(int buffer_nb) = 0;
virtual void *getFramePtr(int acq_frame_nb) = 0;
virtual double getFrameTimeStamp(int acq_frame_nb) = 0;
private:
};
} // namespace lima
......
#ifndef HWBUFFERMGR_H
#define HWBUFFERMGR_H
#include "HwFrameCallback.h"
#include "SizeUtils.h"
#include <vector>
namespace lima
{
class BaseBufferMgr : HwFrameCallbackGen
{
public:
virtual int getMaxNbBuffers(const FrameDim& frame_dim) = 0;
virtual void allocBuffers(int nb_buffers,
const FrameDim& frame_dim) = 0;
virtual const FrameDim& getFrameDim() = 0;
virtual int getNbBuffers() = 0;
virtual void releaseBuffers() = 0;
virtual void *getBufferPtr(int buffer_nb) = 0;
virtual double getBufferTimestamp(int buffer_nb) = 0;
};
class SoftBufferMgr : public BaseBufferMgr
{
public:
SoftBufferMgr();
virtual ~SoftBufferMgr();
virtual int getMaxNbBuffers(const FrameDim& frame_dim);
virtual void allocBuffers(int nb_buffers,
const FrameDim& frame_dim);
virtual const FrameDim& getFrameDim() const;
virtual int getNbBuffers() const;
virtual void releaseBuffers();
virtual void *getBufferPtr(int buffer_nb) const;
virtual double getBufferTimestamp(int buffer_nb);
private:
typedef std::vector<char *> BufferList;
typedef BufferList::const_iterator BufferListCIt;
FrameDim m_frame_dim;
BufferList m_buffer_list;
};
inline const FrameDim& SoftBufferMgr::getFrameDim() const
{
return m_frame_dim;
}
inline int SoftBufferMgr::getNbBuffers() const
{
return m_buffer_list.size();
}
inline void *SoftBufferMgr::getBufferPtr(int buffer_nb) const
{
return m_buffer_list[buffer_nb];
}
inline double SoftBufferMgr::getBufferTimestamp(int buffer_nb)
{
return 0;
}
class ConcatBufferMgr : public BaseBufferMgr
{
};
class AccBufferMgr : public BaseBufferMgr
{
};
} // namespace lima
#endif // HWBUFFERMGR_H
......@@ -6,20 +6,70 @@
namespace lima
{
class HwBufferCtrlObj;
class HwFrameCallback;
/*******************************************************************
* \class HwFrameCallbackGen
* \brief Abstract class with interface for frame callback generation
*
* This class specifies the basic functionality for objects generating
* frame callbacks
*******************************************************************/
class HwFrameCallbackGen
{
public:
virtual ~HwFrameCallbackGen();
void registerFrameCallback(HwFrameCallback *frame_cb);
void unregisterFrameCallback(HwFrameCallback *frame_cb);
protected:
HwFrameCallbackGen();
virtual void setFrameCallbackActive(bool cb_active) = 0;
private:
HwFrameCallback *m_frame_cb;
};
/*******************************************************************
* \class HwFrameCallback
* \brief Base class for classes receiving frame callbacks
*
*******************************************************************/
class HwFrameCallback
{
public:
typedef struct Info {
typedef struct FrameInfo {
int acq_frame_nb;
void *frame_ptr;
const FrameDim& frame_dim;
double frame_time_stamp;
} InfoType;
} FrameInfoType;
HwFrameCallback() : m_frame_cb_gen(NULL) {}
virtual ~HwFrameCallback();
HwFrameCallbackGen *getFrameCallbackGen() const;
virtual bool newFrameReady(const FrameInfoType& frame_info) = 0;
private:
friend class HwFrameCallbackGen;
void setFrameCallbackGen(HwFrameCallbackGen *frame_cb_gen);
HwFrameCallbackGen *m_frame_cb_gen;
};
inline HwFrameCallbackGen *HwFrameCallback::getFrameCallbackGen() const
{
return m_frame_cb_gen;
}
} // namespace lima
#endif // HWFRAMECALLBACK_H
......@@ -9,3 +9,4 @@ HwBufferCtrlObj::HwBufferCtrlObj()
HwBufferCtrlObj::~HwBufferCtrlObj()
{
}
#include "HwBufferMgr.h"
using namespace lima;
SoftBufferMgr::SoftBufferMgr()
{
}
SoftBufferMgr::~SoftBufferMgr()
{
releaseBuffers();
}
int SoftBufferMgr::getMaxNbBuffers(const FrameDim& frame_dim)
{
return 0;
}
void SoftBufferMgr::allocBuffers(int nb_buffers,
const FrameDim& frame_dim)
{
int frame_size = frame_dim.getMemSize();
if (frame_size <= 0)
throw LIMA_HW_EXC(InvalidValue, "Invalid FrameDim");
BufferList& bl = m_buffer_list;
bl.reserve(nb_buffers);
try {
for (int i = 0; i < nb_buffers; ++i)
bl.push_back(new char[frame_size]);
} catch (...) {
releaseBuffers();
throw;
}
m_frame_dim = frame_dim;
}
void SoftBufferMgr::releaseBuffers()
{
BufferList& bl = m_buffer_list;
for (BufferListCIt it = bl.begin(); it != bl.end(); ++it)
delete [] *it;
bl.clear();
m_frame_dim = FrameDim();
}
#include "HwFrameCallback.h"
using namespace lima;
HwFrameCallbackGen::HwFrameCallbackGen()
{
m_frame_cb = NULL;
}
HwFrameCallbackGen::~HwFrameCallbackGen()
{
if (m_frame_cb != NULL)
m_frame_cb->setFrameCallbackGen(NULL);
}
HwFrameCallback::~HwFrameCallback()
{
if (m_frame_cb_gen != NULL)
m_frame_cb_gen->unregisterFrameCallback(this);
}
void HwFrameCallbackGen::registerFrameCallback(HwFrameCallback *frame_cb)
{
if (m_frame_cb != NULL)
throw LIMA_HW_EXC(InvalidValue,
"A FrameCallback is already registered");
frame_cb->setFrameCallbackGen(this);
m_frame_cb = frame_cb;
setFrameCallbackActive(true);
}
void HwFrameCallbackGen::unregisterFrameCallback(HwFrameCallback *frame_cb)
{
if (m_frame_cb != frame_cb)
throw LIMA_HW_EXC(InvalidValue,
"Specified FrameCallback is not registered");
setFrameCallbackActive(false);
m_frame_cb = NULL;
frame_cb->setFrameCallbackGen(NULL);
}
void HwFrameCallback::setFrameCallbackGen(HwFrameCallbackGen *frame_cb_gen)
{
if (frame_cb_gen && m_frame_cb_gen)
throw LIMA_HW_EXC(InvalidValue,
"HwFrameCallbackGen is already set");
else if (!frame_cb_gen && !m_frame_cb_gen)
throw LIMA_HW_EXC(InvalidValue,
"HwFrameCallbackGen is already reset");
m_frame_cb_gen = frame_cb_gen;
}
hw-objs := HwInterface.o HwCap.o HwSyncCtrlObj.o HwBufferCtrlObj.o
hw-objs := HwInterface.o HwCap.o HwSyncCtrlObj.o HwFrameCallback.o \
HwBufferCtrlObj.o HwBufferMgr.o
CXXFLAGS += -I../include -I../../common/include -Wall
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment