root/trunk/libffado/src/libstreaming/util/IsoHandler.h

Revision 748, 5.9 kB (checked in by ppalmers, 14 years ago)

try to reorganize things such that less information is duplicated

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 program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
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 StreamProcessor;
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 StreamProcessors 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(StreamProcessor *s) {return (m_Client == s);};
91
92         virtual bool registerStream(StreamProcessor *);
93         virtual bool unregisterStream(StreamProcessor *);
94
95         int getLocalNodeId() {return raw1394_get_local_id( m_handle );};
96         int getPort() {return m_port;};
97
98     protected:
99         raw1394handle_t m_handle;
100         raw1394handle_t m_handle_util;
101         int             m_port;
102         unsigned int    m_buf_packets;
103         unsigned int    m_max_packet_size;
104         int             m_irq_interval;
105
106         int m_packetcount;
107         int m_dropped;
108
109         StreamProcessor *m_Client;
110
111         virtual int handleBusReset(unsigned int generation);
112
113
114         DECLARE_DEBUG_MODULE;
115
116     private:
117         static int busreset_handler(raw1394handle_t handle, unsigned int generation);
118
119     // the state machine
120     private:
121         enum EHandlerStates {
122             E_Created,
123             E_Initialized,
124             E_Prepared,
125             E_Running,
126             E_Error
127         };
128
129         enum EHandlerStates m_State;
130
131 };
132
133 /*!
134 \brief ISO receive handler class (not multichannel)
135 */
136
137 class IsoRecvHandler : public IsoHandler
138 {
139
140     public:
141         IsoRecvHandler(int port);
142         IsoRecvHandler(int port, unsigned int buf_packets, unsigned int max_packet_size, int irq);
143         virtual ~IsoRecvHandler();
144
145         bool init();
146
147         enum EHandlerType getType() { return EHT_Receive;};
148
149         bool start(int cycle);
150
151         bool prepare();
152
153     protected:
154         int handleBusReset(unsigned int generation);
155
156     private:
157         static enum raw1394_iso_disposition
158         iso_receive_handler(raw1394handle_t handle, unsigned char *data,
159                             unsigned int length, unsigned char channel,
160                             unsigned char tag, unsigned char sy, unsigned int cycle,
161                             unsigned int dropped);
162
163         enum raw1394_iso_disposition
164                 putPacket(unsigned char *data, unsigned int length,
165                           unsigned char channel, unsigned char tag, unsigned char sy,
166                           unsigned int cycle, unsigned int dropped);
167
168 };
169
170 /*!
171 \brief ISO transmit handler class
172 */
173
174 class IsoXmitHandler  : public IsoHandler
175 {
176     public:
177         IsoXmitHandler(int port);
178         IsoXmitHandler(int port, unsigned int buf_packets,
179                         unsigned int max_packet_size, int irq);
180         IsoXmitHandler(int port, unsigned int buf_packets,
181                         unsigned int max_packet_size, int irq,
182                         enum raw1394_iso_speed speed);
183         virtual ~IsoXmitHandler();
184
185         bool init();
186
187         enum EHandlerType getType() { return EHT_Transmit;};
188
189         unsigned int getPreBuffers() {return m_prebuffers;};
190         void setPreBuffers(unsigned int n) {m_prebuffers=n;};
191
192         bool start(int cycle);
193
194         bool prepare();
195
196     protected:
197         int handleBusReset(unsigned int generation);
198
199     private:
200         static enum raw1394_iso_disposition iso_transmit_handler(raw1394handle_t handle,
201                         unsigned char *data, unsigned int *length,
202                         unsigned char *tag, unsigned char *sy,
203                         int cycle, unsigned int dropped);
204         enum raw1394_iso_disposition
205                 getPacket(unsigned char *data, unsigned int *length,
206                         unsigned char *tag, unsigned char *sy,
207                         int cycle, unsigned int dropped);
208
209         enum raw1394_iso_speed m_speed;
210
211         unsigned int m_prebuffers;
212
213 };
214
215 }
216
217 #endif /* __FFADO_ISOHANDLER__  */
218
219
220
Note: See TracBrowser for help on using the browser.