SlsDetectorBuffer.h 3.08 KB
Newer Older
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
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################

#ifndef __SLS_DETECTOR_BUFFER_H
#define __SLS_DETECTOR_BUFFER_H

#include "SlsDetectorCPUAffinity.h"

#include "lima/HwBufferMgr.h"

namespace lima 
{

namespace SlsDetector
{

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
inline Data GetMappedData(void *buffer, const FrameDim& frame_dim)
{
	Data d;
	switch (frame_dim.getImageType()) {
	case Bpp8:  d.type = Data::UINT8;  break;
	case Bpp16: d.type = Data::UINT16; break;
	case Bpp32: d.type = Data::UINT32; break;
	default: throw LIMA_HW_EXC(Error, "Invalid image type");
	}
	const Size& size = frame_dim.getSize();
	d.dimensions = {size.getWidth(), size.getHeight()};
	Buffer *b = new Buffer;
	b->owner = Buffer::MAPPED;
	b->data = buffer;
	d.setBuffer(b);
	b->unref();
	return d;
}
54
55
56
57
58
59
60

class BufferCtrlObj : public NumaSoftBufferCtrlObj {

 public:
	void releaseBuffers() { getBuffer().releaseBuffers(); }

	virtual void getMaxNbBuffers(int& max_nb_buffers)
61
	{ max_nb_buffers = 1024; }
62
63
64
65

	Data getFrameData(FrameType frame)
	{
		StdBufferCbMgr& buffer = getBuffer();
66
		void *buffer_ptr = buffer.getFrameBufferPtr(frame);
67
		const FrameDim& frame_dim = buffer.getFrameDim();
68
		return GetMappedData(buffer_ptr, frame_dim);
69
70
71
72
73
74
75
76
77
78
79
80
	}
};

class BufferMgr
{
	DEB_CLASS_NAMESPC(DebModCamera, "BufferMgr", "SlsDetector");

public:
	void setLimaBufferCtrlObj(BufferCtrlObj *buffer_ctrl_obj);

	void setAcqBufferCPUAffinity(CPUAffinity buffer_affinity);

81
	void waitLimaFrame(FrameType frame_nb, AutoMutex& l);
82
83
	char *getAcqFrameBufferPtr(FrameType frame_nb);

84
85
	BufferCtrlObj *getBufferCtrlObj()
	{ return m_lima_buffer_ctrl_obj; }
86

87
	StdBufferCbMgr *getBufferCbMgr()
88
	{
89
		BufferCtrlObj *buffer = getBufferCtrlObj();
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
		return buffer ? &buffer->getBuffer() : NULL;
	}

	void setMaxMemory(short  max_memory);
	void getMaxMemory(short& max_memory);

	void getMaxNbBuffers(long& nb_buffers);

	void prepareAcq();

	void clearAllBuffers();
	void releaseBuffers();

private:
	friend class Camera;
105
	typedef BufferCtrlObj::Sync BufferSync;
106
107
108
109

	BufferMgr(Camera *cam);

	Camera *m_cam;
110
	Cond& m_cond;
111
112
	CPUAffinity m_buffer_affinity;
	BufferCtrlObj *m_lima_buffer_ctrl_obj;
113
	BufferSync *m_lima_buffer_sync;
114
115
116
117
118
119
120
121
122
	int m_max_memory;
};

} // namespace SlsDetector

} // namespace lima


#endif // __SLS_DETECTOR_BUFFER_H