root/branches/ppalmers-streaming/src/libstreaming/util/IsoHandler.h

Revision 705, 6.1 kB (checked in by ppalmers, 13 years ago)

restructure the streaming directory

Line 
1 /*
2  * Copyright (C) 2005-2007 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 library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
22  */
23
24 #ifndef __FFADO_ISOHANDLER__
25 #define __FFADO_ISOHANDLER__
26
27 #include "debugmodule/debugmodule.h"
28
29 #include <libraw1394/raw1394.h>
30
31
32 enum raw1394_iso_disposition ;
33 namespace Streaming
34 {
35
36 class IsoStream;
37 /*!
38 \brief The Base Class for ISO Handlers
39
40  These classes perform the actual ISO communication through libraw1394.
41  They are different from IsoStreams because one handler can provide multiple
42  streams with packets in case of ISO multichannel receive.
43
44 */
45
46 class IsoHandler
47 {
48     protected:
49
50     public:
51
52         enum EHandlerType {
53                 EHT_Receive,
54                 EHT_Transmit
55         };
56
57         IsoHandler(int port);
58
59         IsoHandler(int port, unsigned int buf_packets, unsigned int max_packet_size, int irq);
60
61         virtual ~IsoHandler();
62
63         virtual bool init();
64         virtual bool prepare();
65         virtual bool start(int cycle);
66         virtual bool stop();
67
68         bool iterate();
69
70         void setVerboseLevel(int l);
71
72         // no setter functions, because those would require a re-init
73         unsigned int getMaxPacketSize() { return m_max_packet_size;};
74         unsigned int getNbBuffers() { return m_buf_packets;};
75         int getWakeupInterval() { return m_irq_interval;};
76
77         int getPacketCount() {return m_packetcount;};
78         void resetPacketCount() {m_packetcount=0;};
79
80         int getDroppedCount() {return m_dropped;};
81         void resetDroppedCount() {m_dropped=0;};
82
83         virtual enum EHandlerType getType() = 0;
84
85         int getFileDescriptor() { return raw1394_get_fd(m_handle);};
86
87         void dumpInfo();
88
89         bool inUse() {return (m_Client != 0) ;};
90         virtual bool isStreamRegistered(IsoStream *s) {return (m_Client == s);};
91
92         virtual bool registerStream(IsoStream *);
93         virtual bool unregisterStream(IsoStream *);
94
95         int getLocalNodeId() {return raw1394_get_local_id( m_handle );};
96         int getPort() {return m_port;};
97
98         /// get the most recent cycle timer value (in ticks)
99         unsigned int getCycleTimerTicks();
100         /// get the most recent cycle timer value (as is)
101         unsigned int getCycleTimer();
102
103     protected:
104         raw1394handle_t m_handle;
105         raw1394handle_t m_handle_util;
106         int             m_port;
107         unsigned int    m_buf_packets;
108         unsigned int    m_max_packet_size;
109         int             m_irq_interval;
110
111         int m_packetcount;
112         int m_dropped;
113
114         IsoStream *m_Client;
115
116         virtual int handleBusReset(unsigned int generation);
117
118
119         DECLARE_DEBUG_MODULE;
120
121     private:
122         static int busreset_handler(raw1394handle_t handle, unsigned int generation);
123
124     // the state machine
125     private:
126         enum EHandlerStates {
127             E_Created,
128             E_Initialized,
129             E_Prepared,
130             E_Running,
131             E_Error
132         };
133
134         enum EHandlerStates m_State;
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         bool start(int cycle);
155
156         bool prepare();
157
158     protected:
159         int handleBusReset(unsigned int generation);
160
161     private:
162         static enum raw1394_iso_disposition
163         iso_receive_handler(raw1394handle_t handle, unsigned char *data,
164                             unsigned int length, unsigned char channel,
165                             unsigned char tag, unsigned char sy, unsigned int cycle,
166                             unsigned int dropped);
167
168         enum raw1394_iso_disposition
169                 putPacket(unsigned char *data, unsigned int length,
170                           unsigned char channel, unsigned char tag, unsigned char sy,
171                           unsigned int cycle, unsigned int dropped);
172
173 };
174
175 /*!
176 \brief ISO transmit handler class
177 */
178
179 class IsoXmitHandler  : public IsoHandler
180 {
181     public:
182         IsoXmitHandler(int port);
183         IsoXmitHandler(int port, unsigned int buf_packets,
184                         unsigned int max_packet_size, int irq);
185         IsoXmitHandler(int port, unsigned int buf_packets,
186                         unsigned int max_packet_size, int irq,
187                         enum raw1394_iso_speed speed);
188         virtual ~IsoXmitHandler();
189
190         bool init();
191
192         enum EHandlerType getType() { return EHT_Transmit;};
193
194         unsigned int getPreBuffers() {return m_prebuffers;};
195         void setPreBuffers(unsigned int n) {m_prebuffers=n;};
196
197         bool start(int cycle);
198
199         bool prepare();
200
201     protected:
202         int handleBusReset(unsigned int generation);
203
204     private:
205         static enum raw1394_iso_disposition iso_transmit_handler(raw1394handle_t handle,
206                         unsigned char *data, unsigned int *length,
207                         unsigned char *tag, unsigned char *sy,
208                         int cycle, unsigned int dropped);
209         enum raw1394_iso_disposition
210                 getPacket(unsigned char *data, unsigned int *length,
211                         unsigned char *tag, unsigned char *sy,
212                         int cycle, unsigned int dropped);
213
214         enum raw1394_iso_speed m_speed;
215
216         unsigned int m_prebuffers;
217
218 };
219
220 }
221
222 #endif /* __FFADO_ISOHANDLER__  */
223
224
225
Note: See TracBrowser for help on using the browser.