root/branches/libfreebob-2.0/src/libstreaming/StreamProcessor.h

Revision 312, 5.9 kB (checked in by jwoithe, 17 years ago)

MOTU: fix xrun recovery glitches inadvertantly introduced in r309.
MOTU: preliminary MIDI port support. Rate control still needs to be added so it probably won't work in its current form yet. MIDI has not yet been tested.
MOTU: tweaks to receive/transmit missed cycle detection.
jack driver: during driver shutdown don't try to free NULL ports created for non-audio ports during initialisation to preserve device port index locations.

Line 
1 /* $Id$ */
2
3 /*
4  *   FreeBob Streaming API
5  *   FreeBob = Firewire (pro-)audio for linux
6  *
7  *   http://freebob.sf.net
8  *
9  *   Copyright (C) 2005,2006 Pieter Palmers <pieterpalmers@users.sourceforge.net>
10  *
11  *   This program is free software {} you can redistribute it and/or modify
12  *   it under the terms of the GNU General Public License as published by
13  *   the Free Software Foundation {} either version 2 of the License, or
14  *   (at your option) any later version.
15  *
16  *   This program is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY {} without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with this program {} if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  *
26  *
27  */
28 #ifndef __FREEBOB_STREAMPROCESSOR__
29 #define __FREEBOB_STREAMPROCESSOR__
30
31 #include "../debugmodule/debugmodule.h"
32
33 #include "IsoStream.h"
34 #include "PortManager.h"
35 #include "streamstatistics.h"
36
37 namespace FreebobStreaming {
38
39 class StreamProcessorManager;
40
41 /*!
42 \brief Class providing a generic interface for Stream Processors
43
44  A stream processor multiplexes or demultiplexes an ISO stream into a
45  collection of ports. This class should be subclassed, and the relevant
46  functions should be overloaded.
47  
48 */
49 class StreamProcessor : public IsoStream,
50                         public PortManager {
51
52         friend class StreamProcessorManager;
53
54 public:
55         enum EProcessorType {
56                 E_Receive,
57                 E_Transmit
58         };
59
60         StreamProcessor(enum IsoStream::EStreamType type, int port, int framerate);
61         virtual ~StreamProcessor();
62
63         virtual enum raw1394_iso_disposition
64                 putPacket(unsigned char *data, unsigned int length,
65                       unsigned char channel, unsigned char tag, unsigned char sy,
66                           unsigned int cycle, unsigned int dropped) = 0;
67         virtual enum raw1394_iso_disposition
68                 getPacket(unsigned char *data, unsigned int *length,
69                       unsigned char *tag, unsigned char *sy,
70                       int cycle, unsigned int dropped, unsigned int max_length) = 0;
71
72         virtual enum EProcessorType getType() =0;
73
74         bool xrunOccurred() { return (m_xruns>0);};
75
76     /**
77      * This is used for implementing the synchronisation.
78      * As long as this function doesn't return true, the current buffer
79      * contents are not transfered to the packet decoders.
80      *
81      * This means that there can be more events in the buffer than
82      * one period worth of them, should the synchronisation mechanism
83      * require this
84      * @return
85      */
86         virtual bool isOnePeriodReady()=0;
87        
88         unsigned int getNbPeriodsReady() { if(m_period) return m_framecounter/m_period; else return 0;};
89         virtual void decrementFrameCounter();
90         virtual void incrementFrameCounter(int nbframes);
91        
92         // move to private?
93         void resetFrameCounter();
94     void resetXrunCounter();
95
96         bool isRunning(); ///< returns true if there is some stream data processed
97         void enable(); ///< enable the stream processing
98         void disable() {m_disabled=true;}; ///< disable the stream processing
99         bool isEnabled() {return !m_disabled;};
100
101         virtual bool transfer(); ///< transfer the buffer contents from/to client
102
103         virtual bool reset(); ///< reset the streams & buffers (e.g. after xrun)
104
105         virtual bool prepare(); ///< prepare the streams & buffers (e.g. prefill)
106
107         virtual void dumpInfo();
108
109         virtual bool init();
110
111         virtual void setVerboseLevel(int l);
112
113         virtual bool preparedForStop() {return true;};
114         virtual bool preparedForStart() {return true;};
115
116 protected:
117        
118
119         void setManager(StreamProcessorManager *manager) {m_manager=manager;};
120         void clearManager() {m_manager=0;};
121
122         unsigned int m_nb_buffers; ///< cached from manager->getNbBuffers(), the number of periods to buffer
123         unsigned int m_period; ///< cached from manager->getPeriod(), the period size
124
125         unsigned int m_xruns;
126         signed int m_framecounter;
127
128         unsigned int m_framerate;
129
130         StreamProcessorManager *m_manager;
131
132         bool m_running;
133         bool m_disabled;
134
135     StreamStatistics m_PacketStat;
136     StreamStatistics m_PeriodStat;
137    
138     StreamStatistics m_WakeupStat;
139    
140
141     DECLARE_DEBUG_MODULE;
142
143
144 };
145
146 /*!
147 \brief Class providing a generic interface for receive Stream Processors
148
149 */
150 class ReceiveStreamProcessor : public StreamProcessor {
151
152 public:
153         ReceiveStreamProcessor(int port, int framerate);
154
155         virtual ~ReceiveStreamProcessor();
156
157
158         virtual enum EProcessorType getType() {return E_Receive;};
159        
160         virtual enum raw1394_iso_disposition
161                 getPacket(unsigned char *data, unsigned int *length,
162                       unsigned char *tag, unsigned char *sy,
163                       int cycle, unsigned int dropped, unsigned int max_length)
164                       {return RAW1394_ISO_STOP;};
165                      
166         virtual enum raw1394_iso_disposition putPacket(unsigned char *data, unsigned int length,
167                       unsigned char channel, unsigned char tag, unsigned char sy,
168                           unsigned int cycle, unsigned int dropped) = 0;
169         virtual void setVerboseLevel(int l);
170
171 protected:
172
173      DECLARE_DEBUG_MODULE;
174
175
176 };
177
178 /*!
179 \brief Class providing a generic interface for receive Stream Processors
180
181 */
182 class TransmitStreamProcessor : public StreamProcessor {
183
184 public:
185         TransmitStreamProcessor(int port, int framerate);
186
187         virtual ~TransmitStreamProcessor();
188
189         virtual enum EProcessorType getType() {return E_Transmit;};
190
191         virtual enum raw1394_iso_disposition
192                 putPacket(unsigned char *data, unsigned int length,
193                       unsigned char channel, unsigned char tag, unsigned char sy,
194                           unsigned int cycle, unsigned int dropped) {return RAW1394_ISO_STOP;};
195                          
196         virtual enum raw1394_iso_disposition
197                 getPacket(unsigned char *data, unsigned int *length,
198                       unsigned char *tag, unsigned char *sy,
199                       int cycle, unsigned int dropped, unsigned int max_length) = 0;
200         virtual void setVerboseLevel(int l);
201
202 protected:
203
204      DECLARE_DEBUG_MODULE;
205
206
207 };
208
209 }
210
211 #endif /* __FREEBOB_STREAMPROCESSOR__ */
212
213
Note: See TracBrowser for help on using the browser.