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

Revision 753, 5.0 kB (checked in by ppalmers, 13 years ago)

have separate threads for every handler

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