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 |
}; |
---|
72 |
|
---|
73 |
bool StreamProcessor::init() |
---|
74 |
{ |
---|
75 |
debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "enter...\n"); |
---|
76 |
|
---|
77 |
return IsoStream::init(); |
---|
78 |
} |
---|
79 |
|
---|
80 |
bool StreamProcessor::reset() { |
---|
81 |
|
---|
82 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Resetting...\n"); |
---|
83 |
|
---|
84 |
resetFrameCounter(); |
---|
85 |
|
---|
86 |
resetXrunCounter(); |
---|
87 |
|
---|
88 |
// loop over the ports to reset them |
---|
89 |
if (!PortManager::resetPorts()) { |
---|
90 |
debugFatal("Could not reset ports\n"); |
---|
91 |
return false; |
---|
92 |
} |
---|
93 |
|
---|
94 |
// reset the iso stream |
---|
95 |
if (!IsoStream::reset()) { |
---|
96 |
debugFatal("Could not reset isostream\n"); |
---|
97 |
return false; |
---|
98 |
} |
---|
99 |
return true; |
---|
100 |
|
---|
101 |
} |
---|
102 |
|
---|
103 |
bool StreamProcessor::prepare() { |
---|
104 |
|
---|
105 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Preparing...\n"); |
---|
106 |
// TODO: implement |
---|
107 |
|
---|
108 |
// init the ports |
---|
109 |
|
---|
110 |
if(!m_manager) { |
---|
111 |
debugFatal("Not attached to a manager!\n"); |
---|
112 |
return -1; |
---|
113 |
} |
---|
114 |
|
---|
115 |
m_nb_buffers=m_manager->getNbBuffers(); |
---|
116 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Setting m_nb_buffers : %d\n", m_nb_buffers); |
---|
117 |
|
---|
118 |
m_period=m_manager->getPeriodSize(); |
---|
119 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Setting m_period : %d\n", m_period); |
---|
120 |
|
---|
121 |
// loop over the ports to reset them |
---|
122 |
PortManager::preparePorts(); |
---|
123 |
|
---|
124 |
// reset the iso stream |
---|
125 |
IsoStream::prepare(); |
---|
126 |
|
---|
127 |
return true; |
---|
128 |
|
---|
129 |
} |
---|
130 |
|
---|
131 |
bool StreamProcessor::transfer() { |
---|
132 |
|
---|
133 |
debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "Transferring period...\n"); |
---|
134 |
// TODO: implement |
---|
135 |
|
---|
136 |
return true; |
---|
137 |
} |
---|
138 |
|
---|
139 |
bool StreamProcessor::isRunning() { |
---|
140 |
return m_running; |
---|
141 |
} |
---|
142 |
|
---|
143 |
void StreamProcessor::enable() { |
---|
144 |
if(!m_running) { |
---|
145 |
debugWarning("The StreamProcessor is not running yet, enable() might not be a good idea.\n"); |
---|
146 |
} |
---|
147 |
m_disabled=false; |
---|
148 |
}; |
---|
149 |
|
---|
150 |
|
---|
151 |
/** |
---|
152 |
* Decrements the frame counter, in a atomic way. This |
---|
153 |
* is thread safe. |
---|
154 |
*/ |
---|
155 |
void StreamProcessor::decrementFrameCounter() { |
---|
156 |
SUBSTRACT_ATOMIC((SInt32 *)&m_framecounter,m_period); |
---|
157 |
}; |
---|
158 |
|
---|
159 |
/** |
---|
160 |
* Resets the frame counter, in a atomic way. This |
---|
161 |
* is thread safe. |
---|
162 |
*/ |
---|
163 |
void StreamProcessor::resetFrameCounter() { |
---|
164 |
ZERO_ATOMIC((SInt32 *)&m_framecounter); |
---|
165 |
}; |
---|
166 |
|
---|
167 |
/** |
---|
168 |
* Resets the xrun counter, in a atomic way. This |
---|
169 |
* is thread safe. |
---|
170 |
*/ |
---|
171 |
void StreamProcessor::resetXrunCounter() { |
---|
172 |
ZERO_ATOMIC((SInt32 *)&m_xruns); |
---|
173 |
}; |
---|
174 |
|
---|
175 |
void StreamProcessor::setVerboseLevel(int l) { |
---|
176 |
setDebugLevel(l); |
---|
177 |
IsoStream::setVerboseLevel(l); |
---|
178 |
PortManager::setVerboseLevel(l); |
---|
179 |
|
---|
180 |
} |
---|
181 |
|
---|
182 |
ReceiveStreamProcessor::ReceiveStreamProcessor(int port, int framerate) |
---|
183 |
: StreamProcessor(IsoStream::EST_Receive, port, framerate) { |
---|
184 |
|
---|
185 |
} |
---|
186 |
|
---|
187 |
ReceiveStreamProcessor::~ReceiveStreamProcessor() { |
---|
188 |
|
---|
189 |
} |
---|
190 |
|
---|
191 |
void ReceiveStreamProcessor::setVerboseLevel(int l) { |
---|
192 |
setDebugLevel(l); |
---|
193 |
StreamProcessor::setVerboseLevel(l); |
---|
194 |
|
---|
195 |
} |
---|
196 |
|
---|
197 |
|
---|
198 |
TransmitStreamProcessor::TransmitStreamProcessor( int port, int framerate) |
---|
199 |
: StreamProcessor(IsoStream::EST_Transmit, port, framerate) { |
---|
200 |
|
---|
201 |
} |
---|
202 |
|
---|
203 |
TransmitStreamProcessor::~TransmitStreamProcessor() { |
---|
204 |
|
---|
205 |
} |
---|
206 |
|
---|
207 |
void TransmitStreamProcessor::setVerboseLevel(int l) { |
---|
208 |
setDebugLevel(l); |
---|
209 |
StreamProcessor::setVerboseLevel(l); |
---|
210 |
|
---|
211 |
} |
---|
212 |
|
---|
213 |
} |
---|