root/branches/streaming-rework/src/libstreaming/IsoHandler.h

Revision 383, 7.1 kB (checked in by pieterpalmers, 16 years ago)

mostly whitespace fixes

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