root/branches/libffado-2.0/src/libstreaming/generic/Port.h

Revision 1449, 5.1 kB (checked in by ppalmers, 13 years ago)

fix small bug in port enable. show port list when running verbose.

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     std::string getPortTypeName();
108     enum E_Direction getDirection() {return m_Direction;}; ///< returns the direction (is fixed)
109
110     /**
111      * \brief returns the size of the port buffer
112      *
113      * counted in number of E_DataType units (events), not in bytes
114      *
115      */
116     unsigned int getBufferSize() {return m_buffersize;};
117
118     /**
119      * \brief sets the size of the port buffer
120      *
121      * counted in number of E_DataType units, not in bytes
122      *
123      * if there is an external buffer assigned, it should
124      * be large enough
125      * if there is an internal buffer, it will be resized
126      *
127      * \note use before calling init()
128      */
129     virtual bool setBufferSize(unsigned int);
130
131     void setBufferAddress(void *buff);
132     void *getBufferAddress();
133
134     PortManager& getManager() { return m_manager; };
135
136     virtual void setVerboseLevel(int l);
137     virtual void show();
138
139 protected:
140     std::string m_Name; ///< Port name, [at construction]
141     bool m_disabled; ///< is the port disabled?, [anytime]
142
143     unsigned int m_buffersize;
144
145     enum E_PortType m_PortType;
146     enum E_Direction m_Direction;
147
148     void *m_buffer;
149
150     PortManager& m_manager;
151
152     DECLARE_DEBUG_MODULE;
153
154 // the state machine
155 protected:
156     enum EStates {
157         E_Created,
158         E_Initialized,
159         E_Prepared,
160         E_Running,
161         E_Error
162     };
163
164     enum EStates m_State;
165 };
166
167 /*!
168 \brief The Base Class for an Audio Port
169
170
171 */
172 class AudioPort : public Port {
173
174 public:
175
176     AudioPort(PortManager& m, std::string name, enum E_Direction direction)
177       : Port(m, name, E_Audio, direction)
178     {};
179
180     virtual ~AudioPort() {};
181 };
182
183 /*!
184 \brief The Base Class for a Midi Port
185
186
187 */
188 class MidiPort : public Port {
189
190 public:
191
192     MidiPort(PortManager& m, std::string name, enum E_Direction direction)
193       : Port(m, name, E_Midi, direction)
194     {};
195     virtual ~MidiPort() {};
196 };
197
198 /*!
199 \brief The Base Class for a control port
200
201
202 */
203 class ControlPort : public Port {
204
205 public:
206
207     ControlPort(PortManager& m, std::string name, enum E_Direction direction)
208       : Port(m, name, E_Control, direction)
209     {};
210     virtual ~ControlPort() {};
211 };
212
213 }
214
215 #endif /* __FFADO_PORT__ */
216
217
Note: See TracBrowser for help on using the browser.