root/trunk/libffado/src/libieee1394/IsoHandlerManager.h

Revision 864, 5.3 kB (checked in by ppalmers, 13 years ago)

update license to GPLv2 or GPLv3 instead of GPLv2 or any later version. Update copyrights to reflect the new year

Line 
1 /*
2  * Copyright (C) 2005-2008 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 program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #ifndef __FFADO_ISOHANDLERMANAGER__
25 #define __FFADO_ISOHANDLERMANAGER__
26
27 #include "config.h"
28
29 #include "debugmodule/debugmodule.h"
30
31 #include "libutil/Thread.h"
32
33 #include <sys/poll.h>
34 #include <errno.h>
35
36 #include <vector>
37
38 class Ieee1394Service;
39
40 class IsoHandler;
41 namespace Streaming {
42     class StreamProcessor;
43     class StreamProcessorManager;
44     typedef std::vector<StreamProcessor *> StreamProcessorVector;
45     typedef std::vector<StreamProcessor *>::iterator StreamProcessorVectorIterator;
46 }
47
48 typedef std::vector<IsoHandler *> IsoHandlerVector;
49 typedef std::vector<IsoHandler *>::iterator IsoHandlerVectorIterator;
50
51 /*!
52 \brief The ISO Handler management class
53
54  This class manages the use of ISO handlers by ISO streams.
55  You can register an Streaming::StreamProcessor with an IsoHandlerManager. This
56  manager will assign an IsoHandler to the stream. If nescessary
57  the manager allocates a new handler. If there is already a handler
58  that can handle the Streaming::StreamProcessor (e.g. in case of multichannel receive),
59  it can be assigned.
60
61 */
62 class IsoHandlerManager : public Util::RunnableInterface
63 {
64     friend class Streaming::StreamProcessorManager;
65     public:
66         bool Init();
67         bool Execute();
68         void updateShadowVars();
69     private:
70         // shadow variables
71         struct pollfd m_poll_fds_shadow[ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT];
72         IsoHandler *m_IsoHandler_map_shadow[ISOHANDLERMANAGER_MAX_ISO_HANDLERS_PER_PORT];
73         unsigned int m_poll_nfds_shadow;
74
75     public:
76
77         IsoHandlerManager(Ieee1394Service& service);
78         IsoHandlerManager(Ieee1394Service& service, bool run_rt, int rt_prio);
79         virtual ~IsoHandlerManager();
80
81         bool setThreadParameters(bool rt, int priority);
82
83         void setVerboseLevel(int l); ///< set the verbose level
84
85         void dumpInfo(); ///< print some information about the manager to stdout/stderr
86
87         bool registerStream(Streaming::StreamProcessor *); ///< register an iso stream with the manager
88         bool unregisterStream(Streaming::StreamProcessor *); ///< unregister an iso stream from the manager
89
90         bool startHandlers(); ///< start the managed ISO handlers
91         bool startHandlers(int cycle); ///< start the managed ISO handlers
92         bool stopHandlers(); ///< stop the managed ISO handlers
93
94         bool reset(); ///< reset the ISO manager and all streams
95         bool init();
96
97         bool disable(IsoHandler *); ///< disables a handler
98         bool enable(IsoHandler *); ///< enables a handler
99         ///> disables the handler attached to the stream
100         bool stopHandlerForStream(Streaming::StreamProcessor *);
101         ///> starts the handler attached to the specific stream
102         bool startHandlerForStream(Streaming::StreamProcessor *);
103         ///> starts the handler attached to the specific stream on a specific cycle
104         bool startHandlerForStream(Streaming::StreamProcessor *, int cycle);
105
106         /**
107          * returns the latency of a wake-up for this stream.
108          * The latency is the time it takes for a packet is delivered to the
109          * stream after it has been received (was on the wire).
110          * expressed in cycles
111          */
112         int getPacketLatencyForStream(Streaming::StreamProcessor *);
113
114         void flushHandlerForStream(Streaming::StreamProcessor *stream);
115
116         Ieee1394Service& get1394Service() {return m_service;};
117
118     // the state machine
119     private:
120         enum eHandlerStates {
121             E_Created,
122             E_Prepared,
123             E_Running,
124             E_Error
125         };
126
127         enum eHandlerStates m_State;
128         const char *eHSToString(enum eHandlerStates);
129
130     private:
131         Ieee1394Service&  m_service;
132         // note: there is a disctinction between streams and handlers
133         // because one handler can serve multiple streams (in case of
134         // multichannel receive)
135
136         // only streams are allowed to be registered externally.
137         // we allocate a handler if we need one, otherwise the stream
138         // is assigned to another handler
139
140         // the collection of handlers
141         IsoHandlerVector m_IsoHandlers;
142
143         bool registerHandler(IsoHandler *);
144         bool unregisterHandler(IsoHandler *);
145         void pruneHandlers();
146
147         // the collection of streams
148         Streaming::StreamProcessorVector m_StreamProcessors;
149
150         // thread params for the handler threads
151         bool m_realtime;
152         int m_priority;
153         Util::Thread *  m_Thread;
154
155         // debug stuff
156         DECLARE_DEBUG_MODULE;
157
158 };
159
160 #endif /* __FFADO_ISOHANDLERMANAGER__  */
161
162
163
Note: See TracBrowser for help on using the browser.