root/trunk/libffado/src/libstreaming/util/IsoHandlerManager.h

Revision 742, 4.8 kB (checked in by ppalmers, 13 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

Line 
1 /*
2  * Copyright (C) 2005-2007 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 3 of the License, or
12  * (at your option) any later version.
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 "debugmodule/debugmodule.h"
28
29 #include "libutil/Thread.h"
30
31 #include <sys/poll.h>
32 #include <errno.h>
33
34 #include <vector>
35
36 #define USLEEP_AFTER_UPDATE_FAILURE 10
37 #define USLEEP_AFTER_UPDATE 100
38 #define MAX_UPDATE_TRIES 10
39 namespace Util {
40     class PosixThread;
41 }
42
43 namespace Streaming
44 {
45 class IsoHandler;
46 class IsoStream;
47
48 typedef std::vector<IsoHandler *> IsoHandlerVector;
49 typedef std::vector<IsoHandler *>::iterator IsoHandlerVectorIterator;
50
51 typedef std::vector<IsoStream *> IsoStreamVector;
52 typedef std::vector<IsoStream *>::iterator IsoStreamVectorIterator;
53
54
55 /*!
56 \brief The ISO Handler management class
57
58  This class manages the use of ISO handlers by ISO streams.
59  You can register an IsoStream with an IsoHandlerManager. This
60  manager will assign an IsoHandler to the stream. If nescessary
61  the manager allocates a new handler. If there is already a handler
62  that can handle the IsoStream (e.g. in case of multichannel receive),
63  it can be assigned.
64
65 */
66
67 class IsoHandlerManager : public Util::RunnableInterface
68 {
69     friend class StreamProcessorManager;
70
71     public:
72
73         IsoHandlerManager();
74         IsoHandlerManager(bool run_rt, unsigned int rt_prio);
75         virtual ~IsoHandlerManager() {};
76
77         void setPollTimeout(int t) {m_poll_timeout=t;}; ///< set the timeout used for poll()
78         int getPollTimeout() {return m_poll_timeout;};  ///< get the timeout used for poll()
79
80         void setTransmitBufferNbFrames(unsigned int t) {m_xmit_nb_frames = t;};
81         int getTransmitBufferNbFrames() {return m_xmit_nb_frames;};
82
83         void setVerboseLevel(int l); ///< set the verbose level
84
85         void dumpInfo(); ///< print some information about the manager to stdout/stderr
86
87         bool registerStream(IsoStream *); ///< register an iso stream with the manager
88         bool unregisterStream(IsoStream *); ///< unregister an iso stream from the manager
89
90         bool startHandlers(); ///< start the managed ISO handlers
91         bool startHandlers(int cycle); ///< start the managed ISO handlers
92         bool stopHandlers(); ///< stop the managed ISO handlers
93
94         bool reset(); ///< reset the ISO manager and all streams
95
96         bool prepare(); ///< prepare the ISO manager and all streams
97
98         bool init();
99
100         void disablePolling(IsoStream *); ///< disables polling on a stream
101         void enablePolling(IsoStream *); ///< enables polling on a stream
102
103     // RunnableInterface interface
104     public:
105         bool Execute(); // note that this is called in we while(running) loop
106         bool Init();
107         pthread_mutex_t m_debug_lock;
108
109     // the state machine
110     private:
111         enum EHandlerStates {
112             E_Created,
113             E_Prepared,
114             E_Running,
115             E_Error
116         };
117
118         enum EHandlerStates m_State;
119
120     private:
121         /// iterate all child handlers
122         bool iterate();
123
124     private:
125         // note: there is a disctinction between streams and handlers
126         // because one handler can serve multiple streams (in case of
127         // multichannel receive)
128
129         // only streams are allowed to be registered externally.
130         // we allocate a handler if we need one, otherwise the stream
131         // is assigned to another handler
132
133         // the collection of handlers
134         IsoHandlerVector m_IsoHandlers;
135
136         bool registerHandler(IsoHandler *);
137         bool unregisterHandler(IsoHandler *);
138         void pruneHandlers();
139
140         // the collection of streams
141         IsoStreamVector m_IsoStreams;
142
143         // poll stuff
144         int m_poll_timeout;
145         struct pollfd *m_poll_fds;
146         int m_poll_nfds;
147
148         bool rebuildFdMap();
149
150         // threading
151         bool m_realtime;
152         unsigned int m_priority;
153         Util::PosixThread *m_isoManagerThread;
154
155         // the preferred number of packets to buffer on xmit
156         unsigned int m_xmit_nb_frames;
157
158         // debug stuff
159         DECLARE_DEBUG_MODULE;
160
161 };
162
163 }
164
165 #endif /* __FFADO_ISOHANDLERMANAGER__  */
166
167
168
Note: See TracBrowser for help on using the browser.