Commit 916b725a authored by seb's avatar seb
Browse files

- change OwnerShip into HwFrameInfo :

	TRANSFERT -> Transfer
	MANAGED   -> Managed
- move frame_dim from a pointer to a structur into HwFrameInfo
- modify all constructer call and access to HwFrameInfo


git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@224 45c4679d-1946-429d-baad-37912b19538b
parent 04c6be38
......@@ -373,7 +373,7 @@ void Acq::real2virtFrameInfo(const struct img_frame_info& real_info,
virt_info.acq_frame_nb = real_info.acq_frame_nr;
virt_info.frame_ptr = buffer_ptr + frame_offset;
virt_info.frame_dim = &m_frame_dim;
virt_info.frame_dim = m_frame_dim;
virt_info.frame_timestamp = USec2Sec(real_info.time_us);
virt_info.valid_pixels = real_info.pixels;
}
......
......@@ -96,7 +96,8 @@ int main(int argc, char *argv[])
Timestamp t = Timestamp::now() - start;
int pixels = Point(frame_dim.getSize()).getArea();
void *buffer = buffer_mgr.getBufferPtr(0);
HwFrameInfoType finfo(i, buffer, &frame_dim, t, pixels);
HwFrameInfoType finfo(i, buffer, &frame_dim, t, pixels,
HwFrameInfoType::Managed);
bs.writeFrame(finfo);
cout << "Written frame number " << i << endl << flush;
}
......
......@@ -49,7 +49,7 @@ bool FoclaFrameCallback::newFrameReady( const HwFrameInfoType &frame_info )
Data aNewData = Data();
aNewData.frameNumber = frame_info.acq_frame_nb;
const Size &aSize = frame_info.frame_dim->getSize();
const Size &aSize = frame_info.frame_dim.getSize();
aNewData.width = aSize.getWidth();
aNewData.height = aSize.getHeight();
aNewData.type = Data::UINT16;
......
......@@ -85,7 +85,8 @@ void SoftRoiCallback::data2FrameInfo(Data& data, HwFrameInfoType& finfo,
int valid_pixels = Point(fdim.getSize()).getArea();
finfo = HwFrameInfoType(data.frameNumber, data.data(), &fdim,
start_ts - Timestamp::now(), valid_pixels);
start_ts - Timestamp::now(), valid_pixels,
HwFrameInfoType::Managed);
}
void SoftRoiCallback::finished(Data& data)
......@@ -158,11 +159,11 @@ void TestFrameCallback::frameInfo2Data(const HwFrameInfoType& frame_info,
DEB_MEMBER_FUNCT();
data.frameNumber = frame_info.acq_frame_nb;
const Size &aSize = frame_info.frame_dim->getSize();
const Size &aSize = frame_info.frame_dim.getSize();
data.width = aSize.getWidth();
data.height = aSize.getHeight();
ImageType image_type = frame_info.frame_dim->getImageType();
ImageType image_type = frame_info.frame_dim.getImageType();
switch (image_type) {
case Bpp8:
data.type = Data::UINT8; break;
......
......@@ -80,10 +80,10 @@ bool TestFrameCallback::newFrameReady(const HwFrameInfoType& frame_info)
if (((acq_frame_nb + 1) % m_nb_stripes) == 0) {
Point factor(1, m_nb_stripes);
m_buffer_dim = *frame_info.frame_dim * factor;
m_buffer_dim = frame_info.frame_dim * factor;
m_buffer_info = frame_info;
m_buffer_info.frame_ptr = m_buffer_ptr;
m_buffer_info.frame_dim = &m_buffer_dim;
m_buffer_info.frame_dim = m_buffer_dim;
m_buffer_info.valid_pixels *= m_nb_stripes;
DEB_ALWAYS() << "Buffer ready: " << m_buffer_info;
......
......@@ -53,7 +53,8 @@ int main( void )
Timestamp t = Timestamp::now() - start;
int pixels = Point(fd.getSize()).getArea();
HwFrameInfoType finfo(frame_nb, buffer, &fd, t, pixels);
HwFrameInfoType finfo(frame_nb, buffer, &fd, t, pixels,
HwFrameInfoType::Managed);
bs.writeFrame(finfo);
}
......
......@@ -101,7 +101,7 @@ void BufferSave::writeEdfHeader( const HwFrameInfoType& finfo )
ctime_r(&ctime_now, time_str);
time_str[strlen(time_str) - 1] = '\0';
const FrameDim *fdim = finfo.frame_dim;
const FrameDim *fdim = &finfo.frame_dim;
const Size& frame_size = fdim->getSize();
int depth = fdim->getDepth();
int image_nb = m_written_frames + 1;
......@@ -146,7 +146,7 @@ void BufferSave::writeEdfHeader( const HwFrameInfoType& finfo )
*******************************************************************/
void BufferSave::writeFrame( const HwFrameInfoType& finfo )
{
const FrameDim *fdim = finfo.frame_dim;
const FrameDim *fdim = &finfo.frame_dim;
if (!fdim)
throw LIMA_HW_EXC(InvalidValue, "Null finfo.fdim");
......
......@@ -197,7 +197,7 @@ void CtBuffer::getDataFromHwFrameInfo(Data &fdata,
ImageType ftype;
Size fsize;
ftype= frame_info.frame_dim->getImageType();
ftype= frame_info.frame_dim.getImageType();
switch (ftype) {
case Bpp8:
fdata.type= Data::UINT8; break;
......@@ -210,14 +210,14 @@ void CtBuffer::getDataFromHwFrameInfo(Data &fdata,
fdata.type= Data::UINT32; break;
}
fsize= frame_info.frame_dim->getSize();
fsize= frame_info.frame_dim.getSize();
fdata.width= fsize.getWidth();
fdata.height= fsize.getHeight();
fdata.frameNumber= frame_info.acq_frame_nb;
fdata.timestamp = frame_info.frame_timestamp;
Buffer *fbuf = NULL;
if(frame_info.owner_ship == HwFrameInfoType::TRANSFERT)
if(frame_info.buffer_owner_ship == HwFrameInfoType::Transfer)
{
fbuf = new Buffer(fdata.size());
memcpy(fbuf->data,frame_info.frame_ptr,fdata.size());
......
......@@ -16,23 +16,27 @@ namespace lima
*******************************************************************/
typedef struct HwFrameInfo {
enum OwnerShip {MANAGED,TRANSFERT};
enum OwnerShip {Managed,Transfer};
int acq_frame_nb;
void *frame_ptr;
const FrameDim *frame_dim;
FrameDim frame_dim;
Timestamp frame_timestamp;
int valid_pixels;
OwnerShip owner_ship;
OwnerShip buffer_owner_ship;
HwFrameInfo()
: acq_frame_nb(-1), frame_ptr(NULL), frame_dim(NULL),
frame_timestamp(), valid_pixels(0), owner_ship(MANAGED) {}
: acq_frame_nb(-1), frame_ptr(NULL), frame_dim(),
frame_timestamp(), valid_pixels(0), buffer_owner_ship(Managed) {}
HwFrameInfo(int frame_nb, void *ptr, const FrameDim *dim,
Timestamp timestamp, int pixels, OwnerShip owner = MANAGED)
: acq_frame_nb(frame_nb), frame_ptr(ptr), frame_dim(dim),
frame_timestamp(timestamp), valid_pixels(pixels),owner_ship(owner) {}
Timestamp timestamp, int pixels, OwnerShip owner)
: acq_frame_nb(frame_nb), frame_ptr(ptr), frame_dim(),
frame_timestamp(timestamp), valid_pixels(pixels),buffer_owner_ship(owner)
{
if(dim)
frame_dim = *dim;
}
bool isValid() const;
} HwFrameInfoType;
......
......@@ -8,22 +8,22 @@ struct HwFrameInfoType
#include <sstream>
using namespace lima;
%End
enum OwnerShip {MANAGED,TRANSFERT};
enum OwnerShip {Managed,Transfer};
int acq_frame_nb;
void *frame_ptr;
void *frame_data;
%GetCode
if(!sipCpp->frame_ptr || !sipCpp->frame_dim)
if(!sipCpp->frame_ptr || !sipCpp->frame_dim.isValid())
return Py_None;
Size size = sipCpp->frame_dim->getSize();
Size size = sipCpp->frame_dim.getSize();
npy_intp dims[2] = {
size.getHeight(), size.getWidth()
};
int arr_type;
ImageType image_type = sipCpp->frame_dim->getImageType();
ImageType image_type = sipCpp->frame_dim.getImageType();
switch (image_type) {
case Bpp8: arr_type = NPY_UBYTE; break;
case Bpp16: arr_type = NPY_USHORT; break;
......@@ -42,7 +42,7 @@ if(!tmpObject) sipErr = 1;
if(!sipErr)
{
int nbDim = PyArray_NDIM(tmpObject);
if(nbDim > 2) sipErr = 1;
if(nbDim != 2) sipErr = 1;
if(!sipErr)
{
......@@ -59,40 +59,51 @@ if(!sipErr)
if(!sipErr)
{
FrameDim *newFrameDim = new FrameDim(PyArray_DIM(tmpObject,1),
sipCpp->frame_dim = FrameDim(PyArray_DIM(tmpObject,1),
PyArray_DIM(tmpObject,0),
image_type);
sipCpp->frame_dim = newFrameDim;
sipCpp->frame_ptr = PyArray_DATA(tmpObject);
PyObject *frame_dimPt = sipConvertFromInstance(const_cast<FrameDim *>(newFrameDim),
sipClass_FrameDim,NULL);
PyObject *namePt = PyString_FromString("_hide_frame_dim");
PyObject_SetAttr(sipPy,namePt,frame_dimPt);
Py_DECREF(namePt);
Py_DECREF(frame_dimPt);
}
}
}
Py_DECREF(tmpObject);
%End
const FrameDim *frame_dim;
Timestamp frame_timestamp;
int valid_pixels;
HwFrameInfoType::OwnerShip owner_ship;
HwFrameInfoType::OwnerShip buffer_owner_ship;
HwFrameInfoType();
HwFrameInfoType(int frame_nb, SIP_PYOBJECT arr, FrameDim *dim,
HwFrameInfoType(int frame_nb, SIP_PYOBJECT arr,
Timestamp timestamp, int pixels,
HwFrameInfoType::OwnerShip = HwFrameInfoType::MANAGED);
HwFrameInfoType::OwnerShip);
%MethodCode
PyArrayObject *arr;
arr = (PyArrayObject *) PyArray_ContiguousFromObject(a1, NPY_NOTYPE,
0, 0);
if (!arr)
return NULL; //should throw an error
sipCpp = new HwFrameInfoType(a0, PyArray_DATA(a1), a2, *a3, a4, a5);
PyArrayObject *tmpObject = (PyArrayObject *) PyArray_ContiguousFromObject(a1, NPY_NOTYPE,
0, 0);
if (tmpObject)
{
int nbDim = PyArray_NDIM(tmpObject);
if(nbDim == 2)
{
ImageType image_type;
switch(tmpObject->descr->type_num)
{
case NPY_UBYTE: image_type = Bpp8; break;
case NPY_USHORT: image_type = Bpp16; break;
case NPY_UINT32: image_type = Bpp32; break;
default:
goto clean;
}
FrameDim tmpFrameDim(PyArray_DIM(tmpObject,1),
PyArray_DIM(tmpObject,0),
image_type);
sipCpp = new HwFrameInfoType(a0, PyArray_DATA(a1),&tmpFrameDim, *a2, a3, a4);
}
clean:
Py_DECREF(tmpObject);
}
%End
const char* __repr__();
%MethodCode
......
......@@ -350,10 +350,10 @@ bool StdBufferCbMgr::newFrameReady(HwFrameInfoType& frame_info)
}
const FrameDim& frame_dim = getFrameDim();
if (!frame_info.frame_dim) {
frame_info.frame_dim = &frame_dim;
} else if (*frame_info.frame_dim != frame_dim) {
DEB_ERROR() << "Invalid " << DEB_VAR1(*frame_info.frame_dim);
if (!frame_info.frame_dim.isValid()) {
frame_info.frame_dim = frame_dim;
} else if (frame_info.frame_dim != frame_dim) {
DEB_ERROR() << "Invalid " << DEB_VAR1(frame_info.frame_dim);
throw LIMA_HW_EXC(InvalidValue, "Invalid frame dim");
}
if (frame_info.valid_pixels == 0)
......@@ -701,7 +701,7 @@ bool BufferCtrlMgr::acqFrameReady(const HwFrameInfoType& acq_frame_info)
void *aux_frame_ptr = aux_mgr.getBufferPtr(aux_buffer_nb,
aux_buffer_frame);
const FrameDim& acq_frame_dim = *acq_frame_info.frame_dim;
const FrameDim& acq_frame_dim = acq_frame_info.frame_dim;
const FrameDim& aux_frame_dim = aux_mgr.getFrameDim();
int valid_pixels = acq_frame_info.valid_pixels;
......@@ -717,7 +717,8 @@ bool BufferCtrlMgr::acqFrameReady(const HwFrameInfoType& acq_frame_info)
aux_mgr.getStartTimestamp(start_ts);
Timestamp frame_ts = Timestamp::now() - start_ts;
HwFrameInfoType aux_frame_info(aux_frame_nb, aux_frame_ptr,
&aux_frame_dim, frame_ts, valid_pixels);
&aux_frame_dim, frame_ts, valid_pixels,
HwFrameInfoType::Managed);
return newFrameReady(aux_frame_info);
}
......
......@@ -6,21 +6,25 @@ using namespace std;
bool HwFrameInfo::isValid() const
{
return (acq_frame_nb >= 0) && frame_ptr && frame_dim &&
frame_timestamp.isSet() && (valid_pixels > 0);
return (acq_frame_nb >= 0) && frame_ptr && frame_dim.isValid() &&
frame_timestamp.isSet() && (valid_pixels > 0);
}
ostream& lima::operator <<(ostream& os, const HwFrameInfoType& info)
{
const char *aBufferOwnerShipPt =
info.buffer_owner_ship == HwFrameInfoType::Managed ? "Managed" : "Transfer";
os << "<"
<< "acq_frame_nb=" << info.acq_frame_nb << ", "
<< "frame_ptr=" << info.frame_ptr << ", ";
if(info.frame_dim)
os << "frame_dim=" << *info.frame_dim << ", ";
if(info.frame_dim.isValid())
os << "frame_dim=" << info.frame_dim << ", ";
os << "time_stamp=" << fixed << setprecision(6)
<< info.frame_timestamp << setprecision(0) << ", "
<< "valid_pixels=" << info.valid_pixels
<< "valid_pixels=" << info.valid_pixels << ", "
<< "buffer_owner_ship=" << aBufferOwnerShipPt
<< ">";
return os;
......
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