root/branches/ppalmers-streaming/src/libstreaming/IsoHandlerManager.h

Revision 703, 4.6 kB (checked in by ppalmers, 15 years ago)

- rework of streaming startup
- started moving files around to enhance structure

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 library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
22  */
23
24 #ifndef __FFADO_ISOHANDLERMANAGER__
25 #define __FFADO_ISOHANDLERMANAGER__
26
27 #include "../debugmodule/debugmodule.h"
28 #include "../libutil/Thread.h"
29
30 #include <sys/poll.h>
31 #include <errno.h>
32
33 #include <vector>
34
35 #define USLEEP_AFTER_UPDATE_FAILURE 10
36 #define USLEEP_AFTER_UPDATE 100
37 #define MAX_UPDATE_TRIES 10
38 namespace Util {
39     class PosixThread;
40 }
41
42 namespace Streaming
43 {
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 setVerboseLevel(int l); ///< set the verbose level
81
82         void dumpInfo(); ///< print some information about the manager to stdout/stderr
83
84         bool registerStream(IsoStream *); ///< register an iso stream with the manager
85         bool unregisterStream(IsoStream *); ///< unregister an iso stream from the manager
86
87         bool startHandlers(); ///< start the managed ISO handlers
88         bool startHandlers(int cycle); ///< start the managed ISO handlers
89         bool stopHandlers(); ///< stop the managed ISO handlers
90
91         bool reset(); ///< reset the ISO manager and all streams
92
93         bool prepare(); ///< prepare the ISO manager and all streams
94
95         bool init();
96
97         void disablePolling(IsoStream *); ///< disables polling on a stream
98         void enablePolling(IsoStream *); ///< enables polling on a stream
99
100     // RunnableInterface interface
101     public:
102         bool Execute(); // note that this is called in we while(running) loop
103         bool Init();
104         pthread_mutex_t m_debug_lock;
105
106     // the state machine
107     private:
108         enum EHandlerStates {
109             E_Created,
110             E_Prepared,
111             E_Running,
112             E_Error
113         };
114
115         enum EHandlerStates m_State;
116
117     private:
118         /// iterate all child handlers
119         bool iterate();
120
121     private:
122         // note: there is a disctinction between streams and handlers
123         // because one handler can serve multiple streams (in case of
124         // multichannel receive)
125
126         // only streams are allowed to be registered externally.
127         // we allocate a handler if we need one, otherwise the stream
128         // is assigned to another handler
129
130         // the collection of handlers
131         IsoHandlerVector m_IsoHandlers;
132
133         bool registerHandler(IsoHandler *);
134         bool unregisterHandler(IsoHandler *);
135         void pruneHandlers();
136
137         // the collection of streams
138         IsoStreamVector m_IsoStreams;
139
140         // poll stuff
141         int m_poll_timeout;
142         struct pollfd *m_poll_fds;
143         int m_poll_nfds;
144
145         bool rebuildFdMap();
146
147         // threading
148         bool m_realtime;
149         unsigned int m_priority;
150         Util::PosixThread *m_isoManagerThread;
151
152         // debug stuff
153         DECLARE_DEBUG_MODULE;
154
155 };
156
157 }
158
159 #endif /* __FFADO_ISOHANDLERMANAGER__  */
160
161
162
Note: See TracBrowser for help on using the browser.