root/trunk/libffado/src/libieee1394/IsoHandler.h

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

Code refactoring. Tries to simplify things and tries to put all code where it belongs.

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 #include "IsoHandlerManager.h"
29
30 enum raw1394_iso_disposition ;
31
32 namespace Streaming {
33     class StreamProcessor;
34 }
35
36 /*!
37 \brief The Base Class for ISO Handlers
38
39  These classes perform the actual ISO communication through libraw1394.
40  They are different from Streaming::StreamProcessors because one handler can provide multiple
41  streams with packets in case of ISO multichannel receive.
42
43 */
44
45 class IsoHandler
46 {
47 public:
48     enum EHandlerType {
49             EHT_Receive,
50             EHT_Transmit
51     };
52     IsoHandler(IsoHandlerManager& manager);
53     IsoHandler(IsoHandlerManager& manager, unsigned int buf_packets, unsigned int max_packet_size, int irq);
54
55     virtual ~IsoHandler();
56
57     virtual bool init();
58     virtual bool prepare();
59
60     bool iterate();
61     void setVerboseLevel(int l);
62
63     virtual bool enable() {return enable(-1);};
64     virtual bool enable(int cycle);
65     virtual bool disable();
66
67     virtual void flush() = 0;
68
69     bool isEnabled()
70         {return m_State == E_Running;};
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 getPacketLatency() { 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     virtual void dumpInfo();
88
89     bool inUse() {return (m_Client != 0) ;};
90     virtual bool isStreamRegistered(Streaming::StreamProcessor *s) {return (m_Client == s);};
91
92     virtual bool registerStream(Streaming::StreamProcessor *);
93     virtual bool unregisterStream(Streaming::StreamProcessor *);
94
95     protected:
96         IsoHandlerManager& m_manager;
97         raw1394handle_t m_handle;
98         unsigned int    m_buf_packets;
99         unsigned int    m_max_packet_size;
100         int             m_irq_interval;
101
102         int m_packetcount;
103         int m_dropped;
104         Streaming::StreamProcessor *m_Client;
105
106         virtual int handleBusReset(unsigned int generation);
107         DECLARE_DEBUG_MODULE;
108     private:
109         static int busreset_handler(raw1394handle_t handle, unsigned int generation);
110
111     // the state machine
112     protected:
113         enum EHandlerStates {
114             E_Created,
115             E_Initialized,
116             E_Prepared,
117             E_Running,
118             E_Error
119         };
120         enum EHandlerStates m_State;
121 };
122
123 /*!
124 \brief ISO receive handler class (not multichannel)
125 */
126
127 class IsoRecvHandler : public IsoHandler
128 {
129
130     public:
131         IsoRecvHandler(IsoHandlerManager& manager);
132         IsoRecvHandler(IsoHandlerManager& manager, unsigned int buf_packets, unsigned int max_packet_size, int irq);
133         virtual ~IsoRecvHandler();
134
135         bool init();
136         enum EHandlerType getType() { return EHT_Receive;};
137         bool enable(int cycle);
138         virtual bool prepare();
139         virtual void flush();
140
141     protected:
142         int handleBusReset(unsigned int generation);
143     private:
144         static enum raw1394_iso_disposition
145         iso_receive_handler(raw1394handle_t handle, unsigned char *data,
146                             unsigned int length, unsigned char channel,
147                             unsigned char tag, unsigned char sy, unsigned int cycle,
148                             unsigned int dropped);
149
150         enum raw1394_iso_disposition
151                 putPacket(unsigned char *data, unsigned int length,
152                           unsigned char channel, unsigned char tag, unsigned char sy,
153                           unsigned int cycle, unsigned int dropped);
154 };
155
156 /*!
157 \brief ISO transmit handler class
158 */
159
160 class IsoXmitHandler  : public IsoHandler
161 {
162     public:
163         IsoXmitHandler(IsoHandlerManager& manager);
164         IsoXmitHandler(IsoHandlerManager& manager, unsigned int buf_packets,
165                         unsigned int max_packet_size, int irq);
166         IsoXmitHandler(IsoHandlerManager& manager, unsigned int buf_packets,
167                         unsigned int max_packet_size, int irq,
168                         enum raw1394_iso_speed speed);
169         virtual ~IsoXmitHandler();
170
171         bool init();
172         enum EHandlerType getType() { return EHT_Transmit;};
173         unsigned int getPreBuffers() {return m_prebuffers;};
174         void setPreBuffers(unsigned int n) {m_prebuffers=n;};
175         virtual bool enable(int cycle);
176         virtual bool prepare();
177         virtual void flush() {};
178
179         void dumpInfo();
180     protected:
181         int handleBusReset(unsigned int generation);
182
183     private:
184         static enum raw1394_iso_disposition iso_transmit_handler(raw1394handle_t handle,
185                         unsigned char *data, unsigned int *length,
186                         unsigned char *tag, unsigned char *sy,
187                         int cycle, unsigned int dropped);
188         enum raw1394_iso_disposition
189                 getPacket(unsigned char *data, unsigned int *length,
190                         unsigned char *tag, unsigned char *sy,
191                         int cycle, unsigned int dropped);
192
193         enum raw1394_iso_speed m_speed;
194         unsigned int m_prebuffers;
195 };
196
197 #endif /* __FFADO_ISOHANDLER__  */
198
199
200
Note: See TracBrowser for help on using the browser.