root/trunk/libffado/src/devicemanager.cpp

Revision 898, 24.9 kB (checked in by wagi, 13 years ago)

add non-debug print function to ConfigRom?

  • 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     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( bool useCache )
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->printConfigRomDebug();
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 ( useCache && 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 enum DeviceManager::eWaitResult
556 DeviceManager::waitForPeriod() {
557     if(m_processorManager->waitForPeriod()) {
558         return eWR_OK;
559     } else {
560         debugWarning("XRUN detected\n");
561         // do xrun recovery
562         if(m_processorManager->handleXrun()) {
563             return eWR_Xrun;
564         } else {
565             debugError("Could not handle XRUN\n");
566             return eWR_Error;
567         }
568     }
569 }
570
571 bool
572 DeviceManager::setStreamingParams(unsigned int period, unsigned int rate, unsigned int nb_buffers) {
573     m_processorManager->setPeriodSize(period);
574     m_processorManager->setNominalRate(rate);
575     m_processorManager->setNbBuffers(nb_buffers);
576     return true;
577 }
578
579 FFADODevice*
580 DeviceManager::getDriverForDevice( std::auto_ptr<ConfigRom>( configRom ),
581                                    int id )
582 {
583 #ifdef ENABLE_BEBOB
584     debugOutput( DEBUG_LEVEL_VERBOSE, "Trying BeBoB...\n" );
585     if ( BeBoB::AvDevice::probe( *configRom.get() ) ) {
586         return BeBoB::AvDevice::createDevice( *this, configRom );
587     }
588 #endif
589
590 #ifdef ENABLE_GENERICAVC
591     debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Generic AV/C...\n" );
592     if ( GenericAVC::AvDevice::probe( *configRom.get() ) ) {
593         return GenericAVC::AvDevice::createDevice( *this, configRom );
594     }
595 #endif
596
597 #ifdef ENABLE_FIREWORKS
598     debugOutput( DEBUG_LEVEL_VERBOSE, "Trying ECHO Audio FireWorks...\n" );
599     if ( FireWorks::Device::probe( *configRom.get() ) ) {
600         return FireWorks::Device::createDevice( *this, configRom );
601     }
602 #endif
603
604 #ifdef ENABLE_BEBOB
605     debugOutput( DEBUG_LEVEL_VERBOSE, "Trying M-Audio...\n" );
606     if ( MAudio::AvDevice::probe( *configRom.get() ) ) {
607         return MAudio::AvDevice::createDevice( *this, configRom );
608     }
609 #endif
610
611 #ifdef ENABLE_MOTU
612     debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Motu...\n" );
613     if ( Motu::MotuDevice::probe( *configRom.get() ) ) {
614         return Motu::MotuDevice::createDevice( *this, configRom );
615     }
616 #endif
617
618 #ifdef ENABLE_DICE
619     debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Dice...\n" );
620     if ( Dice::DiceAvDevice::probe( *configRom.get() ) ) {
621         return Dice::DiceAvDevice::createDevice( *this, configRom );
622     }
623 #endif
624
625 #ifdef ENABLE_METRIC_HALO
626     debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Metric Halo...\n" );
627     if ( MetricHalo::MHAvDevice::probe( *configRom.get() ) ) {
628         return MetricHalo::MHAvDevice::createDevice( *this, configRom );
629     }
630 #endif
631
632 #ifdef ENABLE_RME
633     debugOutput( DEBUG_LEVEL_VERBOSE, "Trying RME...\n" );
634     if ( Rme::RmeDevice::probe( *configRom.get() ) ) {
635         return Rme::RmeDevice::createDevice( *this, configRom );
636     }
637 #endif
638
639 #ifdef ENABLE_BOUNCE
640     debugOutput( DEBUG_LEVEL_VERBOSE, "Trying Bounce...\n" );
641     if ( Bounce::BounceDevice::probe( *configRom.get() ) ) {
642         return Bounce::BounceDevice::createDevice( *this, configRom );
643     }
644 #endif
645
646     return 0;
647 }
648
649 FFADODevice*
650 DeviceManager::getSlaveDriver( std::auto_ptr<ConfigRom>( configRom ) )
651 {
652
653 #ifdef ENABLE_BOUNCE
654     if ( Bounce::BounceSlaveDevice::probe( *configRom.get() ) ) {
655         return Bounce::BounceSlaveDevice::createDevice( configRom );
656     }
657 #endif
658
659     return 0;
660 }
661
662 bool
663 DeviceManager::isValidNode(int node)
664 {
665     for ( FFADODeviceVectorIterator it = m_avDevices.begin();
666           it != m_avDevices.end();
667           ++it )
668     {
669         FFADODevice* avDevice = *it;
670
671         if (avDevice->getConfigRom().getNodeId() == node) {
672             return true;
673     }
674     }
675     return false;
676 }
677
678 int
679 DeviceManager::getNbDevices()
680 {
681     return m_avDevices.size();
682 }
683
684 int
685 DeviceManager::getDeviceNodeId( int deviceNr )
686 {
687     if ( ! ( deviceNr < getNbDevices() ) ) {
688         debugError( "Device number out of range (%d)\n", deviceNr );
689         return -1;
690     }
691
692     FFADODevice* avDevice = m_avDevices.at( deviceNr );
693
694     if ( !avDevice ) {
695         debugError( "Could not get device at position (%d)\n",  deviceNr );
696     }
697
698     return avDevice->getConfigRom().getNodeId();
699 }
700
701 FFADODevice*
702 DeviceManager::getAvDevice( int nodeId )
703 {
704     for ( FFADODeviceVectorIterator it = m_avDevices.begin();
705           it != m_avDevices.end();
706           ++it )
707     {
708         FFADODevice* avDevice = *it;
709         if ( avDevice->getConfigRom().getNodeId() == nodeId ) {
710             return avDevice;
711         }
712     }
713
714     return 0;
715 }
716
717 FFADODevice*
718 DeviceManager::getAvDeviceByIndex( int idx )
719 {
720     return m_avDevices.at(idx);
721 }
722
723 unsigned int
724 DeviceManager::getAvDeviceCount( )
725 {
726     return m_avDevices.size();
727 }
728
729 /**
730  * Return the streamprocessor that is to be used as
731  * the sync source.
732  *
733  * Algorithm still to be determined
734  *
735  * @return StreamProcessor that is sync source
736  */
737 Streaming::StreamProcessor *
738 DeviceManager::getSyncSource() {
739     FFADODevice* device = getAvDeviceByIndex(0);
740
741     bool slaveMode=false;
742     if(!getOption("slaveMode", slaveMode)) {
743         debugWarning("Could not retrieve slaveMode parameter, defauling to false\n");
744     }
745
746     #warning TEST CODE FOR BOUNCE DEVICE !!
747     // this makes the bounce slave use the xmit SP as sync source
748     if (slaveMode) {
749         return device->getStreamProcessorByIndex(1);
750     } else {
751         return device->getStreamProcessorByIndex(0);
752     }
753 }
754
755 bool
756 DeviceManager::deinitialize()
757 {
758     return true;
759 }
760
761
762 void
763 DeviceManager::setVerboseLevel(int l)
764 {
765     setDebugLevel(l);
766     Control::Element::setVerboseLevel(l);
767     m_processorManager->setVerboseLevel(l);
768     for ( FFADODeviceVectorIterator it = m_avDevices.begin();
769           it != m_avDevices.end();
770           ++it )
771     {
772         (*it)->setVerboseLevel(l);
773     }
774     for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin();
775           it != m_1394Services.end();
776           ++it )
777     {
778         (*it)->setVerboseLevel(l);
779     }
780     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l );
781 }
782
783 void
784 DeviceManager::showDeviceInfo() {
785     debugOutput(DEBUG_LEVEL_NORMAL, "===== Device Manager =====\n");
786     Control::Element::show();
787
788     int i=0;
789     for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin();
790           it != m_1394Services.end();
791           ++it )
792     {
793         debugOutput(DEBUG_LEVEL_NORMAL, "--- IEEE1394 Service %2d ---\n", i++);
794         (*it)->show();
795     }
796
797     i=0;
798     for ( FFADODeviceVectorIterator it = m_avDevices.begin();
799         it != m_avDevices.end();
800         ++it )
801     {
802         FFADODevice* avDevice = *it;
803         debugOutput(DEBUG_LEVEL_NORMAL, "--- Device %2d ---\n", i++);
804         avDevice->showDevice();
805
806         debugOutput(DEBUG_LEVEL_NORMAL, "Clock sync sources:\n");
807         FFADODevice::ClockSourceVector sources=avDevice->getSupportedClockSources();
808         for ( FFADODevice::ClockSourceVector::const_iterator it
809                 = sources.begin();
810             it != sources.end();
811             ++it )
812         {
813             FFADODevice::ClockSource c=*it;
814             debugOutput(DEBUG_LEVEL_NORMAL, " Type: %s, Id: %2d, Valid: %1d, Active: %1d, Locked %1d, Slipping: %1d, Description: %s\n",
815                 FFADODevice::ClockSourceTypeToString(c.type), c.id, c.valid, c.active, c.locked, c.slipping, c.description.c_str());
816         }
817     }
818 }
819 void
820 DeviceManager::showStreamingInfo() {
821     m_processorManager->dumpInfo();
822 }
Note: See TracBrowser for help on using the browser.