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

Revision 759, 5.4 kB (checked in by ppalmers, 16 years ago)

fix streaming problem

Line 
1 /*
2  * Copyright (C) 2005-2007 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 3 of the License, or
12  * (at your option) any later version.
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 "debugmodule/debugmodule.h"
28
29 #include "libutil/Thread.h"
30
31 #include <sys/poll.h>
32 #include <errno.h>
33
34 #include <vector>
35
36 #define THREAD_PER_ISOHANDLER
37
38 #define FFADO_MAX_ISO_HANDLERS_PER_PORT 16
39
40 #define USLEEP_AFTER_UPDATE_FAILURE 10
41 #define USLEEP_AFTER_UPDATE 100
42 #define MAX_UPDATE_TRIES 10
43 class Ieee1394Service;
44
45 class IsoHandler;
46 namespace Streaming {
47     class StreamProcessor;
48     class StreamProcessorManager;
49     typedef std::vector<StreamProcessor *> StreamProcessorVector;
50     typedef std::vector<StreamProcessor *>::iterator StreamProcessorVectorIterator;
51 }
52
53 typedef std::vector<IsoHandler *> IsoHandlerVector;
54 typedef std::vector<IsoHandler *>::iterator IsoHandlerVectorIterator;
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 Streaming::StreamProcessor 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 Streaming::StreamProcessor (e.g. in case of multichannel receive),
64  it can be assigned.
65
66 */
67 class IsoHandlerManager : public Util::RunnableInterface
68 {
69     friend class Streaming::StreamProcessorManager;
70     public:
71         bool Init();
72         bool Execute();
73         void updateShadowVars();
74     private:
75         // shadow variables
76         struct pollfd m_poll_fds_shadow[FFADO_MAX_ISO_HANDLERS_PER_PORT];
77         IsoHandler *m_IsoHandler_map_shadow[FFADO_MAX_ISO_HANDLERS_PER_PORT];
78         unsigned int m_poll_nfds_shadow;
79
80     public:
81
82         IsoHandlerManager(Ieee1394Service& service);
83         IsoHandlerManager(Ieee1394Service& service, bool run_rt, int rt_prio);
84         virtual ~IsoHandlerManager();
85
86         bool setThreadParameters(bool rt, int priority);
87
88         void setVerboseLevel(int l); ///< set the verbose level
89
90         void dumpInfo(); ///< print some information about the manager to stdout/stderr
91
92         bool registerStream(Streaming::StreamProcessor *); ///< register an iso stream with the manager
93         bool unregisterStream(Streaming::StreamProcessor *); ///< unregister an iso stream from the manager
94
95         bool startHandlers(); ///< start the managed ISO handlers
96         bool startHandlers(int cycle); ///< start the managed ISO handlers
97         bool stopHandlers(); ///< stop the managed ISO handlers
98
99         bool reset(); ///< reset the ISO manager and all streams
100         bool init();
101
102         bool disable(IsoHandler *); ///< disables a handler
103         bool enable(IsoHandler *); ///< enables a handler
104         ///> disables the handler attached to the stream
105         bool stopHandlerForStream(Streaming::StreamProcessor *);
106         ///> starts the handler attached to the specific stream
107         bool startHandlerForStream(Streaming::StreamProcessor *);
108         ///> starts the handler attached to the specific stream on a specific cycle
109         bool startHandlerForStream(Streaming::StreamProcessor *, int cycle);
110
111         /**
112          * returns the latency of a wake-up for this stream.
113          * The latency is the time it takes for a packet is delivered to the
114          * stream after it has been received (was on the wire).
115          * expressed in cycles
116          */
117         int getPacketLatencyForStream(Streaming::StreamProcessor *);
118
119         void flushHandlerForStream(Streaming::StreamProcessor *stream);
120
121         Ieee1394Service& get1394Service() {return m_service;};
122
123     // the state machine
124     private:
125         enum eHandlerStates {
126             E_Created,
127             E_Prepared,
128             E_Running,
129             E_Error
130         };
131
132         enum eHandlerStates m_State;
133         const char *eHSToString(enum eHandlerStates);
134
135     private:
136         Ieee1394Service&  m_service;
137         // note: there is a disctinction between streams and handlers
138         // because one handler can serve multiple streams (in case of
139         // multichannel receive)
140
141         // only streams are allowed to be registered externally.
142         // we allocate a handler if we need one, otherwise the stream
143         // is assigned to another handler
144
145         // the collection of handlers
146         IsoHandlerVector m_IsoHandlers;
147
148         bool registerHandler(IsoHandler *);
149         bool unregisterHandler(IsoHandler *);
150         void pruneHandlers();
151
152         // the collection of streams
153         Streaming::StreamProcessorVector m_StreamProcessors;
154
155         // thread params for the handler threads
156         bool m_realtime;
157         int m_priority;
158         Util::Thread *  m_Thread;
159
160         // debug stuff
161         DECLARE_DEBUG_MODULE;
162
163 };
164
165 #endif /* __FFADO_ISOHANDLERMANAGER__  */
166
167
168
Note: See TracBrowser for help on using the browser.