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 |
|
---|
43 |
namespace FreebobStreaming |
---|
44 |
{ |
---|
45 |
|
---|
46 |
class IsoHandler; |
---|
47 |
class IsoStream; |
---|
48 |
|
---|
49 |
typedef std::vector<IsoHandler *> IsoHandlerVector; |
---|
50 |
typedef std::vector<IsoHandler *>::iterator IsoHandlerVectorIterator; |
---|
51 |
|
---|
52 |
typedef std::vector<IsoStream *> IsoStreamVector; |
---|
53 |
typedef std::vector<IsoStream *>::iterator IsoStreamVectorIterator; |
---|
54 |
|
---|
55 |
|
---|
56 |
/*! |
---|
57 |
\brief The ISO Handler management class |
---|
58 |
|
---|
59 |
This class manages the use of ISO handlers by ISO streams. |
---|
60 |
You can register an IsoStream with an IsoHandlerManager. This |
---|
61 |
manager will assign an IsoHandler to the stream. If nescessary |
---|
62 |
the manager allocates a new handler. If there is already a handler |
---|
63 |
that can handle the IsoStream (e.g. in case of multichannel receive), |
---|
64 |
it can be assigned. |
---|
65 |
|
---|
66 |
*/ |
---|
67 |
|
---|
68 |
class IsoHandlerManager : public FreebobUtil::RunnableInterface |
---|
69 |
{ |
---|
70 |
friend class StreamProcessorManager; |
---|
71 |
|
---|
72 |
public: |
---|
73 |
|
---|
74 |
IsoHandlerManager(); |
---|
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 |
void disablePolling(IsoStream *); ///< disables polling on a stream |
---|
96 |
void enablePolling(IsoStream *); ///< enables polling on a stream |
---|
97 |
|
---|
98 |
// RunnableInterface interface |
---|
99 |
public: |
---|
100 |
bool Execute(); // note that this is called in we while(running) loop |
---|
101 |
bool Init(); |
---|
102 |
|
---|
103 |
// the state machine |
---|
104 |
private: |
---|
105 |
enum EHandlerStates { |
---|
106 |
E_Created, |
---|
107 |
E_Prepared, |
---|
108 |
E_Running, |
---|
109 |
E_Error |
---|
110 |
}; |
---|
111 |
|
---|
112 |
enum EHandlerStates m_State; |
---|
113 |
|
---|
114 |
private: |
---|
115 |
/// iterate all child handlers |
---|
116 |
bool iterate(); |
---|
117 |
public: // FIXME: just so that SPM can do this (temp solution) |
---|
118 |
/// updates the cycle timer caches of all child handlers |
---|
119 |
void updateCycleTimers(); |
---|
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 |
// debug stuff |
---|
147 |
DECLARE_DEBUG_MODULE; |
---|
148 |
|
---|
149 |
}; |
---|
150 |
|
---|
151 |
} |
---|
152 |
|
---|
153 |
#endif /* __FREEBOB_ISOHANDLERMANAGER__ */ |
---|
154 |
|
---|
155 |
|
---|
156 |
|
---|