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

Revision 268, 5.8 kB (checked in by jwoithe, 18 years ago)

StreamProcessor::m_framecounter is now signed again, since the ability to go
negative is utilised for some devices in certain circumstances.

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