root/trunk/libffado/src/devicemanager.cpp

Revision 750, 24.6 kB (checked in by ppalmers, 15 years ago)

Code refactoring. Tries to simplify things and tries to put all code where it belongs.

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