root/trunk/libffado/src/devicemanager.cpp

Revision 909, 25.1 kB (checked in by ppalmers, 13 years ago)

fix port out of range bug

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