root/trunk/libffado/src/libstreaming/generic/Port.h

Revision 864, 5.0 kB (checked in by ppalmers, 14 years ago)

update license to GPLv2 or GPLv3 instead of GPLv2 or any later version. Update copyrights to reflect the new year

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #ifndef __FFADO_PORT__
25 #define __FFADO_PORT__
26
27 #include "libutil/ringbuffer.h"
28
29 #include "debugmodule/debugmodule.h"
30
31 #include <string>
32 #include <stdint.h>
33
34 namespace Streaming {
35 class PortManager;
36
37 /*!
38 \brief The Base Class for Ports
39
40  Ports are the entities that provide the interface between the ISO streaming
41  layer and the datatype-specific layer. You can define port types by subclassing
42  the base port class.
43
44  After creating a port, you have to set its parameters and then call the init() function.
45  This is because a port needs information from two sources to operate:
46  1) the stream composition information from the AvDevice
47  2) the streaming API setup (buffer type, data type, ...)
48
49  \note There are not much virtual functions here because of the high frequency of
50        calling. We try to do everything with a base class getter, and a child class
51        setter. If this isn't possible, we do a static_cast. This however can only be
52        done inside the streamprocessor that handles the specific sub-class types of
53        the ports. i.e. by design you should make sure that the static_cast will be
54        OK.
55
56 */
57 class Port {
58
59 public:
60     /*!
61     \brief The port type
62     */
63     enum E_PortType {
64         E_Audio,
65         E_Midi,
66         E_Control,
67     };
68
69     /*!
70     \brief The port direction
71     */
72     enum E_Direction {
73         E_Playback,
74         E_Capture,
75     };
76
77     Port(PortManager&, std::string name, enum E_PortType, enum E_Direction);
78
79     virtual ~Port();
80
81
82     /// Enable the port. (this can be called anytime)
83     void enable();
84     /// Disable the port. (this can be called anytime)
85     void disable();
86     /// is the port disabled? (this can be called anytime)
87     bool isDisabled() {return m_disabled;};
88
89     /*!
90     \brief Initialize the port
91     */
92     bool init();
93
94     bool prepare() {return true;};
95     bool reset();
96
97     std::string getName() {return m_Name;};
98     bool setName(std::string name);
99
100     /**
101      * \brief returns the size of the events in the port buffer, in bytes
102      *
103      */
104     unsigned int getEventSize();
105
106     enum E_PortType getPortType() {return m_PortType;}; ///< returns the port type (is fixed)
107     enum E_Direction getDirection() {return m_Direction;}; ///< returns the direction (is fixed)
108
109     /**
110      * \brief returns the size of the port buffer
111      *
112      * counted in number of E_DataType units (events), not in bytes
113      *
114      */
115     unsigned int getBufferSize() {return m_buffersize;};
116
117     /**
118      * \brief sets the size of the port buffer
119      *
120      * counted in number of E_DataType units, not in bytes
121      *
122      * if there is an external buffer assigned, it should
123      * be large enough
124      * if there is an internal buffer, it will be resized
125      *
126      * \note use before calling init()
127      */
128     virtual bool setBufferSize(unsigned int);
129
130     void setBufferAddress(void *buff);
131     void *getBufferAddress();
132
133     PortManager& getManager() { return m_manager; };
134
135     virtual void setVerboseLevel(int l);
136     virtual void show();
137
138 protected:
139     std::string m_Name; ///< Port name, [at construction]
140     bool m_disabled; ///< is the port disabled?, [anytime]
141
142     unsigned int m_buffersize;
143
144     enum E_PortType m_PortType;
145     enum E_Direction m_Direction;
146
147     void *m_buffer;
148
149     PortManager& m_manager;
150
151     DECLARE_DEBUG_MODULE;
152
153 // the state machine
154 protected:
155     enum EStates {
156         E_Created,
157         E_Initialized,
158         E_Prepared,
159         E_Running,
160         E_Error
161     };
162
163     enum EStates m_State;
164 };
165
166 /*!
167 \brief The Base Class for an Audio Port
168
169
170 */
171 class AudioPort : public Port {
172
173 public:
174
175     AudioPort(PortManager& m, std::string name, enum E_Direction direction)
176       : Port(m, name, E_Audio, direction)
177     {};
178
179     virtual ~AudioPort() {};
180 };
181
182 /*!
183 \brief The Base Class for a Midi Port
184
185
186 */
187 class MidiPort : public Port {
188
189 public:
190
191     MidiPort(PortManager& m, std::string name, enum E_Direction direction)
192       : Port(m, name, E_Midi, direction)
193     {};
194     virtual ~MidiPort() {};
195 };
196
197 /*!
198 \brief The Base Class for a control port
199
200
201 */
202 class ControlPort : public Port {
203
204 public:
205
206     ControlPort(PortManager& m, std::string name, enum E_Direction direction)
207       : Port(m, name, E_Control, direction)
208     {};
209     virtual ~ControlPort() {};
210 };
211
212 }
213
214 #endif /* __FFADO_PORT__ */
215
216
Note: See TracBrowser for help on using the browser.