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

Revision 233, 4.9 kB (checked in by pieterpalmers, 18 years ago)

- reworked the debug module to use RT safe messaging

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
29 #include "FreebobAtomic.h"
30
31 #include "StreamProcessor.h"
32 #include "StreamProcessorManager.h"
33 #include <assert.h>
34
35 namespace FreebobStreaming {
36
37 IMPL_DEBUG_MODULE( StreamProcessor, StreamProcessor, DEBUG_LEVEL_NORMAL );
38 IMPL_DEBUG_MODULE( ReceiveStreamProcessor, ReceiveStreamProcessor, DEBUG_LEVEL_NORMAL );
39 IMPL_DEBUG_MODULE( TransmitStreamProcessor, TransmitStreamProcessor, DEBUG_LEVEL_NORMAL );
40
41 StreamProcessor::StreamProcessor(enum IsoStream::EStreamType type, int port, int framerate)
42         : IsoStream(type, port)
43         , m_nb_buffers(0)
44         , m_manager(0)
45         , m_period(0)
46         , m_xruns(0)
47         , m_framecounter(0)
48         , m_framerate(framerate)
49         , m_running(false)
50         , m_disabled(true)
51 {
52
53 }
54
55 StreamProcessor::~StreamProcessor() {
56
57 }
58
59 void StreamProcessor::dumpInfo()
60 {
61
62         debugOutputShort( DEBUG_LEVEL_NORMAL, " StreamProcessor information\n");
63         debugOutputShort( DEBUG_LEVEL_NORMAL, "  Iso stream info:\n");
64        
65         ((IsoStream*)this)->dumpInfo();
66         debugOutputShort( DEBUG_LEVEL_NORMAL, "  Frame counter  : %d\n", m_framecounter);
67         debugOutputShort( DEBUG_LEVEL_NORMAL, "  Xruns          : %d\n", m_xruns);
68         debugOutputShort( DEBUG_LEVEL_NORMAL, "  Running        : %d\n", m_running);
69         debugOutputShort( DEBUG_LEVEL_NORMAL, "  Enabled        : %d\n", !m_disabled);
70        
71     m_PeriodStat.dumpInfo();
72     m_PacketStat.dumpInfo();
73     m_WakeupStat.dumpInfo();
74        
75        
76 };
77
78 bool StreamProcessor::init()
79 {
80         debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "enter...\n");
81
82         return IsoStream::init();
83 }
84
85 bool StreamProcessor::reset() {
86
87         debugOutput( DEBUG_LEVEL_VERBOSE, "Resetting...\n");
88
89         resetFrameCounter();
90
91         resetXrunCounter();
92
93         // loop over the ports to reset them
94         if (!PortManager::resetPorts()) {
95                 debugFatal("Could not reset ports\n");
96                 return false;
97         }
98
99         // reset the iso stream
100         if (!IsoStream::reset()) {
101                 debugFatal("Could not reset isostream\n");
102                 return false;
103         }
104         return true;
105        
106 }
107
108 bool StreamProcessor::prepare() {
109
110         debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing...\n");
111 // TODO: implement
112
113         // init the ports
114        
115         if(!m_manager) {
116                 debugFatal("Not attached to a manager!\n");
117                 return -1;
118         }
119
120         m_nb_buffers=m_manager->getNbBuffers();
121         debugOutput( DEBUG_LEVEL_VERBOSE, "Setting m_nb_buffers  : %d\n", m_nb_buffers);
122
123         m_period=m_manager->getPeriodSize();
124         debugOutput( DEBUG_LEVEL_VERBOSE, "Setting m_period      : %d\n", m_period);
125
126         // loop over the ports to reset them
127         PortManager::preparePorts();
128
129         // reset the iso stream
130         IsoStream::prepare();
131        
132         return true;
133
134 }
135
136 bool StreamProcessor::transfer() {
137
138         debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Transferring period...\n");
139 // TODO: implement
140
141         return true;
142 }
143
144 bool StreamProcessor::isRunning() {
145         return m_running;
146 }
147
148 void StreamProcessor::enable()  {
149         if(!m_running) {
150                 debugWarning("The StreamProcessor is not running yet, enable() might not be a good idea.\n");
151         }
152         m_disabled=false;
153 };
154
155
156 /**
157  * Decrements the frame counter, in a atomic way. This
158  * is thread safe.
159  */
160 void StreamProcessor::decrementFrameCounter() {
161         SUBSTRACT_ATOMIC((SInt32 *)&m_framecounter,m_period);
162 };
163
164 /**
165  * Resets the frame counter, in a atomic way. This
166  * is thread safe.
167  */
168 void StreamProcessor::resetFrameCounter() {
169         ZERO_ATOMIC((SInt32 *)&m_framecounter);
170 };
171
172 /**
173  * Resets the xrun counter, in a atomic way. This
174  * is thread safe.
175  */
176 void StreamProcessor::resetXrunCounter() {
177         ZERO_ATOMIC((SInt32 *)&m_xruns);
178 };
179
180 void StreamProcessor::setVerboseLevel(int l) {
181         setDebugLevel(l);
182         IsoStream::setVerboseLevel(l);
183         PortManager::setVerboseLevel(l);
184
185 }
186
187 ReceiveStreamProcessor::ReceiveStreamProcessor(int port, int framerate)
188         : StreamProcessor(IsoStream::EST_Receive, port, framerate) {
189
190 }
191
192 ReceiveStreamProcessor::~ReceiveStreamProcessor() {
193
194 }
195
196 void ReceiveStreamProcessor::setVerboseLevel(int l) {
197         setDebugLevel(l);
198         StreamProcessor::setVerboseLevel(l);
199
200 }
201
202
203 TransmitStreamProcessor::TransmitStreamProcessor( int port, int framerate)
204         : StreamProcessor(IsoStream::EST_Transmit, port, framerate) {
205
206 }
207
208 TransmitStreamProcessor::~TransmitStreamProcessor() {
209
210 }
211
212 void TransmitStreamProcessor::setVerboseLevel(int l) {
213         setDebugLevel(l);
214         StreamProcessor::setVerboseLevel(l);
215
216 }
217
218 }
Note: See TracBrowser for help on using the browser.