Commit 04c6be38 authored by seb's avatar seb
Browse files

- add owner ship into HwFrameInfo

- change HwFrameInfo wrapping add set frame_ptr
- Should test all this staff


git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@223 45c4679d-1946-429d-baad-37912b19538b
parent be002067
from __future__ import with_statement
import weakref
import threading
import lima
class _ImageReader(threading.Thread) :
def __init__(self,buffer_ctrl) :
_ImageReader.__init__(self)
self.__cond = threading.Condition()
self.__continue = True
def run(self) :
with self.__cond:
while(self.__continue) :
pass
class BufferCtrlObj(lima.HwBufferCtrlObj):
DEB_CLASS(DebModCamera,"BufferCtrlObj","Pilatus")
......@@ -11,6 +26,7 @@ class BufferCtrlObj(lima.HwBufferCtrlObj):
self.__com = weakref.ref(comm_object)
self.__det_info = weakref.ref(det_info)
self.__cbk = None
self.__nb_buffer = 1
@DEB_MEMBER_FUNCT
def setFrameDim(self,frame_dim) :
......@@ -24,12 +40,11 @@ class BufferCtrlObj(lima.HwBufferCtrlObj):
@DEB_MEMBER_FUNCT
def setNbBuffers(self,nb_buffers) :
if nb_buffers != 1:
raise lima.Exceptions(lima.Hardware,lima.NotSupported)
self.__nb_buffer = nb_buffers
@DEB_MEMBER_FUNCT
def getNbBuffers(self) :
return 1
return self.__nb_buffer
@DEB_MEMBER_FUNCT
def setNbConcatFrames(self,nb_concat_frames) :
......@@ -52,7 +67,11 @@ class BufferCtrlObj(lima.HwBufferCtrlObj):
@DEB_MEMBER_FUNCT
def getMaxNbBuffers(self) :
return 1
com = self.__com()
det_info = self.__det_info()
imageFormat = det_info.getMaxImageSize()
imageSize = imageFormat.getWidth() * imageFormat.getHeight() * 4 # 4 == image 32bits
return com.DEFAULT_TMPFS_SIZE / imageSize
@DEB_MEMBER_FUNCT
def getBufferPtr(self,buffer_nb,concat_frame_nb = 0) :
......
......@@ -152,6 +152,7 @@ class Communication:
INTERNAL,EXTERNAL_START,EXTERNAL_MULTI_START,EXTERNAL_GATE = range(4)
DEFAULT_PATH = '/lima_data'
DEFAULT_TMPFS_SIZE = 8 * 1024 * 1024 * 1024 # 8Go
DEFAULT_FILE_NAME = 'tmp_img_00000.edf'
def __init__(self, host = None, port = None):
......
......@@ -216,9 +216,18 @@ void CtBuffer::getDataFromHwFrameInfo(Data &fdata,
fdata.frameNumber= frame_info.acq_frame_nb;
fdata.timestamp = frame_info.frame_timestamp;
Buffer *fbuf = new Buffer();
fbuf->owner = Buffer::MAPPED;
fbuf->data = frame_info.frame_ptr;
Buffer *fbuf = NULL;
if(frame_info.owner_ship == HwFrameInfoType::TRANSFERT)
{
fbuf = new Buffer(fdata.size());
memcpy(fbuf->data,frame_info.frame_ptr,fdata.size());
}
else
{
fbuf = new Buffer();
fbuf->owner = Buffer::MAPPED;
fbuf->data = frame_info.frame_ptr;
}
fdata.setBuffer(fbuf);
fbuf->unref();
......
......@@ -16,20 +16,23 @@ namespace lima
*******************************************************************/
typedef struct HwFrameInfo {
enum OwnerShip {MANAGED,TRANSFERT};
int acq_frame_nb;
void *frame_ptr;
const FrameDim *frame_dim;
Timestamp frame_timestamp;
int valid_pixels;
OwnerShip owner_ship;
HwFrameInfo()
: acq_frame_nb(-1), frame_ptr(NULL), frame_dim(NULL),
frame_timestamp(), valid_pixels(0) {}
frame_timestamp(), valid_pixels(0), owner_ship(MANAGED) {}
HwFrameInfo(int frame_nb, void *ptr, const FrameDim *dim,
Timestamp timestamp, int pixels)
Timestamp timestamp, int pixels, OwnerShip owner = MANAGED)
: acq_frame_nb(frame_nb), frame_ptr(ptr), frame_dim(dim),
frame_timestamp(timestamp), valid_pixels(pixels) {}
frame_timestamp(timestamp), valid_pixels(pixels),owner_ship(owner) {}
bool isValid() const;
} HwFrameInfoType;
......
......@@ -8,7 +8,7 @@ struct HwFrameInfoType
#include <sstream>
using namespace lima;
%End
enum OwnerShip {MANAGED,TRANSFERT};
int acq_frame_nb;
......@@ -34,22 +34,65 @@ using namespace lima;
sipPy = PyArray_SimpleNewFromData(2, dims, arr_type,
sipCpp->frame_ptr);
%End
%SetCode
PyArrayObject *tmpObject = (PyArrayObject*)PyArray_ContiguousFromObject(sipPy,NPY_NOTYPE,0,0);
if(!tmpObject) sipErr = 1;
if(!sipErr)
{
int nbDim = PyArray_NDIM(tmpObject);
if(nbDim > 2) sipErr = 1;
if(!sipErr)
{
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:
sipErr = 1;
}
if(!sipErr)
{
FrameDim *newFrameDim = new 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();
HwFrameInfoType(int frame_nb, SIP_PYOBJECT arr, FrameDim *dim,
Timestamp timestamp, int pixels);
Timestamp timestamp, int pixels,
HwFrameInfoType::OwnerShip = HwFrameInfoType::MANAGED);
%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);
sipCpp = new HwFrameInfoType(a0, PyArray_DATA(a1), a2, *a3, a4, a5);
%End
const char* __repr__();
%MethodCode
......
......@@ -14,9 +14,11 @@ ostream& lima::operator <<(ostream& os, const HwFrameInfoType& info)
{
os << "<"
<< "acq_frame_nb=" << info.acq_frame_nb << ", "
<< "frame_ptr=" << info.frame_ptr << ", "
<< "frame_dim=" << *info.frame_dim << ", "
<< "time_stamp=" << fixed << setprecision(6)
<< "frame_ptr=" << info.frame_ptr << ", ";
if(info.frame_dim)
os << "frame_dim=" << *info.frame_dim << ", ";
os << "time_stamp=" << fixed << setprecision(6)
<< info.frame_timestamp << setprecision(0) << ", "
<< "valid_pixels=" << info.valid_pixels
<< ">";
......
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