1 |
/* $Id$ */ |
---|
2 |
|
---|
3 |
/* |
---|
4 |
* FreeBob streaming API |
---|
5 |
* FreeBob = Firewire (pro-)audio for linux |
---|
6 |
* |
---|
7 |
* http://freebob.sf.net |
---|
8 |
* |
---|
9 |
* Copyright (C) 2006 Pieter Palmers <pieterpalmers@users.sourceforge.net> |
---|
10 |
* |
---|
11 |
* This program is free software {} you can redistribute it and/or modify |
---|
12 |
* it under the terms of the GNU General Public License as published by |
---|
13 |
* the Free Software Foundation {} either version 2 of the License, or |
---|
14 |
* (at your option) any later version. |
---|
15 |
* |
---|
16 |
* This program is distributed in the hope that it will be useful, |
---|
17 |
* but WITHOUT ANY WARRANTY {} without even the implied warranty of |
---|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 |
* GNU General Public License for more details. |
---|
20 |
* |
---|
21 |
* You should have received a copy of the GNU General Public License |
---|
22 |
* along with this program {} if not, write to the Free Software |
---|
23 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
24 |
* |
---|
25 |
* |
---|
26 |
* |
---|
27 |
*/ |
---|
28 |
#ifndef __FREEBOB_ISOHANDLERMANAGER__ |
---|
29 |
#define __FREEBOB_ISOHANDLERMANAGER__ |
---|
30 |
|
---|
31 |
#include "../debugmodule/debugmodule.h" |
---|
32 |
#include "../libutil/Thread.h" |
---|
33 |
|
---|
34 |
#include <sys/poll.h> |
---|
35 |
#include <errno.h> |
---|
36 |
|
---|
37 |
#include <vector> |
---|
38 |
|
---|
39 |
#define USLEEP_AFTER_UPDATE_FAILURE 10 |
---|
40 |
#define USLEEP_AFTER_UPDATE 100 |
---|
41 |
#define MAX_UPDATE_TRIES 10 |
---|
42 |
namespace FreebobUtil { |
---|
43 |
class PosixThread; |
---|
44 |
} |
---|
45 |
|
---|
46 |
namespace FreebobStreaming |
---|
47 |
{ |
---|
48 |
|
---|
49 |
class IsoHandler; |
---|
50 |
class IsoStream; |
---|
51 |
|
---|
52 |
typedef std::vector<IsoHandler *> IsoHandlerVector; |
---|
53 |
typedef std::vector<IsoHandler *>::iterator IsoHandlerVectorIterator; |
---|
54 |
|
---|
55 |
typedef std::vector<IsoStream *> IsoStreamVector; |
---|
56 |
typedef std::vector<IsoStream *>::iterator IsoStreamVectorIterator; |
---|
57 |
|
---|
58 |
|
---|
59 |
/*! |
---|
60 |
\brief The ISO Handler management class |
---|
61 |
|
---|
62 |
This class manages the use of ISO handlers by ISO streams. |
---|
63 |
You can register an IsoStream with an IsoHandlerManager. This |
---|
64 |
manager will assign an IsoHandler to the stream. If nescessary |
---|
65 |
the manager allocates a new handler. If there is already a handler |
---|
66 |
that can handle the IsoStream (e.g. in case of multichannel receive), |
---|
67 |
it can be assigned. |
---|
68 |
|
---|
69 |
*/ |
---|
70 |
|
---|
71 |
class IsoHandlerManager : public FreebobUtil::RunnableInterface |
---|
72 |
{ |
---|
73 |
friend class StreamProcessorManager; |
---|
74 |
|
---|
75 |
public: |
---|
76 |
|
---|
77 |
IsoHandlerManager(); |
---|
78 |
IsoHandlerManager(bool run_rt, unsigned int rt_prio); |
---|
79 |
virtual ~IsoHandlerManager(); |
---|
80 |
|
---|
81 |
void setPollTimeout(int t) {m_poll_timeout=t;}; ///< set the timeout used for poll() |
---|
82 |
int getPollTimeout() {return m_poll_timeout;}; ///< get the timeout used for poll() |
---|
83 |
|
---|
84 |
void setVerboseLevel(int l); ///< set the verbose level |
---|
85 |
|
---|
86 |
void dumpInfo(); ///< print some information about the manager to stdout/stderr |
---|
87 |
|
---|
88 |
bool registerStream(IsoStream *); ///< register an iso stream with the manager |
---|
89 |
bool unregisterStream(IsoStream *); ///< unregister an iso stream from the manager |
---|
90 |
|
---|
91 |
bool startHandlers(); ///< start the managed ISO handlers |
---|
92 |
bool startHandlers(int cycle); ///< start the managed ISO handlers |
---|
93 |
bool stopHandlers(); ///< stop the managed ISO handlers |
---|
94 |
|
---|
95 |
bool reset(); ///< reset the ISO manager and all streams |
---|
96 |
|
---|
97 |
bool prepare(); ///< prepare the ISO manager and all streams |
---|
98 |
|
---|
99 |
bool init(); |
---|
100 |
|
---|
101 |
void disablePolling(IsoStream *); ///< disables polling on a stream |
---|
102 |
void enablePolling(IsoStream *); ///< enables polling on a stream |
---|
103 |
|
---|
104 |
// RunnableInterface interface |
---|
105 |
public: |
---|
106 |
bool Execute(); // note that this is called in we while(running) loop |
---|
107 |
bool Init(); |
---|
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 |
public: // FIXME: just so that SPM can do this (temp solution) |
---|
124 |
/// updates the cycle timer caches of all child handlers |
---|
125 |
void updateCycleTimers(); |
---|
126 |
private: |
---|
127 |
// note: there is a disctinction between streams and handlers |
---|
128 |
// because one handler can serve multiple streams (in case of |
---|
129 |
// multichannel receive) |
---|
130 |
|
---|
131 |
// only streams are allowed to be registered externally. |
---|
132 |
// we allocate a handler if we need one, otherwise the stream |
---|
133 |
// is assigned to another handler |
---|
134 |
|
---|
135 |
// the collection of handlers |
---|
136 |
IsoHandlerVector m_IsoHandlers; |
---|
137 |
|
---|
138 |
bool registerHandler(IsoHandler *); |
---|
139 |
bool unregisterHandler(IsoHandler *); |
---|
140 |
void pruneHandlers(); |
---|
141 |
|
---|
142 |
// the collection of streams |
---|
143 |
IsoStreamVector m_IsoStreams; |
---|
144 |
|
---|
145 |
// poll stuff |
---|
146 |
int m_poll_timeout; |
---|
147 |
struct pollfd *m_poll_fds; |
---|
148 |
int m_poll_nfds; |
---|
149 |
|
---|
150 |
bool rebuildFdMap(); |
---|
151 |
|
---|
152 |
// threading |
---|
153 |
bool m_realtime; |
---|
154 |
unsigned int m_priority; |
---|
155 |
FreebobUtil::PosixThread *m_isoManagerThread; |
---|
156 |
|
---|
157 |
|
---|
158 |
// debug stuff |
---|
159 |
DECLARE_DEBUG_MODULE; |
---|
160 |
|
---|
161 |
}; |
---|
162 |
|
---|
163 |
} |
---|
164 |
|
---|
165 |
#endif /* __FREEBOB_ISOHANDLERMANAGER__ */ |
---|
166 |
|
---|
167 |
|
---|
168 |
|
---|