1 |
/* |
---|
2 |
* Copyright (C) 2005-2007 by Daniel Wagner |
---|
3 |
* Copyright (C) 2005-2007 by Pieter Palmers |
---|
4 |
* |
---|
5 |
* This file is part of FFADO |
---|
6 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
---|
7 |
* |
---|
8 |
* FFADO is based upon FreeBoB. |
---|
9 |
* |
---|
10 |
* This program is free software: you can redistribute it and/or modify |
---|
11 |
* it under the terms of the GNU General Public License as published by |
---|
12 |
* the Free Software Foundation, either version 3 of the License, or |
---|
13 |
* (at your option) any later version. |
---|
14 |
* |
---|
15 |
* This program is distributed in the hope that it will be useful, |
---|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 |
* GNU General Public License for more details. |
---|
19 |
* |
---|
20 |
* You should have received a copy of the GNU General Public License |
---|
21 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
22 |
* |
---|
23 |
*/ |
---|
24 |
|
---|
25 |
#include "fbtypes.h" |
---|
26 |
|
---|
27 |
#include "devicemanager.h" |
---|
28 |
#include "ffadodevice.h" |
---|
29 |
|
---|
30 |
#include "libieee1394/configrom.h" |
---|
31 |
#include "libieee1394/ieee1394service.h" |
---|
32 |
|
---|
33 |
#include "libstreaming/generic/StreamProcessor.h" |
---|
34 |
#include "libstreaming/StreamProcessorManager.h" |
---|
35 |
|
---|
36 |
#include "debugmodule/debugmodule.h" |
---|
37 |
|
---|
38 |
#ifdef ENABLE_BEBOB |
---|
39 |
#include "bebob/bebob_avdevice.h" |
---|
40 |
#include "maudio/maudio_avdevice.h" |
---|
41 |
#endif |
---|
42 |
|
---|
43 |
#ifdef ENABLE_GENERICAVC |
---|
44 |
#include "genericavc/avc_avdevice.h" |
---|
45 |
#endif |
---|
46 |
|
---|
47 |
#ifdef ENABLE_FIREWORKS |
---|
48 |
#include "fireworks/fireworks_device.h" |
---|
49 |
#endif |
---|
50 |
|
---|
51 |
#ifdef ENABLE_BOUNCE |
---|
52 |
#include "bounce/bounce_avdevice.h" |
---|
53 |
#include "bounce/bounce_slave_avdevice.h" |
---|
54 |
#endif |
---|
55 |
|
---|
56 |
#ifdef ENABLE_MOTU |
---|
57 |
#include "motu/motu_avdevice.h" |
---|
58 |
#endif |
---|
59 |
|
---|
60 |
#ifdef ENABLE_RME |
---|
61 |
#include "rme/rme_avdevice.h" |
---|
62 |
#endif |
---|
63 |
|
---|
64 |
#ifdef ENABLE_DICE |
---|
65 |
#include "dice/dice_avdevice.h" |
---|
66 |
#endif |
---|
67 |
|
---|
68 |
#ifdef ENABLE_METRIC_HALO |
---|
69 |
#include "metrichalo/mh_avdevice.h" |
---|
70 |
#endif |
---|
71 |
|
---|
72 |
#include <iostream> |
---|
73 |
#include <sstream> |
---|
74 |
|
---|
75 |
#include <algorithm> |
---|
76 |
|
---|
77 |
using namespace std; |
---|
78 |
|
---|
79 |
IMPL_DEBUG_MODULE( DeviceManager, DeviceManager, DEBUG_LEVEL_NORMAL ); |
---|
80 |
|
---|
81 |
DeviceManager::DeviceManager() |
---|
82 |
: Control::Container("devicemanager") |
---|
83 |
, m_processorManager( new Streaming::StreamProcessorManager() ) |
---|
84 |
{ |
---|
85 |
addOption(Util::OptionContainer::Option("slaveMode",false)); |
---|
86 |
addOption(Util::OptionContainer::Option("snoopMode",false)); |
---|
87 |
} |
---|
88 |
|
---|
89 |
DeviceManager::~DeviceManager() |
---|
90 |
{ |
---|
91 |
delete m_processorManager; |
---|
92 |
|
---|
93 |
for ( FFADODeviceVectorIterator it = m_avDevices.begin(); |
---|
94 |
it != m_avDevices.end(); |
---|
95 |
++it ) |
---|
96 |
{ |
---|
97 |
if (!deleteElement(*it)) { |
---|
98 |
debugWarning("failed to remove AvDevice from Control::Container\n"); |
---|
99 |
} |
---|
100 |
delete *it; |
---|
101 |
} |
---|
102 |
|
---|
103 |
for ( FunctorVectorIterator it = m_busreset_functors.begin(); |
---|
104 |
it != m_busreset_functors.end(); |
---|
105 |
++it ) |
---|
106 |
{ |
---|
107 |
delete *it; |
---|
108 |
} |
---|
109 |
|
---|
110 |
for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin(); |
---|
111 |
it != m_1394Services.end(); |
---|
112 |
++it ) |
---|
113 |
{ |
---|
114 |
delete *it; |
---|
115 |
} |
---|
116 |
} |
---|
117 |
|
---|
118 |
bool |
---|
119 |
DeviceManager::setThreadParameters(bool rt, int priority) { |
---|
120 |
if (!m_processorManager->setThreadParameters(rt, priority)) { |
---|
121 |
debugError("Could not set processor manager thread parameters\n"); |
---|
122 |
return false; |
---|
123 |
} |
---|
124 |
for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin(); |
---|
125 |
it != m_1394Services.end(); |
---|
126 |
++it ) |
---|
127 |
{ |
---|
128 |
if (!(*it)->setThreadParameters(rt, priority)) { |
---|
129 |
debugError("Could not set 1394 service thread parameters\n"); |
---|
130 |
return false; |
---|
131 |
} |
---|
132 |
} |
---|
133 |
m_thread_realtime = rt; |
---|
134 |
m_thread_priority = priority; |
---|
135 |
return true; |
---|
136 |
} |
---|
137 |
|
---|
138 |
bool |
---|
139 |
DeviceManager::initialize() |
---|
140 |
{ |
---|
141 |
assert(m_1394Services.size() == 0); |
---|
142 |
assert(m_busreset_functors.size() == 0); |
---|
143 |
|
---|
144 |
unsigned int nb_detected_ports = Ieee1394Service::detectNbPorts(); |
---|
145 |
if (nb_detected_ports == 0) { |
---|
146 |
debugFatal("No firewire ports found.\n"); |
---|
147 |
return false; |
---|
148 |
} |
---|
149 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Found %d firewire adapters (ports)\n", nb_detected_ports); |
---|
150 |
for (unsigned int port = 0; port < nb_detected_ports; port++) { |
---|
151 |
Ieee1394Service* tmp1394Service = new Ieee1394Service(); |
---|
152 |
if ( !tmp1394Service ) { |
---|
153 |
debugFatal( "Could not create Ieee1349Service object for port %d\n", port ); |
---|
154 |
return false; |
---|
155 |
} |
---|
156 |
tmp1394Service->setVerboseLevel( getDebugLevel() ); |
---|
157 |
m_1394Services.push_back(tmp1394Service); |
---|
158 |
|
---|
159 |
tmp1394Service->setThreadParameters(m_thread_realtime, m_thread_priority); |
---|
160 |
if ( !tmp1394Service->initialize( port ) ) { |
---|
161 |
debugFatal( "Could not initialize Ieee1349Service object for port %d\n", port ); |
---|
162 |
return false; |
---|
163 |
} |
---|
164 |
// add the bus reset handler |
---|
165 |
Functor* tmp_busreset_functor = new MemberFunctor0< DeviceManager*, |
---|
166 |
void (DeviceManager::*)() > |
---|
167 |
( this, &DeviceManager::busresetHandler, false ); |
---|
168 |
if ( !tmp_busreset_functor ) { |
---|
169 |
debugFatal( "Could not create busreset handler for port %d\n", port ); |
---|
170 |
return false; |
---|
171 |
} |
---|
172 |
m_busreset_functors.push_back(tmp_busreset_functor); |
---|
173 |
|
---|
174 |
tmp1394Service->addBusResetHandler( tmp_busreset_functor ); |
---|
175 |
} |
---|
176 |
|
---|
177 |
return true; |
---|
178 |
} |
---|
179 |
|
---|
180 |
bool |
---|
181 |
DeviceManager::addSpecString(char *s) { |
---|
182 |
std::string spec = s; |
---|
183 |
if(isSpecStringValid(spec)) { |
---|
184 |
debugOutput(DEBUG_LEVEL_VERBOSE, "Adding spec string %s\n", spec.c_str()); |
---|
185 |
m_SpecStrings.push_back(spec); |
---|
186 |
return true; |
---|
187 |
} else { |
---|
188 |
debugError("Invalid spec string: %s\n", spec.c_str()); |
---|
189 |
return false; |
---|
190 |
} |
---|
191 |
} |
---|
192 |
|
---|
193 |
bool |
---|
194 |
DeviceManager::isSpecStringValid(std::string s) { |
---|
195 |
return true; |
---|
196 |
} |
---|
197 |
|
---|
198 |
void |
---|
199 |
DeviceManager::busresetHandler() |
---|
200 |
{ |
---|
201 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Bus reset...\n" ); |
---|
202 |
// FIXME: what port was the bus reset on? |
---|
203 |
// propagate the bus reset to all avDevices |
---|
204 |
for ( FFADODeviceVectorIterator it = m_avDevices.begin(); |
---|
205 |
it != m_avDevices.end(); |
---|
206 |
++it ) |
---|
207 |
{ |
---|
208 |
(*it)->handleBusReset(); |
---|
209 |
} |
---|
210 |
} |
---|
211 |
|
---|
212 |
bool |
---|
213 |
DeviceManager::discover( ) |
---|
214 |
{ |
---|
215 |
bool slaveMode=false; |
---|
216 |
if(!getOption("slaveMode", slaveMode)) { |
---|
217 |
debugWarning("Could not retrieve slaveMode parameter, defauling to false\n"); |
---|
218 |
} |
---|
219 |
bool snoopMode=false; |
---|
220 |
if(!getOption("snoopMode", snoopMode)) { |
---|
221 |
debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); |
---|
222 |
} |
---|
223 |
|
---|
224 |
setVerboseLevel(getDebugLevel()); |
---|
225 |
|
---|
226 |
for ( FFADODeviceVectorIterator it = m_avDevices.begin(); |
---|
227 |
it != m_avDevices.end(); |
---|
228 |
++it ) |
---|
229 |
{ |
---|
230 |
if (!deleteElement(*it)) { |
---|
231 |
debugWarning("failed to remove AvDevice from Control::Container\n"); |
---|
232 |
} |
---|
233 |
delete *it; |
---|
234 |
} |
---|
235 |
m_avDevices.clear(); |
---|
236 |
|
---|
237 |
if (!slaveMode) { |
---|
238 |
for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin(); |
---|
239 |
it != m_1394Services.end(); |
---|
240 |
++it ) |
---|
241 |
{ |
---|
242 |
Ieee1394Service *portService = *it; |
---|
243 |
for ( fb_nodeid_t nodeId = 0; |
---|
244 |
nodeId < portService->getNodeCount(); |
---|
245 |
++nodeId ) |
---|
246 |
{ |
---|
247 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Probing node %d...\n", nodeId ); |
---|
248 |
|
---|
249 |
if (nodeId == portService->getLocalNodeId()) { |
---|
250 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Skipping local node (%d)...\n", nodeId ); |
---|
251 |
continue; |
---|
252 |
} |
---|
253 |
|
---|
254 |
std::auto_ptr<ConfigRom> configRom = |
---|
255 |
std::auto_ptr<ConfigRom>( new ConfigRom( *portService, nodeId ) ); |
---|
256 |
if ( !configRom->initialize() ) { |
---|
257 |
// \todo If a PHY on the bus is in power safe mode then |
---|
258 |
// the config rom is missing. So this might be just |
---|
259 |
// such this case and we can safely skip it. But it might |
---|
260 |
// be there is a real software problem on our side. |
---|
261 |
// This should be handlede more carefuly. |
---|
262 |
debugOutput( DEBUG_LEVEL_NORMAL, |
---|
263 |
"Could not read config rom from device (node id %d). " |
---|
264 |
"Skip device discovering for this node\n", |
---|
265 |
nodeId ); |
---|
266 |
continue; |
---|
267 |
} |
---|
268 |
|
---|
269 |
bool already_in_vector = false; |
---|
270 |
for ( FFADODeviceVectorIterator it = m_avDevices.begin(); |
---|
271 |
it != m_avDevices.end(); |
---|
272 |
++it ) |
---|
273 |
{ |
---|
274 |
if ((*it)->getConfigRom().getGuid() == configRom->getGuid()) { |
---|
275 |
already_in_vector = true; |
---|
276 |
break; |
---|
277 |
} |
---|
278 |
} |
---|
279 |
if (already_in_vector) { |
---|
280 |
debugWarning("Device with GUID %s already discovered on other port, skipping device...\n", |
---|
281 |
configRom->getGuidString().c_str()); |
---|
282 |
continue; |
---|
283 |
} |
---|
284 |
|
---|
285 |
if( getDebugLevel() >= DEBUG_LEVEL_VERBOSE) { |
---|
286 |
configRom->printConfigRom(); |
---|
287 |
} |
---|
288 |
|
---|
289 |
FFADODevice* avDevice = getDriverForDevice( configRom, |
---|
290 |
nodeId ); |
---|
291 |
|
---|
292 |
if ( avDevice ) { |
---|
293 |
debugOutput( DEBUG_LEVEL_NORMAL, |
---|
294 |
"driver found for device %d\n", |
---|
295 |
nodeId ); |
---|
296 |
|
---|
297 |
avDevice->setVerboseLevel( getDebugLevel() ); |
---|
298 |
bool isFromCache = false; |
---|
299 |
if ( avDevice->loadFromCache() ) { |
---|
300 |
debugOutput( DEBUG_LEVEL_VERBOSE, "could load from cache\n" ); |
---|
301 |
isFromCache = true; |
---|
302 |
// restore the debug level for everything that was loaded |
---|
303 |
avDevice->setVerboseLevel( getDebugLevel() ); |
---|
304 |
} else if ( avDevice->discover() ) { |
---|
305 |
debugOutput( DEBUG_LEVEL_VERBOSE, "discovery successful\n" ); |
---|
306 |
} else { |
---|
307 |
debugError( "could not discover device\n" ); |
---|
308 |
delete avDevice; |
---|
309 |
continue; |
---|
310 |
} |
---|
311 |
|
---|
312 |
if (snoopMode) { |
---|
313 |
debugOutput( DEBUG_LEVEL_VERBOSE, |
---|
314 |
"Enabling snoop mode on node %d...\n", nodeId ); |
---|
315 |
|
---|
316 |
if(!avDevice->setOption("snoopMode", snoopMode)) { |
---|
317 |
debugWarning("Could not set snoop mode for device on node %d\n", nodeId); |
---|
318 |
delete avDevice; |
---|
319 |
continue; |
---|
320 |
} |
---|
321 |
} |
---|
322 |
|
---|
323 |
if ( !isFromCache && !avDevice->saveCache() ) { |
---|
324 |
debugOutput( DEBUG_LEVEL_VERBOSE, "No cached version of AVC model created\n" ); |
---|
325 |
} |
---|
326 |
m_avDevices.push_back( avDevice ); |
---|
327 |
|
---|
328 |
if (!addElement(avDevice)) { |
---|
329 |
debugWarning("failed to add AvDevice to Control::Container\n"); |
---|
330 |
} |
---|
331 |
|
---|
332 |
debugOutput( DEBUG_LEVEL_NORMAL, "discovery of node %d on port %d done...\n", nodeId, portService->getPort() ); |
---|
333 |
} |
---|
334 |
} |
---|
335 |
} |
---|
336 |
|
---|
337 |
debugOutput( DEBUG_LEVEL_NORMAL, "Discovery finished...\n" ); |
---|
338 |
// FIXME: do better sorting |
---|
339 |
// sort the m_avDevices vector on their GUID |
---|
340 |
// then assign reassign the id's to the devices |
---|
341 |
// the side effect of this is that for the same set of attached devices, |
---|
342 |
// a device id always corresponds to the same device |
---|
343 |
sort(m_avDevices.begin(), m_avDevices.end(), FFADODevice::compareGUID); |
---|
344 |
int i=0; |
---|
345 |
for ( FFADODeviceVectorIterator it = m_avDevices.begin(); |
---|
346 |
it != m_avDevices.end(); |
---|
347 |
++it ) |
---|
348 |
{ |
---|
349 |
if ( !(*it)->setId( i++ ) ) { |
---|
350 |
debugError( "setting Id failed\n" ); |
---|
351 |
} |
---|
352 |
} |
---|
353 |
showDeviceInfo(); |
---|
354 |
return true; |
---|
355 |
} else { // slave mode |
---|
356 |
Ieee1394Service *portService = m_1394Services.at(0); |
---|
357 |
fb_nodeid_t nodeId = portService->getLocalNodeId(); |
---|
358 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Starting in slave mode on node %d...\n", nodeId ); |
---|
359 |
|
---|
360 |
std::auto_ptr<ConfigRom> configRom = |
---|
361 |
std::auto_ptr<ConfigRom>( new ConfigRom( *portService, |
---|
362 |
nodeId ) ); |
---|
363 |
if ( !configRom->initialize() ) { |
---|
364 |
// \todo If a PHY on the bus is in power safe mode then |
---|
365 |
// the config rom is missing. So this might be just |
---|
366 |
// such this case and we can safely skip it. But it might |
---|
367 |
// be there is a real software problem on our side. |
---|
368 |
// This should be handled more carefuly. |
---|
369 |
debugOutput( DEBUG_LEVEL_NORMAL, |
---|
370 |
"Could not read config rom from device (node id %d). " |
---|
371 |
"Skip device discovering for this node\n", |
---|
372 |
nodeId ); |
---|
373 |
return false; |
---|
374 |
} |
---|
375 |
|
---|
376 |
FFADODevice* avDevice = getSlaveDriver( configRom ); |
---|
377 |
if ( avDevice ) { |
---|
378 |
debugOutput( DEBUG_LEVEL_NORMAL, |
---|
379 |
"driver found for device %d\n", |
---|
380 |
nodeId ); |
---|
381 |
|
---|
382 |
avDevice->setVerboseLevel( getDebugLevel() ); |
---|
383 |
|
---|
384 |
if ( !avDevice->discover() ) { |
---|
385 |
debugError( "could not discover device\n" ); |
---|
386 |
delete avDevice; |
---|
387 |
return false; |
---|
388 |
} |
---|
389 |
|
---|
390 |
if ( !avDevice->setId( m_avDevices.size() ) ) { |
---|
391 |
debugError( "setting Id failed\n" ); |
---|
392 |
} |
---|
393 |
if ( getDebugLevel() >= DEBUG_LEVEL_VERBOSE ) { |
---|
394 |
avDevice->showDevice(); |
---|
395 |
} |
---|
396 |
m_avDevices.push_back( avDevice ); |
---|
397 |
debugOutput( DEBUG_LEVEL_NORMAL, "discovery of node %d on port %d done...\n", nodeId, portService->getPort() ); |
---|
398 |
} |
---|
399 |
|
---|
400 |
debugOutput( DEBUG_LEVEL_NORMAL, "discovery finished...\n" ); |
---|
401 |
return true; |
---|
402 |
} |
---|
403 |
} |
---|
404 |
|
---|
405 |
bool |
---|
406 |
DeviceManager::initStreaming() |
---|
407 |
{ |
---|
408 |
// iterate over the found devices |
---|
409 |
// add the stream processors of the devices to the managers |
---|
410 |
for ( FFADODeviceVectorIterator it = m_avDevices.begin(); |
---|
411 |
it != m_avDevices.end(); |
---|
412 |
++it ) |
---|
413 |
{ |
---|
414 |
FFADODevice *device = *it; |
---|
415 |
assert(device); |
---|
416 |
|
---|
417 |
debugOutput(DEBUG_LEVEL_VERBOSE, "Locking device (%p)\n", device); |
---|
418 |
|
---|
419 |
if (!device->lock()) { |
---|
420 |
debugWarning("Could not lock device, skipping device (%p)!\n", device); |
---|
421 |
continue; |
---|
422 |
} |
---|
423 |
|
---|
424 |
debugOutput(DEBUG_LEVEL_VERBOSE, "Setting samplerate to %d for (%p)\n", |
---|
425 |
m_processorManager->getNominalRate(), device); |
---|
426 |
|
---|
427 |
// Set the device's sampling rate to that requested |
---|
428 |
// FIXME: does this really belong here? If so we need to handle errors. |
---|
429 |
if (!device->setSamplingFrequency(m_processorManager->getNominalRate())) { |
---|
430 |
debugOutput(DEBUG_LEVEL_VERBOSE, " => Retry setting samplerate to %d for (%p)\n", |
---|
431 |
m_processorManager->getNominalRate(), device); |
---|
432 |
|
---|
433 |
// try again: |
---|
434 |
if (!device->setSamplingFrequency(m_processorManager->getNominalRate())) { |
---|
435 |
debugFatal("Could not set sampling frequency to %d\n",m_processorManager->getNominalRate()); |
---|
436 |
return false; |
---|
437 |
} |
---|
438 |
} |
---|
439 |
// prepare the device |
---|
440 |
device->prepare(); |
---|
441 |
} |
---|
442 |
|
---|
443 |
// set the sync source |
---|
444 |
if (!m_processorManager->setSyncSource(getSyncSource())) { |
---|
445 |
debugWarning("Could not set processorManager sync source (%p)\n", |
---|
446 |
getSyncSource()); |
---|
447 |
} |
---|
448 |
return true; |
---|
449 |
} |
---|
450 |
|
---|
451 |
bool |
---|
452 |
DeviceManager::prepareStreaming() |
---|
453 |
{ |
---|
454 |
if (!m_processorManager->prepare()) { |
---|
455 |
debugFatal("Could not prepare streaming...\n"); |
---|
456 |
return false; |
---|
457 |
} |
---|
458 |
return true; |
---|
459 |
} |
---|
460 |
|
---|
461 |
bool |
---|
462 |
DeviceManager::finishStreaming() { |
---|
463 |
bool result = true; |
---|
464 |
// iterate over the found devices |
---|
465 |
for ( FFADODeviceVectorIterator it = m_avDevices.begin(); |
---|
466 |
it != m_avDevices.end(); |
---|
467 |
++it ) |
---|
468 |
{ |
---|
469 |
debugOutput(DEBUG_LEVEL_VERBOSE, "Unlocking device (%p)\n", *it); |
---|
470 |
|
---|
471 |
if (!(*it)->unlock()) { |
---|
472 |
debugWarning("Could not unlock device (%p)!\n", *it); |
---|
473 |
result = false; |
---|
474 |
} |
---|
475 |
} |
---|
476 |
return result; |
---|
477 |
} |
---|
478 |
|
---|
479 |
bool |
---|
480 |
DeviceManager::startStreaming() { |
---|
481 |
// create the connections for all devices |
---|
482 |
// iterate over the found devices |
---|
483 |
// add the stream processors of the devices to the managers |
---|
484 |
for ( FFADODeviceVectorIterator it = m_avDevices.begin(); |
---|
485 |
it != m_avDevices.end(); |
---|
486 |
++it ) |
---|
487 |
{ |
---|
488 |
FFADODevice *device = *it; |
---|
489 |
assert(device); |
---|
490 |
|
---|
491 |
int j=0; |
---|
492 |
for(j=0; j < device->getStreamCount(); j++) { |
---|
493 |
debugOutput(DEBUG_LEVEL_VERBOSE,"Starting stream %d of device %p\n", j, device); |
---|
494 |
// start the stream |
---|
495 |
if (!device->startStreamByIndex(j)) { |
---|
496 |
debugWarning("Could not start stream %d of device %p\n", j, device); |
---|
497 |
continue; |
---|
498 |
} |
---|
499 |
} |
---|
500 |
|
---|
501 |
if (!device->enableStreaming()) { |
---|
502 |
debugWarning("Could not enable streaming on device %p!\n", device); |
---|
503 |
} |
---|
504 |
} |
---|
505 |
|
---|
506 |
if(m_processorManager->start()) { |
---|
507 |
return true; |
---|
508 |
} else { |
---|
509 |
stopStreaming(); |
---|
510 |
return false; |
---|
511 |
} |
---|
512 |
} |
---|
513 |
|
---|
514 |
bool |
---|
515 |
DeviceManager::resetStreaming() { |
---|
516 |
return true; |
---|
517 |
} |
---|
518 |
|
---|
519 |
bool |
---|
520 |
DeviceManager::stopStreaming() |
---|
521 |
{ |
---|
522 |
bool result = true; |
---|
523 |
m_processorManager->stop(); |
---|
524 |
|
---|
525 |
// create the connections for all devices |
---|
526 |
// iterate over the found devices |
---|
527 |
// add the stream processors of the devices to the managers |
---|
528 |
for ( FFADODeviceVectorIterator it = m_avDevices.begin(); |
---|
529 |
it != m_avDevices.end(); |
---|
530 |
++it ) |
---|
531 |
{ |
---|
532 |
FFADODevice *device = *it; |
---|
533 |
assert(device); |
---|
534 |
|
---|
535 |
if (!device->disableStreaming()) { |
---|
536 |
debugWarning("Could not disable streaming on device %p!\n", device); |
---|
537 |
} |
---|
538 |
|
---|
539 |
int j=0; |
---|
540 |
for(j=0; j < device->getStreamCount(); j++) { |
---|
541 |
debugOutput(DEBUG_LEVEL_VERBOSE,"Stopping stream %d of device %p\n", j, device); |
---|
542 |
// stop the stream |
---|
543 |
// start the stream |
---|
544 |
if (!device->stopStreamByIndex(j)) { |
---|
545 |
debugWarning("Could not stop stream %d of device %p\n", j, device); |
---|
546 |
result = false; |
---|
547 |
continue; |
---|
548 |
} |
---|
549 |
} |
---|
550 |
} |
---|
551 |
return result; |
---|
552 |
} |
---|
553 |
|
---|
554 |
bool |
---|
555 |
DeviceManager::waitForPeriod() { |
---|
556 |
if(m_processorManager->waitForPeriod()) { |
---|
557 |
return true; |
---|
558 |
} else { |
---|
559 |
debugWarning("XRUN detected\n"); |
---|
560 |
// do xrun recovery |
---|
561 |
m_processorManager->handleXrun(); |
---|
562 |
return false; |
---|
563 |
} |
---|
564 |
} |
---|
565 |
|
---|
566 |
bool |
---|
567 |
DeviceManager::setStreamingParams(unsigned int period, unsigned int rate, unsigned int nb_buffers) { |
---|
568 |
m_processorManager->setPeriodSize(period); |
---|
569 |
m_processorManager->setNominalRate(rate); |
---|
570 |
m_processorManager->setNbBuffers(nb_buffers); |
---|
571 |
return true; |
---|
572 |
} |
---|
573 |
|
---|
574 |
FFADODevice* |
---|
575 |
DeviceManager::getDriverForDevice( std::auto_ptr<ConfigRom>( configRom ), |
---|
576 |
int id ) |
---|
577 |
{ |
---|
578 |
#ifdef ENABLE_BEBOB |
---|
579 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Trying BeBoB...\n" ); |
---|
580 |
if ( BeBoB::AvDevice::probe( *configRom.get() ) ) { |
---|
581 |
return BeBoB::AvDevice::createDevice( *this, configRom ); |
---|
582 |
} |
---|
583 |
#endif |
---|
584 |
|
---|
585 |
#ifdef ENABLE_GENERICAVC |
---|
586 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Generic AV/C...\n" ); |
---|
587 |
if ( GenericAVC::AvDevice::probe( *configRom.get() ) ) { |
---|
588 |
return GenericAVC::AvDevice::createDevice( *this, configRom ); |
---|
589 |
} |
---|
590 |
#endif |
---|
591 |
|
---|
592 |
#ifdef ENABLE_FIREWORKS |
---|
593 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Trying ECHO Audio FireWorks...\n" ); |
---|
594 |
if ( FireWorks::Device::probe( *configRom.get() ) ) { |
---|
595 |
return FireWorks::Device::createDevice( *this, configRom ); |
---|
596 |
} |
---|
597 |
#endif |
---|
598 |
|
---|
599 |
#ifdef ENABLE_BEBOB |
---|
600 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Trying M-Audio...\n" ); |
---|
601 |
if ( MAudio::AvDevice::probe( *configRom.get() ) ) { |
---|
602 |
return MAudio::AvDevice::createDevice( *this, configRom ); |
---|
603 |
} |
---|
604 |
#endif |
---|
605 |
|
---|
606 |
#ifdef ENABLE_MOTU |
---|
607 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Motu...\n" ); |
---|
608 |
if ( Motu::MotuDevice::probe( *configRom.get() ) ) { |
---|
609 |
return Motu::MotuDevice::createDevice( *this, configRom ); |
---|
610 |
} |
---|
611 |
#endif |
---|
612 |
|
---|
613 |
#ifdef ENABLE_DICE |
---|
614 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Dice...\n" ); |
---|
615 |
if ( Dice::DiceAvDevice::probe( *configRom.get() ) ) { |
---|
616 |
return Dice::DiceAvDevice::createDevice( *this, configRom ); |
---|
617 |
} |
---|
618 |
#endif |
---|
619 |
|
---|
620 |
#ifdef ENABLE_METRIC_HALO |
---|
621 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Metric Halo...\n" ); |
---|
622 |
if ( MetricHalo::MHAvDevice::probe( *configRom.get() ) ) { |
---|
623 |
return MetricHalo::MHAvDevice::createDevice( *this, configRom ); |
---|
624 |
} |
---|
625 |
#endif |
---|
626 |
|
---|
627 |
#ifdef ENABLE_RME |
---|
628 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Trying RME...\n" ); |
---|
629 |
if ( Rme::RmeDevice::probe( *configRom.get() ) ) { |
---|
630 |
return Rme::RmeDevice::createDevice( *this, configRom ); |
---|
631 |
} |
---|
632 |
#endif |
---|
633 |
|
---|
634 |
#ifdef ENABLE_BOUNCE |
---|
635 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Bounce...\n" ); |
---|
636 |
if ( Bounce::BounceDevice::probe( *configRom.get() ) ) { |
---|
637 |
return Bounce::BounceDevice::createDevice( *this, configRom ); |
---|
638 |
} |
---|
639 |
#endif |
---|
640 |
|
---|
641 |
return 0; |
---|
642 |
} |
---|
643 |
|
---|
644 |
FFADODevice* |
---|
645 |
DeviceManager::getSlaveDriver( std::auto_ptr<ConfigRom>( configRom ) ) |
---|
646 |
{ |
---|
647 |
|
---|
648 |
#ifdef ENABLE_BOUNCE |
---|
649 |
if ( Bounce::BounceSlaveDevice::probe( *configRom.get() ) ) { |
---|
650 |
return Bounce::BounceSlaveDevice::createDevice( configRom ); |
---|
651 |
} |
---|
652 |
#endif |
---|
653 |
|
---|
654 |
return 0; |
---|
655 |
} |
---|
656 |
|
---|
657 |
bool |
---|
658 |
DeviceManager::isValidNode(int node) |
---|
659 |
{ |
---|
660 |
for ( FFADODeviceVectorIterator it = m_avDevices.begin(); |
---|
661 |
it != m_avDevices.end(); |
---|
662 |
++it ) |
---|
663 |
{ |
---|
664 |
FFADODevice* avDevice = *it; |
---|
665 |
|
---|
666 |
if (avDevice->getConfigRom().getNodeId() == node) { |
---|
667 |
return true; |
---|
668 |
} |
---|
669 |
} |
---|
670 |
return false; |
---|
671 |
} |
---|
672 |
|
---|
673 |
int |
---|
674 |
DeviceManager::getNbDevices() |
---|
675 |
{ |
---|
676 |
return m_avDevices.size(); |
---|
677 |
} |
---|
678 |
|
---|
679 |
int |
---|
680 |
DeviceManager::getDeviceNodeId( int deviceNr ) |
---|
681 |
{ |
---|
682 |
if ( ! ( deviceNr < getNbDevices() ) ) { |
---|
683 |
debugError( "Device number out of range (%d)\n", deviceNr ); |
---|
684 |
return -1; |
---|
685 |
} |
---|
686 |
|
---|
687 |
FFADODevice* avDevice = m_avDevices.at( deviceNr ); |
---|
688 |
|
---|
689 |
if ( !avDevice ) { |
---|
690 |
debugError( "Could not get device at position (%d)\n", deviceNr ); |
---|
691 |
} |
---|
692 |
|
---|
693 |
return avDevice->getConfigRom().getNodeId(); |
---|
694 |
} |
---|
695 |
|
---|
696 |
FFADODevice* |
---|
697 |
DeviceManager::getAvDevice( int nodeId ) |
---|
698 |
{ |
---|
699 |
for ( FFADODeviceVectorIterator it = m_avDevices.begin(); |
---|
700 |
it != m_avDevices.end(); |
---|
701 |
++it ) |
---|
702 |
{ |
---|
703 |
FFADODevice* avDevice = *it; |
---|
704 |
if ( avDevice->getConfigRom().getNodeId() == nodeId ) { |
---|
705 |
return avDevice; |
---|
706 |
} |
---|
707 |
} |
---|
708 |
|
---|
709 |
return 0; |
---|
710 |
} |
---|
711 |
|
---|
712 |
FFADODevice* |
---|
713 |
DeviceManager::getAvDeviceByIndex( int idx ) |
---|
714 |
{ |
---|
715 |
return m_avDevices.at(idx); |
---|
716 |
} |
---|
717 |
|
---|
718 |
unsigned int |
---|
719 |
DeviceManager::getAvDeviceCount( ) |
---|
720 |
{ |
---|
721 |
return m_avDevices.size(); |
---|
722 |
} |
---|
723 |
|
---|
724 |
/** |
---|
725 |
* Return the streamprocessor that is to be used as |
---|
726 |
* the sync source. |
---|
727 |
* |
---|
728 |
* Algorithm still to be determined |
---|
729 |
* |
---|
730 |
* @return StreamProcessor that is sync source |
---|
731 |
*/ |
---|
732 |
Streaming::StreamProcessor * |
---|
733 |
DeviceManager::getSyncSource() { |
---|
734 |
FFADODevice* device = getAvDeviceByIndex(0); |
---|
735 |
|
---|
736 |
bool slaveMode=false; |
---|
737 |
if(!getOption("slaveMode", slaveMode)) { |
---|
738 |
debugWarning("Could not retrieve slaveMode parameter, defauling to false\n"); |
---|
739 |
} |
---|
740 |
|
---|
741 |
#warning TEST CODE FOR BOUNCE DEVICE !! |
---|
742 |
// this makes the bounce slave use the xmit SP as sync source |
---|
743 |
if (slaveMode) { |
---|
744 |
return device->getStreamProcessorByIndex(1); |
---|
745 |
} else { |
---|
746 |
return device->getStreamProcessorByIndex(0); |
---|
747 |
} |
---|
748 |
} |
---|
749 |
|
---|
750 |
bool |
---|
751 |
DeviceManager::deinitialize() |
---|
752 |
{ |
---|
753 |
return true; |
---|
754 |
} |
---|
755 |
|
---|
756 |
|
---|
757 |
void |
---|
758 |
DeviceManager::setVerboseLevel(int l) |
---|
759 |
{ |
---|
760 |
setDebugLevel(l); |
---|
761 |
Control::Element::setVerboseLevel(l); |
---|
762 |
m_processorManager->setVerboseLevel(l); |
---|
763 |
for ( FFADODeviceVectorIterator it = m_avDevices.begin(); |
---|
764 |
it != m_avDevices.end(); |
---|
765 |
++it ) |
---|
766 |
{ |
---|
767 |
(*it)->setVerboseLevel(l); |
---|
768 |
} |
---|
769 |
for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin(); |
---|
770 |
it != m_1394Services.end(); |
---|
771 |
++it ) |
---|
772 |
{ |
---|
773 |
(*it)->setVerboseLevel(l); |
---|
774 |
} |
---|
775 |
debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); |
---|
776 |
} |
---|
777 |
|
---|
778 |
void |
---|
779 |
DeviceManager::showDeviceInfo() { |
---|
780 |
debugOutput(DEBUG_LEVEL_NORMAL, "===== Device Manager =====\n"); |
---|
781 |
Control::Element::show(); |
---|
782 |
|
---|
783 |
int i=0; |
---|
784 |
for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin(); |
---|
785 |
it != m_1394Services.end(); |
---|
786 |
++it ) |
---|
787 |
{ |
---|
788 |
debugOutput(DEBUG_LEVEL_NORMAL, "--- IEEE1394 Service %2d ---\n", i++); |
---|
789 |
(*it)->show(); |
---|
790 |
} |
---|
791 |
|
---|
792 |
i=0; |
---|
793 |
for ( FFADODeviceVectorIterator it = m_avDevices.begin(); |
---|
794 |
it != m_avDevices.end(); |
---|
795 |
++it ) |
---|
796 |
{ |
---|
797 |
FFADODevice* avDevice = *it; |
---|
798 |
debugOutput(DEBUG_LEVEL_NORMAL, "--- Device %2d ---\n", i++); |
---|
799 |
avDevice->showDevice(); |
---|
800 |
|
---|
801 |
debugOutput(DEBUG_LEVEL_NORMAL, "Clock sync sources:\n"); |
---|
802 |
FFADODevice::ClockSourceVector sources=avDevice->getSupportedClockSources(); |
---|
803 |
for ( FFADODevice::ClockSourceVector::const_iterator it |
---|
804 |
= sources.begin(); |
---|
805 |
it != sources.end(); |
---|
806 |
++it ) |
---|
807 |
{ |
---|
808 |
FFADODevice::ClockSource c=*it; |
---|
809 |
debugOutput(DEBUG_LEVEL_NORMAL, " Type: %s, Id: %2d, Valid: %1d, Active: %1d, Locked %1d, Slipping: %1d, Description: %s\n", |
---|
810 |
FFADODevice::ClockSourceTypeToString(c.type), c.id, c.valid, c.active, c.locked, c.slipping, c.description.c_str()); |
---|
811 |
} |
---|
812 |
} |
---|
813 |
} |
---|
814 |
void |
---|
815 |
DeviceManager::showStreamingInfo() { |
---|
816 |
m_processorManager->dumpInfo(); |
---|
817 |
} |
---|