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

Revision 753, 6.5 kB (checked in by ppalmers, 13 years ago)

have separate threads for every handler

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