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

Revision 398, 6.3 kB (checked in by pieterpalmers, 16 years ago)

remove cycle timer prediction & DLL code from the IsoHandler?, as it is replaced by a raw1394 API call

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