HwBufferMgr.h 5.31 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#ifndef HWBUFFERMGR_H
#define HWBUFFERMGR_H

#include "HwFrameCallback.h"
#include "SizeUtils.h"

#include <vector>

namespace lima
{

ahoms's avatar
ahoms committed
12
13
14
15
16
17
18
19
/*******************************************************************
 * \class BufferAllocMgr
 * \brief Abstract class defining interface for buffer allocation
 *
 * Specifies the basic functionality for allocating frame buffers
 *******************************************************************/

class BufferAllocMgr
20
21
{
 public:
ahoms's avatar
ahoms committed
22
23
	virtual ~BufferAllocMgr();

24
25
26
27
28
29
	virtual int getMaxNbBuffers(const FrameDim& frame_dim) = 0;
	virtual void allocBuffers(int nb_buffers, 
				  const FrameDim& frame_dim) = 0;
	virtual const FrameDim& getFrameDim() = 0;
	virtual int getNbBuffers() = 0;
	virtual void releaseBuffers() = 0;
ahoms's avatar
ahoms committed
30

31
	virtual void *getBufferPtr(int buffer_nb) = 0;
ahoms's avatar
ahoms committed
32
33
34

	virtual void clearBuffer(int buffer_nb);
	virtual void clearAllBuffers();
35
36
37
};


ahoms's avatar
ahoms committed
38
39
40
41
42
43
44
45
/*******************************************************************
 * \class SoftBufferAllocMgr
 * \brief Simple full software implementation of BufferAllocMgr
 *
 * This classes uses new and delete to allocate the memory buffers
 *******************************************************************/

class SoftBufferAllocMgr : public BufferAllocMgr
46
47
{
 public:
ahoms's avatar
ahoms committed
48
49
	SoftBufferAllocMgr();
	virtual ~SoftBufferAllocMgr();
50

ahoms's avatar
ahoms committed
51
52
	static int getSystemMem(int& mem_unit);
	
53
54
55
	virtual int getMaxNbBuffers(const FrameDim& frame_dim);
	virtual void allocBuffers(int nb_buffers, 
				  const FrameDim& frame_dim);
ahoms's avatar
ahoms committed
56
57
	virtual const FrameDim& getFrameDim();
	virtual int getNbBuffers();
58
59
	virtual void releaseBuffers();

ahoms's avatar
ahoms committed
60
61
	virtual void *getBufferPtr(int buffer_nb);
	
62
63
64
65
66
67
68
69
70
 private:
	typedef std::vector<char *> BufferList;
	typedef BufferList::const_iterator BufferListCIt;

	FrameDim m_frame_dim;
	BufferList m_buffer_list;
};


ahoms's avatar
ahoms committed
71
72
73
74
75
76
77
/*******************************************************************
 * \class BufferCbMgr
 * \brief Abstract class with interface for buffer alloc. and callbacks
 *
 * Specifies the basic functionality for allocating frame buffers and
 * for managing the frame callbacks
 *******************************************************************/
78

ahoms's avatar
ahoms committed
79
class BufferCbMgr : public HwFrameCallbackGen
80
{
ahoms's avatar
ahoms committed
81
82
 public:
	enum Cap {
ahoms's avatar
ahoms committed
83
		Basic=0, Concat=1, Acc=2,
ahoms's avatar
ahoms committed
84
	};
85

ahoms's avatar
ahoms committed
86
87
88
89
90
91
92
93
94
95
96
97
	virtual ~BufferCbMgr();

	virtual Cap getCap() = 0;

	virtual int getMaxNbBuffers(const FrameDim& frame_dim) = 0;
	virtual void allocBuffers(int nb_buffers, 
				  const FrameDim& frame_dim) = 0;
	virtual const FrameDim& getFrameDim() = 0;
	virtual int getNbBuffers() = 0;
	virtual void releaseBuffers() = 0;

	virtual void *getBufferPtr(int buffer_nb) = 0;
98

ahoms's avatar
ahoms committed
99
100
	virtual void clearBuffer(int buffer_nb) = 0;
	virtual void clearAllBuffers() = 0;
101

ahoms's avatar
ahoms committed
102
103
104
105
106
107
108
109
110
111
112
113
114
	virtual Timestamp getBufferTimestamp(int buffer_nb) = 0;
};


/*******************************************************************
 * \class StdBufferCbMgr
 * \brief Class providing standard buffer cb functionality
 *
 * This class implements the normal buffer mode using a basic 
 * BufferAllocMgr
 *******************************************************************/

class StdBufferCbMgr : public BufferCbMgr
115
{
ahoms's avatar
ahoms committed
116
 public:
117
	StdBufferCbMgr(BufferAllocMgr& alloc_mgr);
ahoms's avatar
ahoms committed
118
	virtual ~StdBufferCbMgr();
119

ahoms's avatar
ahoms committed
120
	virtual Cap getCap();
121

ahoms's avatar
ahoms committed
122
123
124
	virtual int getMaxNbBuffers(const FrameDim& frame_dim);
	virtual void allocBuffers(int nb_buffers, 
				  const FrameDim& frame_dim);
ahoms's avatar
ahoms committed
125
126
	virtual const FrameDim& getFrameDim();
	virtual int getNbBuffers();
ahoms's avatar
ahoms committed
127
128
	virtual void releaseBuffers();

ahoms's avatar
ahoms committed
129
130
131
132
133
134
	virtual void *getBufferPtr(int buffer_nb);

	virtual void clearBuffer(int buffer_nb);
	virtual void clearAllBuffers();

	virtual Timestamp getBufferTimestamp(int buffer_nb);
135

ahoms's avatar
ahoms committed
136
137
138
139
140
141
142
143
144
	void setStartTimestamp(Timestamp start_ts);
	bool newFrameReady(int acq_frame_nr);

 protected:
	virtual void setFrameCallbackActive(bool cb_active);
	
 private:
	typedef std::vector<Timestamp> TimestampList;

145
	BufferAllocMgr& m_alloc_mgr;
ahoms's avatar
ahoms committed
146
147
148
	TimestampList m_ts_list;
	Timestamp m_start_ts;
	bool m_fcb_act;
149
150
151
};


ahoms's avatar
ahoms committed
152
153
154
155
156
157
158
159
160
161
/*******************************************************************
 * \class BufferCtrlMgr
 * \brief Class providing full buffer functionality for a given hardware
 *
 * This class implements all the buffer functionality required by the
 * hardware buffer interface. It can use different kinds of acq. buffer
 * managers and complement their missing functionality.
 *******************************************************************/

class BufferCtrlMgr
162
{
ahoms's avatar
ahoms committed
163
 public:
164
	BufferCtrlMgr(BufferCbMgr& acq_buffer_mgr);
ahoms's avatar
ahoms committed
165
166
	~BufferCtrlMgr();

ahoms's avatar
ahoms committed
167
	void setFrameDim(const FrameDim& frame_dim);
ahoms's avatar
ahoms committed
168
	void getFrameDim(      FrameDim& frame_dim);
169

ahoms's avatar
ahoms committed
170
171
	void setNbBuffers(int  nb_buffers);
	void getNbBuffers(int& nb_buffers);
172

ahoms's avatar
ahoms committed
173
174
	void setNbConcatFrames(int  nb_concat_frames);
	void getNbConcatFrames(int& nb_concat_frames);
175

ahoms's avatar
ahoms committed
176
177
178
179
180
181
182
183
184
185
186
187
188
189
	void setNbAccFrames(int  nb_acc_frames);
	void getNbAccFrames(int& nb_acc_frames);

	void getMaxNbBuffers(int& max_nb_buffers);

	void setBufferMode(BufferMode  buffer_mode);
	void getBufferMode(BufferMode& buffer_mode);

	void *getBufferPtr(int buffer_nb);
	void *getFramePtr(int acq_frame_nb);
	Timestamp getFrameTimeStamp(int acq_frame_nb);

	void   registerFrameCallback(HwFrameCallback *frame_cb);
	void unregisterFrameCallback(HwFrameCallback *frame_cb);
ahoms's avatar
ahoms committed
190
191
192
193

	BufferCbMgr& getAcqBufferMgr();

 private:
194
195
	BufferCbMgr& m_acq_buffer_mgr;
	SoftBufferAllocMgr m_aux_alloc_mgr;
ahoms's avatar
ahoms committed
196
197
198
	StdBufferCbMgr m_aux_buffer_mgr;
	BufferCbMgr *m_effect_buffer_mgr;
	FrameDim m_frame_dim;
199
200
201
};


ahoms's avatar
ahoms committed
202
203


204
205
206
} // namespace lima

#endif // HWBUFFERMGR_H