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

Revision 341, 6.0 kB (checked in by pieterpalmers, 17 years ago)

- changed bebob avdevice to use debugmodule instead of printf/cout
- fixed some minor merge side-effects
- implement a RT safe mechanism to obtain the cycle counter.

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                 // get the most recent cycle counter value
114                 // RT safe
115                 unsigned int getCycleCounter();
116                
117                 // update the cycle counter cache
118                 // not RT safe
119                 // the isohandlermanager is responsible for calling this!
120         void updateCycleCounter();
121
122         protected:
123             raw1394handle_t m_handle;
124         raw1394handle_t m_handle_util;
125                 int             m_port;
126                 unsigned int    m_buf_packets;
127                 unsigned int    m_max_packet_size;
128                 int             m_irq_interval;
129                 unsigned int    m_cyclecounter;
130
131                 int m_packetcount;
132                 int m_dropped;
133
134                 IsoStream *m_Client;
135
136                 virtual int handleBusReset(unsigned int generation) = 0;
137
138                 DECLARE_DEBUG_MODULE;
139
140         private:
141                 static int busreset_handler(raw1394handle_t handle, unsigned int generation);
142
143
144 };
145
146 /*!
147 \brief ISO receive handler class (not multichannel)
148 */
149
150 class IsoRecvHandler : public IsoHandler
151 {
152
153         public:
154                 IsoRecvHandler(int port);
155                 IsoRecvHandler(int port, unsigned int buf_packets, unsigned int max_packet_size, int irq);
156                 virtual ~IsoRecvHandler();
157
158                 bool init();
159        
160                 enum EHandlerType getType() { return EHT_Receive;};
161
162 //              int registerStream(IsoStream *);
163 //              int unregisterStream(IsoStream *);
164
165                 bool start(int cycle);
166
167                 bool prepare();
168
169         private:
170                 int handleBusReset(unsigned int generation);
171
172                 static enum raw1394_iso_disposition
173                 iso_receive_handler(raw1394handle_t handle, unsigned char *data,
174                                                 unsigned int length, unsigned char channel,
175                                                 unsigned char tag, unsigned char sy, unsigned int cycle,
176                                                 unsigned int dropped);
177
178                 enum raw1394_iso_disposition 
179                         putPacket(unsigned char *data, unsigned int length,
180                               unsigned char channel, unsigned char tag, unsigned char sy,
181                                   unsigned int cycle, unsigned int dropped);
182
183 };
184
185 /*!
186 \brief ISO transmit handler class
187 */
188
189 class IsoXmitHandler  : public IsoHandler
190 {
191         public:
192                 IsoXmitHandler(int port);
193                 IsoXmitHandler(int port, unsigned int buf_packets,
194                                unsigned int max_packet_size, int irq);
195                 IsoXmitHandler(int port, unsigned int buf_packets,
196                                unsigned int max_packet_size, int irq,
197                                enum raw1394_iso_speed speed);
198                 virtual ~IsoXmitHandler();
199
200                 bool init();
201                
202                 enum EHandlerType getType() { return EHT_Transmit;};
203
204 //              int registerStream(IsoStream *);
205 //              int unregisterStream(IsoStream *);
206
207                 unsigned int getPreBuffers() {return m_prebuffers;};
208                 void setPreBuffers(unsigned int n) {m_prebuffers=n;};
209
210                 bool start(int cycle);
211
212                 bool prepare();
213
214         private:
215
216                 int handleBusReset(unsigned int generation);
217
218                 static enum raw1394_iso_disposition iso_transmit_handler(raw1394handle_t handle,
219                                 unsigned char *data, unsigned int *length,
220                                 unsigned char *tag, unsigned char *sy,
221                                 int cycle, unsigned int dropped);
222                 enum raw1394_iso_disposition 
223                         getPacket(unsigned char *data, unsigned int *length,
224                               unsigned char *tag, unsigned char *sy,
225                               int cycle, unsigned int dropped);
226
227                 enum raw1394_iso_speed m_speed;
228                
229                 unsigned int m_prebuffers;
230
231 };
232
233 }
234
235 #endif /* __FREEBOB_ISOHANDLER__  */
236
237
238
Note: See TracBrowser for help on using the browser.