root/branches/libfreebob-1.0/src/bebob/bebob_avdevice.cpp

Revision 241, 23.9 kB (checked in by pieterpalmers, 18 years ago)

* configure.ac: Version bump to 1.0.0

* Changed all FreeBob? to FreeBoB
* Removed all .cvsignore
* Added Pieter to AUTHORS
* Updated NEWS and README (release canditate date added)

by Daniel Wagner

Line 
1 /* bebob_avdevice.cpp
2  * Copyright (C) 2005,06 by Daniel Wagner
3  *
4  * This file is part of FreeBoB.
5  *
6  * FreeBoB is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * FreeBoB is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with FreeBoB; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA.
19  */
20
21 #include "bebob/bebob_avdevice.h"
22 #include "bebob/bebob_avdevice_subunit.h"
23 #include "configrom.h"
24
25 #include "libfreebobavc/avc_plug_info.h"
26 #include "libfreebobavc/avc_extended_plug_info.h"
27 #include "libfreebobavc/avc_subunit_info.h"
28 #include "libfreebobavc/avc_extended_stream_format.h"
29 #include "libfreebobavc/serialize.h"
30 #include "libfreebobavc/ieee1394service.h"
31 #include "libfreebobavc/avc_definitions.h"
32
33 #include "debugmodule/debugmodule.h"
34
35 #include <iostream>
36
37 namespace BeBoB {
38
39 IMPL_DEBUG_MODULE( AvDevice, AvDevice, DEBUG_LEVEL_NORMAL );
40
41 AvDevice::AvDevice( Ieee1394Service& ieee1394service,
42                     int nodeId,
43                     int verboseLevel )
44     :  m_1394Service( &ieee1394service )
45     , m_nodeId( nodeId )
46     , m_verboseLevel( verboseLevel )
47     , m_plugManager( verboseLevel )
48 {
49     if ( m_verboseLevel ) {
50         setDebugLevel( DEBUG_LEVEL_VERBOSE );
51     }
52     debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::AvDevice (NodeID %d)\n",
53                  nodeId );
54
55     m_configRom = new ConfigRom( m_1394Service, m_nodeId );
56     m_configRom->initialize();
57 }
58
59 AvDevice::~AvDevice()
60 {
61     delete m_configRom;
62     for ( AvDeviceSubunitVector::iterator it = m_subunits.begin();
63           it != m_subunits.end();
64           ++it )
65     {
66         delete *it;
67     }
68     for ( AvPlugConnectionVector::iterator it = m_plugConnections.begin();
69           it != m_plugConnections.end();
70           ++it )
71     {
72         delete *it;
73     }
74     for ( AvPlugVector::iterator it = m_pcrPlugs.begin();
75           it != m_pcrPlugs.end();
76           ++it )
77     {
78         delete *it;
79     }
80     for ( AvPlugVector::iterator it = m_externalPlugs.begin();
81           it != m_externalPlugs.end();
82           ++it )
83     {
84         delete *it;
85     }
86 }
87
88 ConfigRom&
89 AvDevice::getConfigRom() const
90 {
91     return *m_configRom;
92 }
93
94 bool
95 AvDevice::discover()
96 {
97     if ( !enumerateSubUnits() ) {
98         debugError( "Could not enumarate sub units\n" );
99         return false;
100     }
101
102     if ( !discoverPlugs() ) {
103         debugError( "Detecting plugs failed\n" );
104         return false;
105     }
106
107     if ( !discoverPlugConnections() ) {
108         debugError( "Detecting plug connections failed\n" );
109         return false;
110     }
111
112     if ( !discoverSubUnitsPlugConnections() ) {
113         debugError( "Detecting plug connnection failed\n" );
114         return false;
115     }
116
117     if ( !discoverSyncModes() ) {
118         debugError( "Detecting sync modes failed\n" );
119         return false;
120     }
121
122     return true;
123 }
124
125 bool
126 AvDevice::discoverPlugs()
127 {
128     //////////////////////////////////////////////
129     // Get number of available isochronous input
130     // and output plugs of unit
131
132     PlugInfoCmd plugInfoCmd( m_1394Service );
133     plugInfoCmd.setNodeId( m_nodeId );
134     plugInfoCmd.setCommandType( AVCCommand::eCT_Status );
135     plugInfoCmd.setVerbose( m_verboseLevel );
136
137     if ( !plugInfoCmd.fire() ) {
138         debugError( "plug info command failed\n" );
139         return false;
140     }
141
142     debugOutput( DEBUG_LEVEL_NORMAL, "number of iso input plugs = %d\n",
143                  plugInfoCmd.m_serialBusIsochronousInputPlugs );
144     debugOutput( DEBUG_LEVEL_NORMAL, "number of iso output plugs = %d\n",
145                  plugInfoCmd.m_serialBusIsochronousOutputPlugs );
146     debugOutput( DEBUG_LEVEL_NORMAL, "number of external input plugs = %d\n",
147                  plugInfoCmd.m_externalInputPlugs );
148     debugOutput( DEBUG_LEVEL_NORMAL, "number of external output plugs = %d\n",
149                  plugInfoCmd.m_externalOutputPlugs );
150
151     if ( !discoverPlugsPCR( AvPlug::eAPD_Input,
152                             plugInfoCmd.m_serialBusIsochronousInputPlugs ) )
153     {
154         debugError( "pcr input plug discovering failed\n" );
155         return false;
156     }
157
158     if ( !discoverPlugsPCR( AvPlug::eAPD_Output,
159                             plugInfoCmd.m_serialBusIsochronousOutputPlugs ) )
160     {
161         debugError( "pcr output plug discovering failed\n" );
162         return false;
163     }
164
165     if ( !discoverPlugsExternal( AvPlug::eAPD_Input,
166                                  plugInfoCmd.m_externalInputPlugs ) )
167     {
168         debugError( "external input plug discovering failed\n" );
169         return false;
170     }
171
172     if ( !discoverPlugsExternal( AvPlug::eAPD_Output,
173                                  plugInfoCmd.m_externalOutputPlugs ) )
174     {
175         debugError( "external output plug discovering failed\n" );
176         return false;
177     }
178
179     return true;
180 }
181
182 bool
183 AvDevice::discoverPlugsPCR( AvPlug::EAvPlugDirection plugDirection,
184                             plug_id_t plugMaxId )
185 {
186     for ( int plugId = 0;
187           plugId < plugMaxId;
188           ++plugId )
189     {
190         AvPlug* plug  = new AvPlug( *m_1394Service,
191                                     m_nodeId,
192                                     m_plugManager,
193                                     AVCCommand::eST_Unit,
194                                     0xff,
195                                     0xff,
196                                     0xff,
197                                     AvPlug::eAPA_PCR,
198                                     plugDirection,
199                                     plugId,
200                                     m_verboseLevel );
201         if ( !plug || !plug->discover() ) {
202             debugError( "plug discovering failed\n" );
203             delete plug;
204             return false;
205         }
206
207         debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n",
208                      plug->getName() );
209         m_pcrPlugs.push_back( plug );
210     }
211
212     return true;
213 }
214
215 bool
216 AvDevice::discoverPlugsExternal( AvPlug::EAvPlugDirection plugDirection,
217                                  plug_id_t plugMaxId )
218 {
219     for ( int plugId = 0;
220           plugId < plugMaxId;
221           ++plugId )
222     {
223         AvPlug* plug  = new AvPlug( *m_1394Service,
224                                     m_nodeId,
225                                     m_plugManager,
226                                     AVCCommand::eST_Unit,
227                                     0xff,
228                                     0xff,
229                                     0xff,
230                                     AvPlug::eAPA_ExternalPlug,
231                                     plugDirection,
232                                     plugId,
233                                     m_verboseLevel );
234         if ( !plug || !plug->discover() ) {
235             debugError( "plug discovering failed\n" );
236             return false;
237         }
238
239         debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n",
240                      plug->getName() );
241         m_externalPlugs.push_back( plug );
242     }
243
244     return true;
245 }
246
247 bool
248 AvDevice::discoverPlugConnections()
249 {
250     for ( AvPlugVector::iterator it = m_pcrPlugs.begin();
251           it != m_pcrPlugs.end();
252           ++it )
253     {
254         AvPlug* plug = *it;
255         if ( !plug->discoverConnections() ) {
256             debugError( "Could not discover plug connections\n" );
257             return false;
258         }
259     }
260     for ( AvPlugVector::iterator it = m_externalPlugs.begin();
261           it != m_externalPlugs.end();
262           ++it )
263     {
264         AvPlug* plug = *it;
265         if ( !plug->discoverConnections() ) {
266             debugError( "Could not discover plug connections\n" );
267             return false;
268         }
269     }
270
271     return true;
272 }
273
274 bool
275 AvDevice::discoverSubUnitsPlugConnections()
276 {
277     for ( AvDeviceSubunitVector::iterator it = m_subunits.begin();
278           it != m_subunits.end();
279           ++it )
280     {
281         AvDeviceSubunit* subunit = *it;
282         if ( !subunit->discoverConnections() ) {
283             debugError( "Subunit '%s'  plug connections failed\n",
284                         subunit->getName() );
285             return false;
286         }
287     }
288     return true;
289 }
290
291 bool
292 AvDevice::discoverSyncModes()
293 {
294     // Following possible sync plugs exists:
295     // - Music subunit sync output plug = internal sync (CSP)
296     // - Unit input plug 0 = SYT match
297     // - Unit input plut 1 = Sync stream
298     //
299     // If last sync mode is reported it is mostelikely not
300     // implemented *sic*
301     //
302     // Following sync sources are device specific:
303     // - All unit external input plugs which have a
304     //   sync information (WS, SPDIF, ...)
305
306     // First we have to find the sync input and output plug
307     // in the music subunit.
308
309     // Note PCR input means 1394bus-to-device where as
310     // MSU input means subunit-to-device
311
312     AvPlugVector syncPCRInputPlugs = getPlugsByType( m_pcrPlugs,
313                                                      AvPlug::eAPD_Input,
314                                                      AvPlug::eAPT_Sync );
315     if ( !syncPCRInputPlugs.size() ) {
316         debugWarning( "No PCR sync input plug found\n" );
317     }
318
319     AvPlugVector syncPCROutputPlugs = getPlugsByType( m_pcrPlugs,
320                                                       AvPlug::eAPD_Output,
321                                                       AvPlug::eAPT_Sync );
322     if ( !syncPCROutputPlugs.size() ) {
323         debugWarning( "No PCR sync output plug found\n" );
324     }
325
326     AvPlugVector isoPCRInputPlugs = getPlugsByType( m_pcrPlugs,
327                                                     AvPlug::eAPD_Input,
328                                                     AvPlug::eAPT_IsoStream );
329     if ( !isoPCRInputPlugs.size() ) {
330         debugWarning( "No PCR iso input plug found\n" );
331
332     }
333
334     AvPlugVector isoPCROutputPlugs = getPlugsByType( m_pcrPlugs,
335                                                     AvPlug::eAPD_Output,
336                                                     AvPlug::eAPT_IsoStream );
337     if ( !isoPCROutputPlugs.size() ) {
338         debugWarning( "No PCR iso output plug found\n" );
339
340     }
341
342     AvPlugVector digitalPCRInputPlugs = getPlugsByType( m_externalPlugs,
343                                                     AvPlug::eAPD_Input,
344                                                     AvPlug::eAPT_Digital );
345
346     AvPlugVector syncMSUInputPlugs = m_plugManager.getPlugsByType(
347         AVCCommand::eST_Music,
348         0,
349         0xff,
350         0xff,
351         AvPlug::eAPA_SubunitPlug,
352         AvPlug::eAPD_Input,
353         AvPlug::eAPT_Sync );
354     if ( !syncMSUInputPlugs.size() ) {
355         debugWarning( "No sync input plug for MSU subunit found\n" );
356     }
357
358     AvPlugVector syncMSUOutputPlugs = m_plugManager.getPlugsByType(
359         AVCCommand::eST_Music,
360         0,
361         0xff,
362         0xff,
363         AvPlug::eAPA_SubunitPlug,
364         AvPlug::eAPD_Output,
365         AvPlug::eAPT_Sync );
366     if ( !syncMSUOutputPlugs.size() ) {
367         debugWarning( "No sync output plug for MSU subunit found\n" );
368     }
369
370     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Input Plugs:\n" );
371     showAvPlugs( syncPCRInputPlugs );
372     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Sync Output Plugs:\n" );
373     showAvPlugs( syncPCROutputPlugs );
374     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Input Plugs:\n" );
375     showAvPlugs( isoPCRInputPlugs );
376     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR Iso Output Plugs:\n" );
377     showAvPlugs( isoPCROutputPlugs );
378     debugOutput( DEBUG_LEVEL_VERBOSE, "PCR digital Input Plugs:\n" );
379     showAvPlugs( digitalPCRInputPlugs );
380     debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Input Plugs:\n" );
381     showAvPlugs( syncMSUInputPlugs );
382     debugOutput( DEBUG_LEVEL_VERBOSE, "MSU Sync Output Plugs:\n" );
383     showAvPlugs( syncMSUOutputPlugs );
384
385     // Check all possible PCR input to MSU input connections
386     // -> sync stream input
387     checkSyncConnections( syncPCRInputPlugs, syncMSUInputPlugs );
388
389     // Check all possible MSU output to PCR output connections
390     // -> sync stream output
391     checkSyncConnections( syncMSUOutputPlugs,  syncPCROutputPlugs );
392
393     // Check all PCR iso input to MSU input connections
394     // -> SYT match
395     checkSyncConnections( isoPCRInputPlugs, syncMSUInputPlugs );
396
397     // Check all MSU sync output to MSU input connections
398     // -> CSP
399     checkSyncConnections( syncMSUOutputPlugs, syncMSUInputPlugs );
400
401     // Check all external PCR digital input to MSU input connections
402     // -> SPDIF/ADAT sync
403     checkSyncConnections( digitalPCRInputPlugs, syncMSUInputPlugs );
404
405
406     // Currently active connection signal sourqce cmd, command type
407     // status, source unknown, destination MSU sync input plug
408
409     for ( AvPlugVector::const_iterator it = syncMSUInputPlugs.begin();
410           it != syncMSUInputPlugs.end();
411           ++it )
412     {
413         AvPlug* msuPlug = *it;
414         for ( AvPlugVector::const_iterator jt =
415                   msuPlug->getInputConnections().begin();
416               jt != msuPlug->getInputConnections().end();
417               ++jt )
418         {
419             AvPlug* plug = *jt;
420             plug = plug; // disable compiler warning in release mode
421                          // will be optimized away
422             debugOutput( DEBUG_LEVEL_NORMAL,
423                          "Active Sync Connection: '%s' -> '%s'\n",
424                          msuPlug->getName(),
425                          plug->getName() );
426         }
427     }
428
429     return true;
430 }
431
432 bool
433 AvDevice::enumerateSubUnits()
434 {
435     SubUnitInfoCmd subUnitInfoCmd( m_1394Service );
436     //subUnitInfoCmd.setVerbose( 1 );
437     subUnitInfoCmd.setCommandType( AVCCommand::eCT_Status );
438
439     // BeBoB has always exactly one audio and one music subunit. This
440     // means is fits into the first page of the SubUnitInfo command.
441     // So there is no need to do more than needed
442
443     subUnitInfoCmd.m_page = 0;
444     subUnitInfoCmd.setNodeId( m_nodeId );
445     subUnitInfoCmd.setVerbose( m_verboseLevel );
446     if ( !subUnitInfoCmd.fire() ) {
447         debugError( "Subunit info command failed\n" );
448     }
449
450     for ( int i = 0; i < subUnitInfoCmd.getNrOfValidEntries(); ++i ) {
451         subunit_type_t subunit_type
452             = subUnitInfoCmd.m_table[i].m_subunit_type;
453
454         unsigned int subunitId = getNrOfSubunits( subunit_type );
455
456         debugOutput( DEBUG_LEVEL_VERBOSE,
457                      "subunit_id = %2d, subunit_type = %2d (%s)\n",
458                      subunitId,
459                      subunit_type,
460                      subunitTypeToString( subunit_type ) );
461
462         AvDeviceSubunit* subunit = 0;
463         switch( subunit_type ) {
464         case AVCCommand::eST_Audio:
465             subunit = new AvDeviceSubunitAudio( *this, subunitId,
466                                                 m_verboseLevel );
467             if ( !subunit ) {
468                 debugFatal( "Could not allocate AvDeviceSubunitAudio\n" );
469                 return false;
470             }
471             break;
472         case AVCCommand::eST_Music:
473             subunit = new AvDeviceSubunitMusic( *this, subunitId,
474                                                 m_verboseLevel );
475             if ( !subunit ) {
476                 debugFatal( "Could not allocate AvDeviceSubunitMusic\n" );
477                 return false;
478             }
479             break;
480         default:
481             debugOutput( DEBUG_LEVEL_NORMAL,
482                          "Unsupported subunit found, subunit_type = %d (%s)\n",
483                          subunit_type,
484                          subunitTypeToString( subunit_type ) );
485             continue;
486
487         }
488
489         if ( !subunit->discover() ) {
490             debugError( "enumerateSubUnits: Could not discover "
491                         "subunit_id = %2d, subunit_type = %2d (%s)\n",
492                         subunitId,
493                         subunit_type,
494                         subunitTypeToString( subunit_type ) );
495             delete subunit;
496             return false;
497         }
498         m_subunits.push_back( subunit );
499     }
500
501     return true;
502 }
503
504
505 AvDeviceSubunit*
506 AvDevice::getSubunit( subunit_type_t subunitType,
507                       subunit_id_t subunitId ) const
508 {
509     for ( AvDeviceSubunitVector::const_iterator it = m_subunits.begin();
510           it != m_subunits.end();
511           ++it )
512     {
513         AvDeviceSubunit* subunit = *it;
514         if ( ( subunitType == subunit->getSubunitType() )
515              && ( subunitId == subunit->getSubunitId() ) )
516         {
517             return subunit;
518         }
519     }
520
521     return 0;
522 }
523
524
525 unsigned int
526 AvDevice::getNrOfSubunits( subunit_type_t subunitType ) const
527 {
528     unsigned int nrOfSubunits = 0;
529
530     for ( AvDeviceSubunitVector::const_iterator it = m_subunits.begin();
531           it != m_subunits.end();
532           ++it )
533     {
534         AvDeviceSubunit* subunit = *it;
535         if ( subunitType == subunit->getSubunitType() ) {
536             nrOfSubunits++;
537         }
538     }
539
540     return nrOfSubunits;
541 }
542
543 AvPlugConnection*
544 AvDevice::getPlugConnection( AvPlug& srcPlug ) const
545 {
546     for ( AvPlugConnectionVector::const_iterator it
547               = m_plugConnections.begin();
548           it != m_plugConnections.end();
549           ++it )
550     {
551         AvPlugConnection* plugConnection = *it;
552         if ( &( plugConnection->getSrcPlug() ) == &srcPlug ) {
553             return plugConnection;
554         }
555     }
556
557     return 0;
558 }
559
560 AvPlug*
561 AvDevice::getPlugById( AvPlugVector& plugs,
562                        AvPlug::EAvPlugDirection plugDirection,
563                        int id )
564 {
565     for ( AvPlugVector::iterator it = plugs.begin();
566           it != plugs.end();
567           ++it )
568     {
569         AvPlug* plug = *it;
570         if ( ( id == plug->getPlugId() )
571              && ( plugDirection == plug->getPlugDirection() ) )
572         {
573             return plug;
574         }
575     }
576
577     return 0;
578 }
579
580 AvPlugVector
581 AvDevice::getPlugsByType( AvPlugVector& plugs,
582                           AvPlug::EAvPlugDirection plugDirection,
583                           AvPlug::EAvPlugType type)
584 {
585     AvPlugVector plugVector;
586     for ( AvPlugVector::iterator it = plugs.begin();
587           it != plugs.end();
588           ++it )
589     {
590         AvPlug* plug = *it;
591         if ( ( type == plug->getPlugType() )
592              && ( plugDirection == plug->getPlugDirection() ) )
593         {
594             plugVector.push_back( plug );
595         }
596     }
597
598     return plugVector;
599 }
600
601 AvPlug*
602 AvDevice::getSyncPlug( int maxPlugId, AvPlug::EAvPlugDirection )
603 {
604     return 0;
605 }
606
607 bool
608 AvDevice::setSamplingFrequency( ESamplingFrequency samplingFrequency )
609 {
610
611     AvPlug* plug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Input, 0 );
612     if ( !plug ) {
613         debugError( "setSampleRate: Could not retrieve iso input plug 0\n" );
614         return false;
615     }
616
617     if ( !setSamplingFrequencyPlug( *plug,
618                                     AvPlug::eAPD_Input,
619                                     samplingFrequency ) )
620     {
621         debugError( "setSampleRate: Setting sample rate failed\n" );
622         return false;
623     }
624
625     plug = getPlugById( m_pcrPlugs, AvPlug::eAPD_Output,  0 );
626     if ( !plug ) {
627         debugError( "setSampleRate: Could not retrieve iso output plug 0\n" );
628         return false;
629     }
630
631     if ( !setSamplingFrequencyPlug( *plug,
632                                     AvPlug::eAPD_Output,
633                                     samplingFrequency ) )
634     {
635         debugError( "setSampleRate: Setting sample rate failed\n" );
636         return false;
637     }
638
639
640     debugOutput( DEBUG_LEVEL_VERBOSE,
641                  "setSampleRate: Set sample rate to %d\n",
642                  convertESamplingFrequency( samplingFrequency ) );
643     return true;
644 }
645
646 bool
647 AvDevice::setSamplingFrequencyPlug( AvPlug& plug,
648                                     AvPlug::EAvPlugDirection direction,
649                                     ESamplingFrequency samplingFrequency )
650 {
651
652     ExtendedStreamFormatCmd extStreamFormatCmd(
653         m_1394Service,
654         ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommandList );
655     UnitPlugAddress unitPlugAddress( UnitPlugAddress::ePT_PCR,
656                                      plug.getPlugId() );
657
658     extStreamFormatCmd.setPlugAddress(
659         PlugAddress(
660             AvPlug::convertPlugDirection(direction ),
661             PlugAddress::ePAM_Unit,
662             unitPlugAddress ) );
663
664     extStreamFormatCmd.setNodeId( m_nodeId );
665     extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status );
666
667     int i = 0;
668     bool cmdSuccess = false;
669     bool correctFormatFound = false;
670
671     do {
672         extStreamFormatCmd.setIndexInStreamFormat( i );
673         extStreamFormatCmd.setCommandType( AVCCommand::eCT_Status );
674         extStreamFormatCmd.setVerbose( m_verboseLevel );
675
676         cmdSuccess = extStreamFormatCmd.fire();
677
678         if ( cmdSuccess
679              && ( extStreamFormatCmd.getResponse() ==
680                   AVCCommand::eR_Implemented ) )
681         {
682             ESamplingFrequency foundFreq = eSF_DontCare;
683
684             FormatInformation* formatInfo =
685                 extStreamFormatCmd.getFormatInformation();
686             FormatInformationStreamsCompound* compoundStream
687                 = dynamic_cast< FormatInformationStreamsCompound* > (
688                     formatInfo->m_streams );
689             if ( compoundStream ) {
690                 foundFreq =
691                     static_cast<ESamplingFrequency>(
692                         compoundStream->m_samplingFrequency );
693             }
694
695             FormatInformationStreamsSync* syncStream
696                 = dynamic_cast< FormatInformationStreamsSync* > (
697                     formatInfo->m_streams );
698             if ( syncStream ) {
699                 foundFreq =
700                     static_cast<ESamplingFrequency>(
701                         compoundStream->m_samplingFrequency );
702             }
703
704             if ( foundFreq == samplingFrequency )
705             {
706                 correctFormatFound = true;
707                 break;
708             }
709         }
710
711         ++i;
712     } while ( cmdSuccess
713               && ( extStreamFormatCmd.getResponse() ==
714                    ExtendedStreamFormatCmd::eR_Implemented )
715               && ( extStreamFormatCmd.getStatus() !=
716                    ExtendedStreamFormatCmd::eS_NotUsed ) );
717
718     if ( !cmdSuccess ) {
719         debugError( "setSampleRatePlug: Failed to retrieve format info\n" );
720         return false;
721     }
722
723     if ( !correctFormatFound ) {
724         debugError( "setSampleRatePlug: %s plug %d does not support "
725                     "sample rate %d\n",
726                     plug.getName(),
727                     plug.getPlugId(),
728                     convertESamplingFrequency( samplingFrequency ) );
729         return false;
730     }
731
732     extStreamFormatCmd.setSubFunction(
733         ExtendedStreamFormatCmd::eSF_ExtendedStreamFormatInformationCommand );
734     extStreamFormatCmd.setCommandType( AVCCommand::eCT_Control );
735     extStreamFormatCmd.setVerbose( m_verboseLevel );
736
737     if ( !extStreamFormatCmd.fire() ) {
738         debugError( "setSampleRate: Could not set sample rate %d "
739                     "to %s plug %d\n",
740                     convertESamplingFrequency( samplingFrequency ),
741                     plug.getName(),
742                     plug.getPlugId() );
743         return false;
744     }
745
746     return true;
747 }
748
749 void
750 AvDevice::showDevice() const
751 {
752     m_plugManager.showPlugs();
753 }
754
755 void
756 AvDevice::showAvPlugs( AvPlugVector& plugs ) const
757 {
758     int i = 0;
759     for ( AvPlugVector::const_iterator it = plugs.begin();
760           it != plugs.end();
761           ++it, ++i )
762     {
763         AvPlug* plug = *it;
764         debugOutput( DEBUG_LEVEL_VERBOSE, "Plug %d\n", i );
765         plug->showPlug();
766     }
767 }
768
769 bool
770 AvDevice::checkSyncConnections( AvPlugVector& plhs, AvPlugVector& prhs )
771 {
772     for ( AvPlugVector::iterator plIt = plhs.begin();
773           plIt != plhs.end();
774           ++plIt )
775     {
776         AvPlug* pl = *plIt;
777         for ( AvPlugVector::iterator prIt = prhs.begin();
778               prIt != prhs.end();
779               ++prIt )
780         {
781             AvPlug* pr = *prIt;
782             if ( pl->inquireConnnection( *pr ) ) {
783                 debugOutput( DEBUG_LEVEL_NORMAL,
784                              "Sync connection '%s' -> '%s'\n",
785                              pl->getName(),
786                              pr->getName() );
787             }
788         }
789     }
790     return true;
791 }
792
793 bool AvDevice::setId( unsigned int id) {
794         return true;
795 }
796
797 }
Note: See TracBrowser for help on using the browser.