root/trunk/libffado/src/devicemanager.cpp

Revision 942, 26.1 kB (checked in by ppalmers, 16 years ago)

add support for the device spec strings (no more auto-grab-all)

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