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

Revision 309, 5.8 kB (checked in by jwoithe, 16 years ago)

MOTU: Fixed false "missed rx cycle" report following xrun recovery.
Ensure iso rx/tx contexts are deallocated during shutdown/xrun recovery by explicitly deleting IsoHandlers? in IsoHandlerManager::pruneHandlers(). If they aren't deleted here they never get deleted because the reference is lost.
IsoHandler? destructor should only call stop() if the handle is valid.
IsoXmitHandler?'s destructor sets the handle NULL to prevent double-free by the inherited IsoHandler? destructor.
Don't call raw1394_iso_shutdown() from our code. libraw1394 1.2.1 has a bug whereby raw1394_new_handle() fails to initialise the iso_packet_infos field. The bug hits us particularly in IsoRecvHandler::prepare(). It's also not really necessary to call raw1394_iso_shutdown() since raw1394_destroy_handle() will do any cleanups we happen to need.
MOTU: the receive stream no longer falsely complains of buffer problems during device shutdown.
MOTU: fixed a false "missed cycle" detection immediately after the stream was enabled.

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_ISOHANDLER__
29 #define __FREEBOB_ISOHANDLER__
30
31 #include "../debugmodule/debugmodule.h"
32
33 #include <libraw1394/raw1394.h>
34
35
36 enum raw1394_iso_disposition ;
37 namespace FreebobStreaming
38 {
39
40 class IsoStream;
41
42 /*!
43 \brief The Base Class for ISO Handlers
44
45  These classes perform the actual ISO communication through libraw1394.
46  They are different from IsoStreams because one handler can provide multiple
47  streams with packets in case of ISO multichannel receive.
48
49 */
50
51 class IsoHandler
52 {
53         protected:
54        
55         public:
56        
57                 enum EHandlerType {
58                         EHT_Receive,
59                         EHT_Transmit
60                 };
61        
62                 IsoHandler(int port)
63                    : m_handle(0), m_handle_util(0), m_port(port),
64                    m_buf_packets(400), m_max_packet_size(1024), m_irq_interval(-1),
65                    m_packetcount(0), m_dropped(0), m_Client(0)
66                 {}
67
68                 IsoHandler(int port, unsigned int buf_packets, unsigned int max_packet_size, int irq)
69                    : m_handle(0), m_port(port),
70                    m_buf_packets(buf_packets), m_max_packet_size( max_packet_size),
71                    m_irq_interval(irq), m_packetcount(0), m_dropped(0), m_Client(0)
72                 {}
73
74                 virtual ~IsoHandler();
75
76                 virtual bool init();
77                
78                 int iterate() { if(m_handle) return raw1394_loop_iterate(m_handle); else return -1; };
79                
80                 void setVerboseLevel(int l);
81
82                 // no setter functions, because those would require a re-init
83                 unsigned int getMaxPacketSize() { return m_max_packet_size;};
84                 unsigned int getBuffersize() { return m_buf_packets;};
85                 int getWakeupInterval() { return m_irq_interval;};
86
87                 int getPacketCount() {return m_packetcount;};
88                 void resetPacketCount() {m_packetcount=0;};
89
90                 int getDroppedCount() {return m_dropped;};
91                 void resetDroppedCount() {m_dropped=0;};
92
93                 virtual enum EHandlerType getType() = 0;
94
95                 virtual bool start(int cycle) = 0;
96                 virtual bool stop();
97                
98                 int getFileDescriptor() { return raw1394_get_fd(m_handle);};
99
100                 void dumpInfo();
101
102                 bool inUse() {return (m_Client != 0) ;};
103                 virtual bool isStreamRegistered(IsoStream *s) {return (m_Client == s);};
104
105                 virtual bool registerStream(IsoStream *);
106                 virtual bool unregisterStream(IsoStream *);
107
108                 int getLocalNodeId() {return raw1394_get_local_id( m_handle );};
109                 int getPort() {return m_port;};
110
111                 virtual bool prepare() = 0;
112                
113                 unsigned int getCycleCounter();
114
115         protected:
116             raw1394handle_t m_handle;
117         raw1394handle_t m_handle_util;
118                 int             m_port;
119                 unsigned int    m_buf_packets;
120                 unsigned int    m_max_packet_size;
121                 int             m_irq_interval;
122
123                 int m_packetcount;
124                 int m_dropped;
125
126                 IsoStream *m_Client;
127
128                 virtual int handleBusReset(unsigned int generation) = 0;
129
130                 DECLARE_DEBUG_MODULE;
131
132         private:
133                 static int busreset_handler(raw1394handle_t handle, unsigned int generation);
134
135
136 };
137
138 /*!
139 \brief ISO receive handler class (not multichannel)
140 */
141
142 class IsoRecvHandler : public IsoHandler
143 {
144
145         public:
146                 IsoRecvHandler(int port);
147                 IsoRecvHandler(int port, unsigned int buf_packets, unsigned int max_packet_size, int irq);
148                 virtual ~IsoRecvHandler();
149
150                 bool init();
151        
152                 enum EHandlerType getType() { return EHT_Receive;};
153
154 //              int registerStream(IsoStream *);
155 //              int unregisterStream(IsoStream *);
156
157                 bool start(int cycle);
158
159                 bool prepare();
160
161         private:
162                 int handleBusReset(unsigned int generation);
163
164                 static enum raw1394_iso_disposition
165                 iso_receive_handler(raw1394handle_t handle, unsigned char *data,
166                                                 unsigned int length, unsigned char channel,
167                                                 unsigned char tag, unsigned char sy, unsigned int cycle,
168                                                 unsigned int dropped);
169
170                 enum raw1394_iso_disposition 
171                         putPacket(unsigned char *data, unsigned int length,
172                               unsigned char channel, unsigned char tag, unsigned char sy,
173                                   unsigned int cycle, unsigned int dropped);
174
175 };
176
177 /*!
178 \brief ISO transmit handler class
179 */
180
181 class IsoXmitHandler  : public IsoHandler
182 {
183         public:
184                 IsoXmitHandler(int port);
185                 IsoXmitHandler(int port, unsigned int buf_packets,
186                                unsigned int max_packet_size, int irq);
187                 IsoXmitHandler(int port, unsigned int buf_packets,
188                                unsigned int max_packet_size, int irq,
189                                enum raw1394_iso_speed speed);
190                 virtual ~IsoXmitHandler();
191
192                 bool init();
193                
194                 enum EHandlerType getType() { return EHT_Transmit;};
195
196 //              int registerStream(IsoStream *);
197 //              int unregisterStream(IsoStream *);
198
199                 unsigned int getPreBuffers() {return m_prebuffers;};
200                 void setPreBuffers(unsigned int n) {m_prebuffers=n;};
201
202                 bool start(int cycle);
203
204                 bool prepare();
205
206         private:
207
208                 int handleBusReset(unsigned int generation);
209
210                 static enum raw1394_iso_disposition iso_transmit_handler(raw1394handle_t handle,
211                                 unsigned char *data, unsigned int *length,
212                                 unsigned char *tag, unsigned char *sy,
213                                 int cycle, unsigned int dropped);
214                 enum raw1394_iso_disposition 
215                         getPacket(unsigned char *data, unsigned int *length,
216                               unsigned char *tag, unsigned char *sy,
217                               int cycle, unsigned int dropped);
218
219                 enum raw1394_iso_speed m_speed;
220                
221                 unsigned int m_prebuffers;
222
223 };
224
225 }
226
227 #endif /* __FREEBOB_ISOHANDLER__  */
228
229
230
Note: See TracBrowser for help on using the browser.