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

Revision 398, 4.7 kB (checked in by pieterpalmers, 17 years ago)

remove cycle timer prediction & DLL code from the IsoHandler?, as it is replaced by a raw1394 API call

Line 
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
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         FreebobUtil::PosixThread *m_isoManagerThread;
154        
155        
156         // debug stuff
157         DECLARE_DEBUG_MODULE;
158
159 };
160
161 }
162
163 #endif /* __FREEBOB_ISOHANDLERMANAGER__  */
164
165
166
Note: See TracBrowser for help on using the browser.