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

Revision 287, 5.9 kB (checked in by jwoithe, 16 years ago)

Some cleanups to the MotuStreamProcessor? source.
First pass at a stop preparation method (StreamProcessor::preparedToStop()).
Motu uses preparedToStop to write zero data to device before iso closedown.

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
115 protected:
116        
117
118         void setManager(StreamProcessorManager *manager) {m_manager=manager;};
119         void clearManager() {m_manager=0;};
120
121         unsigned int m_nb_buffers; ///< cached from manager->getNbBuffers(), the number of periods to buffer
122         unsigned int m_period; ///< cached from manager->getPeriod(), the period size
123
124         unsigned int m_xruns;
125         signed int m_framecounter;
126
127         unsigned int m_framerate;
128
129         StreamProcessorManager *m_manager;
130
131         bool m_running;
132         bool m_disabled;
133
134     StreamStatistics m_PacketStat;
135     StreamStatistics m_PeriodStat;
136    
137     StreamStatistics m_WakeupStat;
138    
139
140     DECLARE_DEBUG_MODULE;
141
142
143 };
144
145 /*!
146 \brief Class providing a generic interface for receive Stream Processors
147
148 */
149 class ReceiveStreamProcessor : public StreamProcessor {
150
151 public:
152         ReceiveStreamProcessor(int port, int framerate);
153
154         virtual ~ReceiveStreamProcessor();
155
156
157         virtual enum EProcessorType getType() {return E_Receive;};
158        
159         virtual enum raw1394_iso_disposition
160                 getPacket(unsigned char *data, unsigned int *length,
161                       unsigned char *tag, unsigned char *sy,
162                       int cycle, unsigned int dropped, unsigned int max_length)
163                       {return RAW1394_ISO_STOP;};
164                      
165         virtual enum raw1394_iso_disposition putPacket(unsigned char *data, unsigned int length,
166                       unsigned char channel, unsigned char tag, unsigned char sy,
167                           unsigned int cycle, unsigned int dropped) = 0;
168         virtual void setVerboseLevel(int l);
169
170 protected:
171
172      DECLARE_DEBUG_MODULE;
173
174
175 };
176
177 /*!
178 \brief Class providing a generic interface for receive Stream Processors
179
180 */
181 class TransmitStreamProcessor : public StreamProcessor {
182
183 public:
184         TransmitStreamProcessor(int port, int framerate);
185
186         virtual ~TransmitStreamProcessor();
187
188         virtual enum EProcessorType getType() {return E_Transmit;};
189
190         virtual enum raw1394_iso_disposition
191                 putPacket(unsigned char *data, unsigned int length,
192                       unsigned char channel, unsigned char tag, unsigned char sy,
193                           unsigned int cycle, unsigned int dropped) {return RAW1394_ISO_STOP;};
194                          
195         virtual enum raw1394_iso_disposition
196                 getPacket(unsigned char *data, unsigned int *length,
197                       unsigned char *tag, unsigned char *sy,
198                       int cycle, unsigned int dropped, unsigned int max_length) = 0;
199         virtual void setVerboseLevel(int l);
200
201 protected:
202
203      DECLARE_DEBUG_MODULE;
204
205
206 };
207
208 }
209
210 #endif /* __FREEBOB_STREAMPROCESSOR__ */
211
212
Note: See TracBrowser for help on using the browser.