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 |
|
---|
105 |
// the state machine |
---|
106 |
private: |
---|
107 |
enum EHandlerStates { |
---|
108 |
E_Created, |
---|
109 |
E_Prepared, |
---|
110 |
E_Running, |
---|
111 |
E_Error |
---|
112 |
}; |
---|
113 |
|
---|
114 |
enum EHandlerStates m_State; |
---|
115 |
|
---|
116 |
private: |
---|
117 |
/// iterate all child handlers |
---|
118 |
bool iterate(); |
---|
119 |
|
---|
120 |
private: |
---|
121 |
// note: there is a disctinction between streams and handlers |
---|
122 |
// because one handler can serve multiple streams (in case of |
---|
123 |
// multichannel receive) |
---|
124 |
|
---|
125 |
// only streams are allowed to be registered externally. |
---|
126 |
// we allocate a handler if we need one, otherwise the stream |
---|
127 |
// is assigned to another handler |
---|
128 |
|
---|
129 |
// the collection of handlers |
---|
130 |
IsoHandlerVector m_IsoHandlers; |
---|
131 |
|
---|
132 |
bool registerHandler(IsoHandler *); |
---|
133 |
bool unregisterHandler(IsoHandler *); |
---|
134 |
void pruneHandlers(); |
---|
135 |
|
---|
136 |
// the collection of streams |
---|
137 |
IsoStreamVector m_IsoStreams; |
---|
138 |
|
---|
139 |
// poll stuff |
---|
140 |
int m_poll_timeout; |
---|
141 |
struct pollfd *m_poll_fds; |
---|
142 |
int m_poll_nfds; |
---|
143 |
|
---|
144 |
bool rebuildFdMap(); |
---|
145 |
|
---|
146 |
// threading |
---|
147 |
bool m_realtime; |
---|
148 |
unsigned int m_priority; |
---|
149 |
Util::PosixThread *m_isoManagerThread; |
---|
150 |
|
---|
151 |
|
---|
152 |
// debug stuff |
---|
153 |
DECLARE_DEBUG_MODULE; |
---|
154 |
|
---|
155 |
}; |
---|
156 |
|
---|
157 |
} |
---|
158 |
|
---|
159 |
#endif /* __FFADO_ISOHANDLERMANAGER__ */ |
---|
160 |
|
---|
161 |
|
---|
162 |
|
---|