SlsDetectorBuffer.h 3.42 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//###########################################################################
// 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
{

enum BufferType {
	AcqBuffer, LimaBuffer
};

class BufferCtrlObj : public NumaSoftBufferCtrlObj {

 public:
	BufferCtrlObj() : m_type(AcqBuffer) {}

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

	void setType(BufferType type)
	{
		if (type == m_type)
			return;
		releaseBuffers();
		m_type = type;
	}

	virtual void getMaxNbBuffers(int& max_nb_buffers)
	{
		if (m_type == LimaBuffer)
			max_nb_buffers = 1024;
		else
			NumaSoftBufferCtrlObj::getMaxNbBuffers(max_nb_buffers);
	}

	Data getFrameData(FrameType frame)
	{
		Data d;
		StdBufferCbMgr& buffer = getBuffer();
		const FrameDim& frame_dim = buffer.getFrameDim();
		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.getFrameBufferPtr(frame);;
		d.setBuffer(b);
		b->unref();
		return d;
	}

 private:
	BufferType m_type;
};

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

public:
	enum Mode { Single, Dual };

	void setLimaBufferCtrlObj(BufferCtrlObj *buffer_ctrl_obj);

	void setAcqBufferCPUAffinity(CPUAffinity buffer_affinity);

	char *getAcqFrameBufferPtr(FrameType frame_nb);

	BufferCtrlObj *getBufferCtrlObj(BufferType type)
	{
		bool lima = ((type == LimaBuffer) || (m_mode == Single));
		return lima ? m_lima_buffer_ctrl_obj :
			      m_acq_buffer_ctrl_obj.getPtr();
	}

	StdBufferCbMgr *getBufferCbMgr(BufferType type)
	{
		BufferCtrlObj *buffer = getBufferCtrlObj(type);
		return buffer ? &buffer->getBuffer() : NULL;
	}

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

	void getMaxNbBuffers(long& nb_buffers);

	void setMode(Mode  mode);
	void getMode(Mode& mode);

	void prepareAcq();

	void clearAllBuffers();
	void releaseBuffers();

private:
	friend class Camera;

	BufferMgr(Camera *cam);

	Camera *m_cam;
	Mode m_mode;
	CPUAffinity m_buffer_affinity;
	BufferCtrlObj *m_lima_buffer_ctrl_obj;
	AutoPtr<BufferCtrlObj> m_acq_buffer_ctrl_obj;
	int m_max_memory;
};

} // namespace SlsDetector

} // namespace lima


#endif // __SLS_DETECTOR_BUFFER_H