root/trunk/libffado/src/devicemanager.cpp

Revision 784, 24.7 kB (checked in by ppalmers, 15 years ago)

fix shutdown bug

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