root/branches/libfreebob-2.0/src/libstreaming/IsoHandlerManager.h

Revision 230, 3.6 kB (checked in by pieterpalmers, 18 years ago)

- xrun handling now works

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 "FreebobThread.h"
33
34 #include <sys/poll.h>
35 #include <errno.h>
36
37 #include <vector>
38
39 namespace FreebobStreaming
40 {
41
42 class IsoHandler;
43 class IsoStream;
44
45 typedef std::vector<IsoHandler *> IsoHandlerVector;
46 typedef std::vector<IsoHandler *>::iterator IsoHandlerVectorIterator;
47
48 typedef std::vector<IsoStream *> IsoStreamVector;
49 typedef std::vector<IsoStream *>::iterator IsoStreamVectorIterator;
50
51
52 /*!
53 \brief The ISO Handler management class
54
55  This class manages the use of ISO handlers by ISO streams.
56  You can register an IsoStream with an IsoHandlerManager. This
57  manager will assign an IsoHandler to the stream. If nescessary
58  the manager allocates a new handler. If there is already a handler
59  that can handle the IsoStream (e.g. in case of multichannel receive),
60  it can be assigned.
61
62 */
63
64 class IsoHandlerManager : public FreebobRunnableInterface
65 {
66         friend class StreamProcessorManager;
67
68     public:
69
70         IsoHandlerManager();
71         virtual ~IsoHandlerManager();
72
73                 void setPollTimeout(int t) {m_poll_timeout=t;}; ///< set the timeout used for poll()
74                 int getPollTimeout() {return m_poll_timeout;};  ///< get the timeout used for poll()
75
76                 void setVerboseLevel(int l); ///< set the verbose level
77
78                 void dumpInfo(); ///< print some information about the manager to stdout/stderr
79
80                 bool registerStream(IsoStream *); ///< register an iso stream with the manager
81                 bool unregisterStream(IsoStream *); ///< unregister an iso stream from the manager
82
83                 bool startHandlers(); ///< start the managed ISO handlers
84                 bool startHandlers(int cycle); ///< start the managed ISO handlers
85                 bool stopHandlers(); ///< stop the managed ISO handlers
86
87                 bool reset() {return true;}; ///< reset the ISO manager and all streams
88
89                 bool prepare(); ///< prepare the ISO manager and all streams
90
91         protected:
92                 // FreebobRunnableInterface interface
93                 bool Execute(); // note that this is called in we while(running) loop
94                 bool Init();
95
96
97                 // note: there is a disctinction between streams and handlers
98                 // because one handler can serve multiple streams (in case of
99                 // multichannel receive)
100
101                 // only streams are allowed to be registered externally.
102                 // we allocate a handler if we need one, otherwise the stream
103                 // is assigned to another handler
104
105                 // the collection of handlers
106                 IsoHandlerVector m_IsoHandlers;
107
108                 bool registerHandler(IsoHandler *);
109                 bool unregisterHandler(IsoHandler *);
110                 void pruneHandlers();
111
112                 // the collection of streams
113                 IsoStreamVector m_IsoStreams;
114
115                 // poll stuff
116                 int m_poll_timeout;
117                 struct pollfd *m_poll_fds;
118                 int m_poll_nfds;
119
120                 bool rebuildFdMap();
121
122
123             DECLARE_DEBUG_MODULE;
124
125 };
126
127 }
128
129 #endif /* __FREEBOB_ISOHANDLERMANAGER__  */
130
131
132
Note: See TracBrowser for help on using the browser.