1 |
/* $Id$ */ |
---|
2 |
|
---|
3 |
/* |
---|
4 |
* FreeBob Streaming API |
---|
5 |
* FreeBob = Firewire (pro-)audio for linux |
---|
6 |
* |
---|
7 |
* http://freebob.sf.net |
---|
8 |
* |
---|
9 |
* Copyright (C) 2005,2006 Pieter Palmers <pieterpalmers@users.sourceforge.net> |
---|
10 |
* |
---|
11 |
* This program is free software {} you can redistribute it and/or modify |
---|
12 |
* it under the terms of the GNU General Public License as published by |
---|
13 |
* the Free Software Foundation {} either version 2 of the License, or |
---|
14 |
* (at your option) any later version. |
---|
15 |
* |
---|
16 |
* This program is distributed in the hope that it will be useful, |
---|
17 |
* but WITHOUT ANY WARRANTY {} without even the implied warranty of |
---|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 |
* GNU General Public License for more details. |
---|
20 |
* |
---|
21 |
* You should have received a copy of the GNU General Public License |
---|
22 |
* along with this program {} if not, write to the Free Software |
---|
23 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
24 |
* |
---|
25 |
* |
---|
26 |
* |
---|
27 |
*/ |
---|
28 |
#ifndef __FREEBOB_PORT__ |
---|
29 |
#define __FREEBOB_PORT__ |
---|
30 |
|
---|
31 |
#include "../debugmodule/debugmodule.h" |
---|
32 |
#include <string> |
---|
33 |
|
---|
34 |
namespace FreebobStreaming { |
---|
35 |
|
---|
36 |
/*! |
---|
37 |
\brief The Base Class for Ports |
---|
38 |
|
---|
39 |
Ports are the entities that provide the interface between the ISO streaming |
---|
40 |
layer and the datatype-specific layer. You can define plug types by subclassing |
---|
41 |
the base port type. |
---|
42 |
*/ |
---|
43 |
class Port { |
---|
44 |
|
---|
45 |
public: |
---|
46 |
friend class PortManager; |
---|
47 |
|
---|
48 |
/*! |
---|
49 |
\brief Specifies the buffering type for ports |
---|
50 |
*/ |
---|
51 |
enum E_BufferType { |
---|
52 |
E_PacketBuffered, ///< the port is to be processed for every packet |
---|
53 |
E_PeriodBuffered, ///< the port is to be processed after a period of frames |
---|
54 |
// E_SampleBuffered ///< the port is to be processed after each frame (sample) |
---|
55 |
}; |
---|
56 |
|
---|
57 |
/*! |
---|
58 |
\brief The datatype of the port buffer |
---|
59 |
*/ |
---|
60 |
enum E_DataType { |
---|
61 |
E_Float, |
---|
62 |
E_Int24, |
---|
63 |
E_Byte, |
---|
64 |
E_Default, |
---|
65 |
}; |
---|
66 |
|
---|
67 |
/*! |
---|
68 |
\brief The port type |
---|
69 |
*/ |
---|
70 |
enum E_PortType { |
---|
71 |
E_Audio, |
---|
72 |
E_Midi, |
---|
73 |
E_Control, |
---|
74 |
}; |
---|
75 |
|
---|
76 |
/*! |
---|
77 |
\brief The port direction |
---|
78 |
*/ |
---|
79 |
enum E_Direction { |
---|
80 |
E_Playback, |
---|
81 |
E_Capture, |
---|
82 |
}; |
---|
83 |
|
---|
84 |
Port(std::string name, enum E_BufferType type, unsigned int buffsize, |
---|
85 |
enum E_DataType datatype, enum E_PortType porttype, enum E_Direction direction); |
---|
86 |
|
---|
87 |
Port(std::string name, enum E_BufferType type, unsigned int buffsize, |
---|
88 |
enum E_DataType datatype, void *externalbuffer, enum E_PortType porttype, enum E_Direction direction); |
---|
89 |
|
---|
90 |
virtual ~Port() |
---|
91 |
{}; |
---|
92 |
|
---|
93 |
std::string getName() {return m_Name;}; |
---|
94 |
void setName(std::string name) {m_Name=name;}; |
---|
95 |
|
---|
96 |
void enable() {m_enabled=true;}; |
---|
97 |
void disable() {m_enabled=false;}; |
---|
98 |
bool isEnabled() {return m_enabled;}; |
---|
99 |
|
---|
100 |
enum E_BufferType getBufferType() {return m_BufferType;}; |
---|
101 |
|
---|
102 |
|
---|
103 |
enum E_DataType getDataType() {return m_datatype;}; |
---|
104 |
bool setDataType(enum E_DataType datatype); |
---|
105 |
|
---|
106 |
enum E_PortType getPortType() {return m_porttype;}; |
---|
107 |
enum E_Direction getDirection() {return m_direction;}; |
---|
108 |
|
---|
109 |
// NOT THREAD SAFE! |
---|
110 |
// attaches a user buffer to the port. |
---|
111 |
// deallocates the internal buffer, if there was one |
---|
112 |
// buffersize is in 'events' |
---|
113 |
|
---|
114 |
// int attachBuffer(void *buff); |
---|
115 |
|
---|
116 |
// detach the user buffer, allocates an internal buffer |
---|
117 |
// int detachBuffer(); |
---|
118 |
|
---|
119 |
/** |
---|
120 |
* \brief returns the size of the events in the port buffer, in bytes |
---|
121 |
* |
---|
122 |
*/ |
---|
123 |
unsigned int getEventSize(); |
---|
124 |
|
---|
125 |
/** |
---|
126 |
* \brief returns the size of the port buffer |
---|
127 |
* |
---|
128 |
* counted in number of E_DataType units (events), not in bytes |
---|
129 |
* |
---|
130 |
*/ |
---|
131 |
unsigned int getBufferSize() {return m_buffersize;}; |
---|
132 |
|
---|
133 |
/** |
---|
134 |
* \brief sets the size of the port buffer |
---|
135 |
* |
---|
136 |
* counted in number of E_DataType units, not in bytes |
---|
137 |
* |
---|
138 |
* if there is an external buffer assigned, it should |
---|
139 |
* be large enough |
---|
140 |
* if there is an internal buffer, it will be resized |
---|
141 |
* |
---|
142 |
*/ |
---|
143 |
bool setBufferSize(unsigned int); |
---|
144 |
|
---|
145 |
// FIXME: this is not really OO, but for performance??? |
---|
146 |
void *getBufferAddress() {return m_buffer;}; |
---|
147 |
void setBufferAddress(void *buff) {m_buffer=buff;}; |
---|
148 |
|
---|
149 |
virtual void setVerboseLevel(int l); |
---|
150 |
|
---|
151 |
protected: |
---|
152 |
std::string m_Name; ///< Port name, [at construction] |
---|
153 |
|
---|
154 |
enum E_BufferType m_BufferType; ///< Buffer type, [at construction] |
---|
155 |
|
---|
156 |
bool m_enabled; ///< is the port enabled?, [anytime] |
---|
157 |
|
---|
158 |
/** |
---|
159 |
* \brief size of the buffer |
---|
160 |
* |
---|
161 |
* counted in number of E_DataType units, not in bytes |
---|
162 |
* |
---|
163 |
* [] |
---|
164 |
*/ |
---|
165 |
unsigned int m_buffersize; |
---|
166 |
|
---|
167 |
enum E_DataType m_datatype; ///< size of the buffer, number of E_DataType units [] |
---|
168 |
enum E_PortType m_porttype; |
---|
169 |
enum E_Direction m_direction; |
---|
170 |
|
---|
171 |
void *m_buffer; |
---|
172 |
bool m_buffer_attached; |
---|
173 |
|
---|
174 |
bool allocateInternalBuffer(); |
---|
175 |
void freeInternalBuffer(); |
---|
176 |
|
---|
177 |
// call this when the event size is changed |
---|
178 |
virtual bool eventSizeChanged(); ///< this is called whenever the event size changes. |
---|
179 |
|
---|
180 |
DECLARE_DEBUG_MODULE; |
---|
181 |
|
---|
182 |
}; |
---|
183 |
|
---|
184 |
/*! |
---|
185 |
\brief The Base Class for an Audio Port |
---|
186 |
|
---|
187 |
|
---|
188 |
*/ |
---|
189 |
class AudioPort : public Port { |
---|
190 |
|
---|
191 |
public: |
---|
192 |
|
---|
193 |
AudioPort(std::string name, unsigned int buffsize, enum E_Direction direction) |
---|
194 |
: Port(name, E_PeriodBuffered, buffsize, E_Int24, E_Audio, direction) |
---|
195 |
{}; |
---|
196 |
|
---|
197 |
AudioPort(std::string name, enum E_BufferType type, unsigned int buffsize, |
---|
198 |
enum E_Direction direction) |
---|
199 |
: Port(name, type, buffsize, E_Int24, E_Audio, direction) |
---|
200 |
{}; |
---|
201 |
AudioPort(std::string name, enum E_BufferType type, unsigned int buffsize, |
---|
202 |
void *externalbuffer, enum E_Direction direction) |
---|
203 |
: Port(name, type, buffsize, E_Int24, externalbuffer, E_Audio, direction) |
---|
204 |
{}; |
---|
205 |
|
---|
206 |
AudioPort(std::string name, enum E_DataType datatype, |
---|
207 |
enum E_BufferType type, unsigned int buffsize, enum E_Direction direction) |
---|
208 |
: Port(name, type, buffsize, datatype, E_Audio, direction) |
---|
209 |
{}; |
---|
210 |
AudioPort(std::string name, enum E_DataType datatype, |
---|
211 |
enum E_BufferType type, unsigned int buffsize, void *externalbuffer, |
---|
212 |
enum E_Direction direction) |
---|
213 |
: Port(name, type, buffsize, datatype, externalbuffer, E_Audio, direction) |
---|
214 |
{}; |
---|
215 |
|
---|
216 |
virtual ~AudioPort() {}; |
---|
217 |
|
---|
218 |
protected: |
---|
219 |
enum E_DataType m_DataType; |
---|
220 |
|
---|
221 |
|
---|
222 |
}; |
---|
223 |
|
---|
224 |
/*! |
---|
225 |
\brief The Base Class for a Midi Port |
---|
226 |
|
---|
227 |
|
---|
228 |
*/ |
---|
229 |
class MidiPort : public Port { |
---|
230 |
|
---|
231 |
public: |
---|
232 |
|
---|
233 |
MidiPort(std::string name, unsigned int buffsize, enum E_Direction direction) |
---|
234 |
: Port(name, E_PacketBuffered, buffsize, E_Byte, E_Midi, direction) |
---|
235 |
{}; |
---|
236 |
virtual ~MidiPort() {}; |
---|
237 |
|
---|
238 |
|
---|
239 |
protected: |
---|
240 |
enum E_DataType m_DataType; |
---|
241 |
|
---|
242 |
|
---|
243 |
}; |
---|
244 |
|
---|
245 |
/*! |
---|
246 |
\brief The Base Class for a control port |
---|
247 |
|
---|
248 |
|
---|
249 |
*/ |
---|
250 |
class ControlPort : public Port { |
---|
251 |
|
---|
252 |
public: |
---|
253 |
|
---|
254 |
ControlPort(std::string name, unsigned int buffsize, enum E_Direction direction) |
---|
255 |
: Port(name, E_PeriodBuffered, buffsize, E_Int24, E_Control, direction) |
---|
256 |
{}; |
---|
257 |
virtual ~ControlPort() {}; |
---|
258 |
|
---|
259 |
|
---|
260 |
protected: |
---|
261 |
|
---|
262 |
|
---|
263 |
}; |
---|
264 |
|
---|
265 |
} |
---|
266 |
|
---|
267 |
#endif /* __FREEBOB_PORT__ */ |
---|
268 |
|
---|
269 |
|
---|