Commit 0cef248f authored by Sebastien Petitdemange's avatar Sebastien Petitdemange
Browse files

add callback for buffer usage (it's compile)

parent 509fce49
......@@ -87,14 +87,18 @@ namespace lima {
bool isAccumulationActive() const {return !!m_ct_accumulation;}
static void getDataFromHwFrameInfo(Data&,const HwFrameInfoType&,
int readBlockLen=1);
void getDataFromHwFrameInfo(Data&,const HwFrameInfoType&,
int readBlockLen=1);
private:
HwBufferCtrlObj* m_hw_buffer;
CtBufferFrameCB* m_frame_cb;
Parameters m_pars;
CtAccumulation* m_ct_accumulation;
class _DataDestroyCallback;
friend class _DataDestroyCallback;
HwBufferCtrlObj* m_hw_buffer;
CtBufferFrameCB* m_frame_cb;
Parameters m_pars;
CtAccumulation* m_ct_accumulation;
HwBufferCtrlObj::Callback* m_hw_buffer_cb;
Buffer::Callback* m_data_destroy_callback;
};
inline std::ostream& operator<<(std::ostream &os,
......
......@@ -62,6 +62,6 @@ using namespace lima;
bool isAccumulationActive() const;
static void getDataFromHwFrameInfo(Data& /Out/,const HwFrameInfoType&,
int readBlockLen=1);
void getDataFromHwFrameInfo(Data& /Out/,const HwFrameInfoType&,
int readBlockLen=1);
};
......@@ -24,13 +24,26 @@
using namespace lima;
class CtBuffer::_DataDestroyCallback : public Buffer::Callback
{
public:
_DataDestroyCallback(CtBuffer &buffer) : m_buffer(buffer) {}
virtual void destroy(void *dataPt)
{
m_buffer.m_hw_buffer_cb->release(dataPt);
}
private:
CtBuffer& m_buffer;
};
bool CtBufferFrameCB::newFrameReady(const HwFrameInfoType& frame_info)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(frame_info);
Data fdata;
CtBuffer::getDataFromHwFrameInfo(fdata,frame_info);
m_ct->buffer()->getDataFromHwFrameInfo(fdata,frame_info);
if(m_ct_accumulation)
return m_ct_accumulation->_newFrameReady(fdata);
else
......@@ -38,13 +51,18 @@ bool CtBufferFrameCB::newFrameReady(const HwFrameInfoType& frame_info)
}
CtBuffer::CtBuffer(HwInterface *hw)
: m_frame_cb(NULL),m_ct_accumulation(NULL)
: m_frame_cb(NULL),m_ct_accumulation(NULL),
m_data_destroy_callback(NULL)
{
DEB_CONSTRUCTOR();
if (!hw->getHwCtrlObj(m_hw_buffer))
throw LIMA_CTL_EXC(Error, "Cannot get hardware buffer object");
m_hw_buffer_cb = m_hw_buffer->getBufferCallback();
if(m_hw_buffer_cb)
m_data_destroy_callback = new _DataDestroyCallback(*this);
}
CtBuffer::~CtBuffer()
......@@ -52,6 +70,7 @@ CtBuffer::~CtBuffer()
DEB_DESTRUCTOR();
unregisterFrameCallback();
delete m_data_destroy_callback;
}
void CtBuffer::registerFrameCallback(CtControl *ct)
......@@ -231,6 +250,9 @@ void CtBuffer::setup(CtControl *ct)
m_pars.nbBuffers = nbuffers;
registerFrameCallback(ct);
m_frame_cb->m_ct_accumulation = m_ct_accumulation;
if(m_hw_buffer_cb)
m_hw_buffer_cb->releaseAll();
}
void CtBuffer::getDataFromHwFrameInfo(Data &fdata,
......@@ -279,7 +301,13 @@ void CtBuffer::getDataFromHwFrameInfo(Data &fdata,
fdata.setBuffer(fbuf);
fbuf->unref();
// Manage Buffer callback
if(m_hw_buffer_cb)
{
m_hw_buffer_cb->map(frame_info.frame_ptr);
fbuf->callback = m_data_destroy_callback;
}
DEB_RETURN() << DEB_VAR1(fdata);
}
// -----------------
......
......@@ -55,6 +55,16 @@ public:
virtual void registerFrameCallback(HwFrameCallback& frame_cb) = 0;
virtual void unregisterFrameCallback(HwFrameCallback& frame_cb) = 0;
class Callback
{
public:
virtual void map(void *address) = 0;
virtual void release(void *address) = 0;
virtual void releaseAll() = 0;
};
virtual Callback* getBufferCallback() {return NULL;}
};
} // namespace lima
......
......@@ -28,6 +28,7 @@
#include "MemUtils.h"
#include <vector>
#include <set>
namespace lima
{
......@@ -275,14 +276,15 @@ class LIMACORE_API BufferCtrlMgr : public HwFrameCallbackGen
/** @brief this class is a basic software allocation class,
* It can be directly provide to the control layer as a HwBufferCtrlObj
*/
class SoftBufferCtrlMgr : public HwBufferCtrlObj
class LIMACORE_API SoftBufferCtrlMgr : public HwBufferCtrlObj
{
public:
SoftBufferCtrlMgr() :
HwBufferCtrlObj(),
m_buffer_cb_mgr(m_buffer_alloc_mgr),
m_mgr(m_buffer_cb_mgr),
m_acq_frame_nb(-1)
m_acq_frame_nb(-1),
m_buffer_callback(NULL)
{}
virtual void setFrameDim(const FrameDim& frame_dim) {m_mgr.setFrameDim(frame_dim);}
......@@ -315,11 +317,33 @@ class SoftBufferCtrlMgr : public HwBufferCtrlObj
StdBufferCbMgr& getBuffer() {return m_buffer_cb_mgr;}
int getNbAcquiredFrames() {return m_acq_frame_nb + 1;}
class LIMACORE_API Sync : public HwBufferCtrlObj::Callback
{
friend class SoftBufferCtrlMgr;
public:
enum Status {AVAILABLE,TIMEOUT,INTERRUPTED};
Status wait(int frame_number,double timeout = -1.);
protected:
virtual void map(void *address);
virtual void release(void *address);
virtual void releaseAll();
private:
Sync(SoftBufferCtrlMgr&,Cond&);
Cond& m_cond;
SoftBufferCtrlMgr& m_buffer_mgr;
std::set<void*> m_buffer_in_use;
};
Sync* getBufferSync(Cond&);
virtual HwBufferCtrlObj::Callback* getBufferCallback() {return m_buffer_callback;}
protected:
SoftBufferAllocMgr m_buffer_alloc_mgr;
StdBufferCbMgr m_buffer_cb_mgr;
BufferCtrlMgr m_mgr;
int m_acq_frame_nb;
SoftBufferAllocMgr m_buffer_alloc_mgr;
StdBufferCbMgr m_buffer_cb_mgr;
BufferCtrlMgr m_mgr;
int m_acq_frame_nb;
HwBufferCtrlObj::Callback* m_buffer_callback;
};
} // namespace lima
......
......@@ -672,3 +672,65 @@ BufferCtrlMgr::AcqFrameCallback::newFrameReady(const HwFrameInfoType& finfo)
DEB_MEMBER_FUNCT();
return m_buffer_mgr->acqFrameReady(finfo);
}
/*****************************************************************************
SoftBufferCtrlMgr
****************************************************************************/
SoftBufferCtrlMgr::Sync* SoftBufferCtrlMgr::getBufferSync(Cond &cond)
{
if(!m_buffer_callback)
m_buffer_callback = new Sync(*this,cond);
return (SoftBufferCtrlMgr::Sync*)m_buffer_callback;
}
SoftBufferCtrlMgr::Sync::Sync(SoftBufferCtrlMgr &mgr,
Cond &cond) :
m_cond(cond),
m_buffer_mgr(mgr)
{
}
SoftBufferCtrlMgr::Sync::Status
SoftBufferCtrlMgr::Sync::wait(int frame_number,double timeout)
{
AutoMutex aLock(m_cond.mutex());
void *framePtr = m_buffer_mgr.getBuffer().getFrameBufferPtr(frame_number);
std::set<void*>::iterator i = m_buffer_in_use.find(framePtr);
bool okFlag = true;
if(i != m_buffer_in_use.end())
okFlag = m_cond.wait(timeout);
if(okFlag)
{
i = m_buffer_in_use.find(framePtr);
return i == m_buffer_in_use.end() ? AVAILABLE : INTERRUPTED;
}
else
return TIMEOUT;
}
void SoftBufferCtrlMgr::Sync::map(void *address)
{
AutoMutex aLock(m_cond.mutex());
m_buffer_in_use.insert(address);
}
void SoftBufferCtrlMgr::Sync::release(void *address)
{
AutoMutex aLock(m_cond.mutex());
std::set<void*>::iterator i = m_buffer_in_use.find(address);
if(i != m_buffer_in_use.end())
{
m_buffer_in_use.erase(i);
m_cond.broadcast();
}
}
void SoftBufferCtrlMgr::Sync::releaseAll()
{
AutoMutex aLock(m_cond.mutex());
m_buffer_in_use.clear();
m_cond.broadcast();
}
Processlib @ 6deba4cf
Subproject commit 13d3262e8422039937bcb09c39cfd03fe97c91b7
Subproject commit 6deba4cfd03e5919522bc3f8382b315833e2e041
Supports Markdown
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