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

Revision 754, 5.1 kB (checked in by ppalmers, 13 years ago)

- simplify IsoHandler?
- fix some small issues

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, enum EHandlerType t);
55     IsoHandler(IsoHandlerManager& manager, enum EHandlerType t,
56                unsigned int buf_packets, unsigned int max_packet_size, int irq);
57     IsoHandler(IsoHandlerManager& manager, enum EHandlerType t,
58                unsigned int buf_packets, unsigned int max_packet_size, int irq, enum raw1394_iso_speed speed);
59     ~IsoHandler();
60
61 private: // the ISO callback interface
62     static enum raw1394_iso_disposition
63     iso_receive_handler(raw1394handle_t handle, unsigned char *data,
64                         unsigned int length, unsigned char channel,
65                         unsigned char tag, unsigned char sy, unsigned int cycle,
66                         unsigned int dropped);
67
68     enum raw1394_iso_disposition
69             putPacket(unsigned char *data, unsigned int length,
70                         unsigned char channel, unsigned char tag, unsigned char sy,
71                         unsigned int cycle, unsigned int dropped);
72
73     static enum raw1394_iso_disposition iso_transmit_handler(raw1394handle_t handle,
74                     unsigned char *data, unsigned int *length,
75                     unsigned char *tag, unsigned char *sy,
76                     int cycle, unsigned int dropped);
77     enum raw1394_iso_disposition
78             getPacket(unsigned char *data, unsigned int *length,
79                     unsigned char *tag, unsigned char *sy,
80                     int cycle, unsigned int dropped);
81
82 public:
83     // runnable interface
84     bool Init();
85     bool Execute();
86     int getFileDescriptor() { return raw1394_get_fd(m_handle);};
87     bool setThreadParameters(bool rt, int priority);
88
89     bool init();
90     bool prepare();
91
92     bool iterate();
93     void setVerboseLevel(int l);
94
95     bool enable() {return enable(-1);};
96     bool enable(int cycle);
97     bool disable();
98
99     void flush();
100     enum EHandlerType getType() {return m_type;};
101
102     bool isEnabled()
103         {return m_State == E_Running;};
104
105     // no setter functions, because those would require a re-init
106     unsigned int getMaxPacketSize() { return m_max_packet_size;};
107     unsigned int getNbBuffers() { return m_buf_packets;};
108     int getPacketLatency() { return m_irq_interval;};
109
110     int getPacketCount() {return m_packetcount;};
111     void resetPacketCount() {m_packetcount=0;};
112
113     int getDroppedCount() {return m_dropped;};
114     void resetDroppedCount() {m_dropped=0;};
115
116     unsigned int getPreBuffers() {return m_prebuffers;};
117     void setPreBuffers(unsigned int n) {m_prebuffers=n;};
118
119     void dumpInfo();
120
121     bool inUse() {return (m_Client != 0) ;};
122     bool isStreamRegistered(Streaming::StreamProcessor *s) {return (m_Client == s);};
123
124     bool registerStream(Streaming::StreamProcessor *);
125     bool unregisterStream(Streaming::StreamProcessor *);
126
127 private:
128     IsoHandlerManager& m_manager;
129     enum EHandlerType m_type;
130     raw1394handle_t m_handle;
131     unsigned int    m_buf_packets;
132     unsigned int    m_max_packet_size;
133     int             m_irq_interval;
134
135     int m_packetcount;
136     int m_dropped;
137     Streaming::StreamProcessor *m_Client;
138
139     int handleBusReset(unsigned int generation);
140
141     static int busreset_handler(raw1394handle_t handle, unsigned int generation);
142
143     struct pollfd   m_poll_fd;
144     int             m_poll_timeout;
145     // threading
146     bool            m_realtime;
147     int             m_priority;
148     Util::Thread *  m_Thread;
149
150     enum raw1394_iso_speed m_speed;
151     unsigned int m_prebuffers;
152
153     // the state machine
154     enum EHandlerStates {
155         E_Created,
156         E_Initialized,
157         E_Prepared,
158         E_Running,
159         E_Error
160     };
161     enum EHandlerStates m_State;
162     DECLARE_DEBUG_MODULE;
163 };
164
165 #endif /* __FFADO_ISOHANDLER__  */
166
167
168
Note: See TracBrowser for help on using the browser.