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

Revision 1531, 7.2 kB (checked in by ppalmers, 15 years ago)

svn merge -r 1506:HEAD svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0

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_ISOHANDLER__
25 #define __FFADO_ISOHANDLER__
26
27 #include "debugmodule/debugmodule.h"
28
29 #include "libutil/Thread.h"
30
31 enum raw1394_iso_disposition;
32
33 class IsoHandlerManager;
34 namespace Streaming {
35     class StreamProcessor;
36 }
37
38 /*!
39 \brief The Base Class for ISO Handlers
40
41  These classes perform the actual ISO communication through libraw1394.
42  They are different from Streaming::StreamProcessors because one handler can provide multiple
43  streams with packets in case of ISO multichannel receive.
44
45 */
46
47 class IsoHandler
48 {
49 public:
50     enum EHandlerType {
51             eHT_Receive,
52             eHT_Transmit
53     };
54     IsoHandler(IsoHandlerManager& manager, enum EHandlerType t);
55     IsoHandler(IsoHandlerManager& manager, enum EHandlerType t,
56                unsigned int buf_packets, unsigned int max_packet_size, int irq);
57     IsoHandler(IsoHandlerManager& manager, enum EHandlerType t,
58                unsigned int buf_packets, unsigned int max_packet_size, int irq, enum raw1394_iso_speed speed);
59     ~IsoHandler();
60
61 private: // the ISO callback interface
62     static enum raw1394_iso_disposition
63     iso_receive_handler(raw1394handle_t handle, unsigned char *data,
64                         unsigned int length, unsigned char channel,
65                         unsigned char tag, unsigned char sy, unsigned int cycle,
66                         unsigned int dropped);
67
68     enum raw1394_iso_disposition
69             putPacket(unsigned char *data, unsigned int length,
70                         unsigned char channel, unsigned char tag, unsigned char sy,
71                         unsigned int cycle, unsigned int dropped);
72
73     static enum raw1394_iso_disposition iso_transmit_handler(raw1394handle_t handle,
74                     unsigned char *data, unsigned int *length,
75                     unsigned char *tag, unsigned char *sy,
76                     int cycle, unsigned int dropped);
77     enum raw1394_iso_disposition
78             getPacket(unsigned char *data, unsigned int *length,
79                     unsigned char *tag, unsigned char *sy,
80                     int cycle, unsigned int dropped, unsigned int skipped);
81
82 public:
83
84     /**
85      * Iterate the handler, transporting ISO packets to the client(s)
86      * @return true if success
87      */
88     bool iterate();
89
90     /**
91      * Iterate the handler, transporting ISO packets to the client(s)
92      * @param  ctr_now the CTR time at which the iterate call is done.
93      * @return true if success
94      */
95     bool iterate(uint32_t ctr_now);
96
97     int getFileDescriptor() { return raw1394_get_fd(m_handle);};
98
99     bool init();
100     void setVerboseLevel(int l);
101
102     // the enable/disable functions should only be used from within the loop that iterates()
103     // but not from within the iterate callback. use the requestEnable / requestDisable functions
104     // for that
105     bool enable() {return enable(-1);};
106     bool enable(int cycle);
107     bool disable();
108
109     // functions to request enable or disable at the next opportunity
110     bool requestEnable(int cycle = -1);
111     bool requestDisable();
112
113     /**
114      * updates the internal state if required
115      */
116     void updateState();
117
118     enum EHandlerType getType() {return m_type;};
119     const char *getTypeString() {return eHTToString(m_type); };
120
121     // pretty printing
122     const char *eHTToString(enum EHandlerType);
123
124     bool isEnabled()
125         {return m_State == eHS_Running;};
126
127     // no setter functions, because those would require a re-init
128     unsigned int getMaxPacketSize() { return m_max_packet_size;};
129     unsigned int getNbBuffers() { return m_buf_packets;};
130     int getIrqInterval() { return m_irq_interval;};
131
132     unsigned int getPreBuffers() {return m_prebuffers;};
133     void setPreBuffers(unsigned int n) {m_prebuffers=n;};
134
135     void dumpInfo();
136
137     bool inUse() {return (m_Client != 0) ;};
138     bool isStreamRegistered(Streaming::StreamProcessor *s) {return (m_Client == s);};
139
140     bool registerStream(Streaming::StreamProcessor *);
141     bool unregisterStream(Streaming::StreamProcessor *);
142
143     bool canIterateClient(); // FIXME: implement with functor
144
145     /**
146      * @brief request that the handler exits the packet processing loop ASAP
147      *
148      * The raw1394 lib doesn't provide a means to stop the packet iteration loop
149      * except when the iterate callback returns a DEFER value. Calling this function
150      * will make the callback return DEFER ASAP.
151      */
152     void requestIterateLoopExit() {m_dont_exit_iterate_loop = false;};
153     /**
154      * @brief allow the handler to stay in the packet processing loop
155      *
156      * This resets the state set by requestIterateLoopExit()
157      */
158     void allowIterateLoop() {m_dont_exit_iterate_loop = true;};
159
160
161     /**
162      * @brief get last cycle number seen by handler
163      * @return cycle number
164      */
165     int getLastCycle() {return m_last_cycle;};
166
167     /**
168      * @brief returns the CTR value saved at the last iterate() call
169      * @return CTR value saved at last iterate() call
170      */
171     uint32_t getLastIterateTime() {return m_last_now;};
172
173     /**
174      * @brief returns the CTR value saved at the last iterate handler call
175      * @return CTR value saved at last iterate handler call
176      */
177     uint32_t getLastPacketTime() {return m_last_packet_handled_at;};
178
179     /**
180      * @brief set iso receive mode. doesn't have any effect if the stream is running
181      * @param m receive mode
182      */
183     void setReceiveMode(enum raw1394_iso_dma_recv_mode m)
184         {m_receive_mode = m;}
185
186     void notifyOfDeath();
187     bool handleBusReset();
188
189 private:
190     IsoHandlerManager& m_manager;
191     enum EHandlerType m_type;
192     raw1394handle_t m_handle;
193     unsigned int    m_buf_packets;
194     unsigned int    m_max_packet_size;
195     int             m_irq_interval;
196     int             m_last_cycle;
197     uint32_t        m_last_now;
198     uint32_t        m_last_packet_handled_at;
199     enum raw1394_iso_dma_recv_mode m_receive_mode;
200
201     Streaming::StreamProcessor *m_Client; // FIXME: implement with functors
202
203     enum raw1394_iso_speed m_speed;
204     unsigned int m_prebuffers;
205     bool m_dont_exit_iterate_loop;
206
207     // the state machine
208     enum EHandlerStates {
209         eHS_Stopped,
210         eHS_Running,
211         eHS_Error,
212     };
213     enum EHandlerStates m_State;
214     enum EHandlerStates m_NextState;
215     int m_switch_on_cycle;
216
217 public:
218     unsigned int    m_packets;
219     #ifdef DEBUG
220     unsigned int    m_dropped;
221     unsigned int    m_skipped;
222     int             m_min_ahead;
223     #endif
224
225 protected:
226     DECLARE_DEBUG_MODULE;
227 };
228
229 #endif /* __FFADO_ISOHANDLER__  */
230
231
232
Note: See TracBrowser for help on using the browser.