root/trunk/libffado/src/libieee1394/IsoHandlerManager.h

Revision 1336, 7.5 kB (checked in by ppalmers, 16 years ago)

Bring trunk up to date with branches/libffado-2.0:

"""
svn merge -r 1254:1299 svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0
svn merge -r 1301:1320 svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0
svn merge -r 1322:1323 svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0
svn merge -r 1329:HEAD svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0
"""

Add getSupportedSamplingFrequencies() to DICE, RME and Metric Halo AvDevices?

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_ISOHANDLERMANAGER__
25 #define __FFADO_ISOHANDLERMANAGER__
26
27 #include "config.h"
28
29 #include "debugmodule/debugmodule.h"
30
31 #include "libutil/Thread.h"
32
33 #include "IsoHandler.h"
34
35 #include <sys/poll.h>
36 #include <errno.h>
37 #include <vector>
38 #include <semaphore.h>
39
40 class Ieee1394Service;
41 //class IsoHandler;
42 //enum IsoHandler::EHandlerType;
43
44 namespace Streaming {
45     class StreamProcessor;
46     typedef std::vector<StreamProcessor *> StreamProcessorVector;
47     typedef std::vector<StreamProcessor *>::iterator StreamProcessorVectorIterator;
48 }
49
50 typedef std::vector<IsoHandler *> IsoHandlerVector;
51 typedef std::vector<IsoHandler *>::iterator IsoHandlerVectorIterator;
52
53 class IsoHandlerManager;
54
55 // threads that will handle the packet framing
56 // one thread per direction, as a compromise for one per
57 // channel and one for all
58 class IsoTask : public Util::RunnableInterface
59 {
60     public:
61         IsoTask(IsoHandlerManager& manager, enum IsoHandler::EHandlerType);
62         virtual ~IsoTask();
63
64     public:
65         bool Init();
66         bool Execute();
67
68         /**
69          * @brief requests the thread to sync it's stream map with the manager
70          */
71         bool requestShadowMapUpdate();
72         enum eActivityResult {
73             eAR_Activity,
74             eAR_Timeout,
75             eAR_Interrupted,
76             eAR_Error
77         };
78
79         /**
80          * @brief signals that something happened in one of the clients of this task
81          */
82         void signalActivity();
83         /**
84          * @brief wait until something happened in one of the clients of this task
85          */
86         enum eActivityResult waitForActivity();
87
88         /**
89          * @brief This should be called when a busreset has happened.
90          */
91         bool handleBusReset();
92
93         void setVerboseLevel(int i);
94     protected:
95         IsoHandlerManager& m_manager;
96
97         // the event request structure
98         int32_t request_update;
99
100         // static allocation due to RT constraints
101         // this is the map used by the actual thread
102         // it is a shadow of the m_StreamProcessors vector
103         struct pollfd   m_poll_fds_shadow[ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT];
104         IsoHandler *    m_IsoHandler_map_shadow[ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT];
105         unsigned int    m_poll_nfds_shadow;
106         IsoHandler *    m_SyncIsoHandler;
107
108         // updates the streams map
109         void updateShadowMapHelper();
110
111 #ifdef DEBUG
112         uint64_t m_last_loop_entry;
113         int m_successive_short_loops;
114 #endif
115
116         // activity signaling
117         sem_t m_activity_semaphore;
118
119         enum IsoHandler::EHandlerType m_handlerType;
120         bool m_running;
121         bool m_in_busreset;
122
123         // debug stuff
124         DECLARE_DEBUG_MODULE;
125 };
126
127 /*!
128 \brief The ISO Handler management class
129
130  This class manages the use of ISO handlers by ISO streams.
131  You can register an Streaming::StreamProcessor with an IsoHandlerManager. This
132  manager will assign an IsoHandler to the stream. If nescessary
133  the manager allocates a new handler. If there is already a handler
134  that can handle the Streaming::StreamProcessor (e.g. in case of multichannel receive),
135  it can be assigned.
136
137 */
138
139 class IsoHandlerManager
140 {
141     friend class IsoTask;
142
143     public:
144
145         IsoHandlerManager(Ieee1394Service& service);
146         IsoHandlerManager(Ieee1394Service& service, bool run_rt, int rt_prio);
147         virtual ~IsoHandlerManager();
148
149         bool setThreadParameters(bool rt, int priority);
150
151         void setVerboseLevel(int l); ///< set the verbose level
152
153         void dumpInfo(); ///< print some information about the manager to stdout/stderr
154
155         bool registerStream(Streaming::StreamProcessor *); ///< register an iso stream with the manager
156         bool unregisterStream(Streaming::StreamProcessor *); ///< unregister an iso stream from the manager
157
158         bool startHandlers(); ///< start the managed ISO handlers
159         bool startHandlers(int cycle); ///< start the managed ISO handlers
160         bool stopHandlers(); ///< stop the managed ISO handlers
161
162         bool reset(); ///< reset the ISO manager and all streams
163         bool init();
164
165         bool disable(IsoHandler *); ///< disables a handler
166         bool enable(IsoHandler *); ///< enables a handler
167
168         /**
169          * @brief signals that something happened in one of the clients
170          */
171         void signalActivityTransmit();
172         void signalActivityReceive();
173
174         ///> disables the handler attached to the stream
175         bool stopHandlerForStream(Streaming::StreamProcessor *);
176         ///> starts the handler attached to the specific stream
177         bool startHandlerForStream(Streaming::StreamProcessor *);
178         ///> starts the handler attached to the specific stream on a specific cycle
179         bool startHandlerForStream(Streaming::StreamProcessor *, int cycle);
180
181         /**
182          * returns the latency of a wake-up for this stream.
183          * The latency is the time it takes for a packet is delivered to the
184          * stream after it has been received (was on the wire).
185          * expressed in cycles
186          */
187         int getPacketLatencyForStream(Streaming::StreamProcessor *);
188
189         void flushHandlerForStream(Streaming::StreamProcessor *stream);
190         IsoHandler * getHandlerForStream(Streaming::StreamProcessor *stream);
191
192         Ieee1394Service& get1394Service() {return m_service;};
193
194         void requestShadowMapUpdate();
195
196         /**
197          * This should be called when a busreset has happened.
198          */
199         bool handleBusReset();
200     // the state machine
201     private:
202         enum eHandlerStates {
203             E_Created,
204             E_Prepared,
205             E_Running,
206             E_Error
207         };
208
209         enum eHandlerStates m_State;
210         const char *eHSToString(enum eHandlerStates);
211
212     private:
213         Ieee1394Service&  m_service;
214         // note: there is a disctinction between streams and handlers
215         // because one handler can serve multiple streams (in case of
216         // multichannel receive)
217
218         // only streams are allowed to be registered externally.
219         // we allocate a handler if we need one, otherwise the stream
220         // is assigned to another handler
221
222         // the collection of handlers
223         IsoHandlerVector m_IsoHandlers;
224
225         bool registerHandler(IsoHandler *);
226         bool unregisterHandler(IsoHandler *);
227         void pruneHandlers();
228
229         // the collection of streams
230         Streaming::StreamProcessorVector m_StreamProcessors;
231
232         // handler thread/task
233         bool            m_realtime;
234         int             m_priority;
235         Util::Thread *  m_IsoThreadTransmit;
236         IsoTask *       m_IsoTaskTransmit;
237         Util::Thread *  m_IsoThreadReceive;
238         IsoTask *       m_IsoTaskReceive;
239
240         // debug stuff
241         DECLARE_DEBUG_MODULE;
242
243 };
244
245 #endif /* __FFADO_ISOHANDLERMANAGER__  */
246
247
248
Note: See TracBrowser for help on using the browser.