root/trunk/libffado/src/bebob/bebob_functionblock.cpp

Revision 2803, 14.5 kB (checked in by jwoithe, 2 years ago)

Cosmetic: capitalise "L" in "Linux".

"Linux" is a proper noun so it should start with a capital letter. These
changes are almost all within comments.

This patch was originally proposed by pander on the ffado-devel mailing
list. It has been expanded to cover all similar cases to maintain
consistency throughout the source tree.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Daniel Wagner
3  *
4  * This file is part of FFADO
5  * FFADO = Free FireWire (pro-)audio drivers for Linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "bebob/bebob_functionblock.h"
25 #include "bebob/bebob_avdevice_subunit.h"
26 #include "bebob/bebob_avdevice.h"
27 #include "libieee1394/configrom.h"
28
29 #include "libutil/cmd_serialize.h"
30
31 using namespace AVC;
32
33 namespace BeBoB {
34
35 IMPL_DEBUG_MODULE( FunctionBlock, FunctionBlock, DEBUG_LEVEL_NORMAL );
36
37 FunctionBlock::FunctionBlock(
38     AVC::Subunit& subunit,
39     function_block_type_t type,
40     function_block_type_t subtype,
41     function_block_id_t id,
42     ESpecialPurpose purpose,
43     no_of_input_plugs_t nrOfInputPlugs,
44     no_of_output_plugs_t nrOfOutputPlugs,
45     int verbose )
46     : m_subunit( &subunit )
47     , m_type( type )
48     , m_subtype( subtype )
49     , m_id( id )
50     , m_purpose( purpose )
51     , m_nrOfInputPlugs( nrOfInputPlugs )
52     , m_nrOfOutputPlugs( nrOfOutputPlugs )
53     , m_verbose( verbose )
54 {
55     setDebugLevel( verbose );
56 }
57
58 FunctionBlock::FunctionBlock( const FunctionBlock& rhs )
59     : m_subunit( rhs.m_subunit )
60     , m_type( rhs.m_type )
61     , m_subtype( rhs.m_subtype )
62     , m_id( rhs.m_id )
63     , m_purpose( rhs.m_purpose )
64     , m_nrOfInputPlugs( rhs.m_nrOfInputPlugs )
65     , m_nrOfOutputPlugs( rhs.m_nrOfOutputPlugs )
66     , m_verbose( rhs.m_verbose )
67 {
68 }
69
70 FunctionBlock::FunctionBlock()
71 {
72 }
73
74 FunctionBlock::~FunctionBlock()
75 {
76     for ( PlugVector::iterator it = m_plugs.begin();
77           it != m_plugs.end();
78           ++it )
79     {
80         delete *it;
81     }
82
83 }
84
85 bool
86 FunctionBlock::discover()
87 {
88     debugOutput( DEBUG_LEVEL_NORMAL,
89                  "discover function block %s (nr of input plugs = %d, "
90                  "nr of output plugs = %d)\n",
91                  getName(),
92                  m_nrOfInputPlugs,
93                  m_nrOfOutputPlugs );
94
95     if ( !discoverPlugs( AVC::Plug::eAPD_Input, m_nrOfInputPlugs ) ) {
96         debugError( "Could not discover input plug for '%s'\n",
97                     getName() );
98         return false;
99     }
100
101     if ( !discoverPlugs( AVC::Plug::eAPD_Output, m_nrOfOutputPlugs ) ) {
102         debugError( "Could not discover output plugs for '%s'\n",
103                     getName() );
104         return false;
105     }
106
107     return true;
108 }
109
110 bool
111 FunctionBlock::discoverPlugs( AVC::Plug::EPlugDirection plugDirection,
112                               plug_id_t plugMaxId )
113 {
114     for ( int plugId = 0; plugId < plugMaxId; ++plugId ) {
115         AVC::Plug* plug = new BeBoB::Plug(
116             &m_subunit->getUnit(),
117             m_subunit,
118             m_type,
119             m_id,
120             AVC::Plug::eAPA_FunctionBlockPlug,
121             plugDirection,
122             plugId);
123
124         if ( !plug || !plug->discover() ) {
125             debugError( "plug discovering failed for plug %d\n",
126                         plugId );
127             delete plug;
128             return false;
129         }
130
131         debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n",
132                      plug->getName() );
133         m_plugs.push_back( plug );
134     }
135
136     return true;
137 }
138
139 bool
140 FunctionBlock::discoverConnections()
141 {
142     debugOutput( DEBUG_LEVEL_VERBOSE,
143                  "discover connections function block %s\n",
144                  getName() );
145
146     for ( PlugVector::iterator it = m_plugs.begin();
147           it != m_plugs.end();
148           ++it )
149     {
150         BeBoB::Plug* plug = dynamic_cast<BeBoB::Plug*>(*it);
151         if(!plug) {
152             debugError("BUG: not a bebob plug\n");
153             return false;
154         }
155         if ( !plug->discoverConnections() ) {
156             debugError( "Could not discover plug connections\n" );
157             return false;
158         }
159     }
160     return true;
161 }
162
163 bool
164 FunctionBlock::serialize( std::string basePath, Util::IOSerialize& ser ) const
165 {
166     bool result;
167
168     result  = ser.write( basePath + "m_type", m_type );
169     result &= ser.write( basePath + "m_subtype", m_subtype );
170     result &= ser.write( basePath + "m_id", m_id );
171     result &= ser.write( basePath + "m_purpose", m_purpose );
172     result &= ser.write( basePath + "m_nrOfInputPlugs", m_nrOfInputPlugs );
173     result &= ser.write( basePath + "m_nrOfOutputPlugs", m_nrOfOutputPlugs );
174     result &= serializePlugVector( basePath + "m_plugs", ser, m_plugs );
175
176     return result;
177 }
178
179 FunctionBlock*
180 FunctionBlock::deserialize( std::string basePath,
181                             Util::IODeserialize& deser,
182                             AVC::Unit& unit,
183                             AVC::Subunit& subunit )
184 {
185     bool result;
186     function_block_type_t type;
187     function_block_type_t subtype;
188     FunctionBlock* pFB = 0;
189
190     if ( !deser.isExisting( basePath + "m_type" ) ) {
191         return 0;
192     }
193
194     result  = deser.read( basePath + "m_type", type );
195     result &= deser.read( basePath + "m_subtype", subtype );
196     if ( !result ) {
197         return 0;
198     }
199
200     switch ( type ) {
201     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitSelector:
202         pFB = new FunctionBlockSelector;
203         break;
204     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitFeature:
205         pFB = new FunctionBlockFeature;
206         break;
207     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitProcessing:
208         if ( subtype == ExtendedSubunitInfoCmd::ePT_EnhancedMixer ) {
209             pFB = new FunctionBlockEnhancedMixer;
210         } else {
211             pFB = new FunctionBlockProcessing;
212         }
213         break;
214     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitCodec:
215         pFB = new FunctionBlockCodec;
216         break;
217     default:
218         pFB = 0;
219     }
220
221     if ( !pFB ) {
222         return 0;
223     }
224
225     pFB->m_subunit = &subunit;
226     pFB->m_type = type;
227     pFB->m_subtype = subtype;
228
229     result &= deser.read( basePath + "m_id", pFB->m_id );
230     result &= deser.read( basePath + "m_purpose", pFB->m_purpose );
231     result &= deser.read( basePath + "m_nrOfInputPlugs", pFB->m_nrOfInputPlugs );
232     result &= deser.read( basePath + "m_nrOfOutputPlugs", pFB->m_nrOfOutputPlugs );
233
234     if ( !result ) {
235         delete pFB;
236         return 0;
237     }
238
239     return pFB;
240 }
241
242 bool
243 FunctionBlock::deserializeUpdate( std::string basePath,
244                                   Util::IODeserialize& deser )
245 {
246     bool result;
247
248     result = deserializePlugVector( basePath + "m_plugs", deser,
249                                     m_subunit->getUnit().getPlugManager(), m_plugs );
250     return result;
251 }
252
253 ///////////////////////
254
255 FunctionBlockSelector::FunctionBlockSelector(
256     AVC::Subunit& subunit,
257     function_block_id_t id,
258     ESpecialPurpose purpose,
259     no_of_input_plugs_t nrOfInputPlugs,
260     no_of_output_plugs_t nrOfOutputPlugs,
261     int verbose )
262     : FunctionBlock( subunit,
263                      eFBT_AudioSubunitSelector,
264                      0,
265                      id,
266                      purpose,
267                      nrOfInputPlugs,
268                      nrOfOutputPlugs,
269                      verbose )
270 {
271 }
272
273 FunctionBlockSelector::FunctionBlockSelector(
274     const FunctionBlockSelector& rhs )
275     : FunctionBlock( rhs )
276 {
277 }
278
279 FunctionBlockSelector::FunctionBlockSelector()
280     : FunctionBlock()
281 {
282 }
283
284 FunctionBlockSelector::~FunctionBlockSelector()
285 {
286 }
287
288 const char*
289 FunctionBlockSelector::getName()
290 {
291     return "Selector";
292 }
293
294 bool
295 FunctionBlockSelector::serializeChild( std::string basePath,
296                                        Util::IOSerialize& ser ) const
297 {
298     return true;
299 }
300
301 bool
302 FunctionBlockSelector::deserializeChild( std::string basePath,
303                                          Util::IODeserialize& deser,
304                                          AvDevice& unit )
305 {
306     return true;
307 }
308
309 ///////////////////////
310
311 FunctionBlockFeature::FunctionBlockFeature(
312     AVC::Subunit& subunit,
313     function_block_id_t id,
314     ESpecialPurpose purpose,
315     no_of_input_plugs_t nrOfInputPlugs,
316     no_of_output_plugs_t nrOfOutputPlugs,
317     int verbose )
318     : FunctionBlock( subunit,
319                      eFBT_AudioSubunitFeature,
320                      0,
321                      id,
322                      purpose,
323                      nrOfInputPlugs,
324                      nrOfOutputPlugs,
325                      verbose )
326 {
327 }
328
329 FunctionBlockFeature::FunctionBlockFeature(
330     const FunctionBlockFeature& rhs )
331     : FunctionBlock( rhs )
332 {
333 }
334
335 FunctionBlockFeature::FunctionBlockFeature()
336     : FunctionBlock()
337 {
338 }
339
340 FunctionBlockFeature::~FunctionBlockFeature()
341 {
342 }
343
344 const char*
345 FunctionBlockFeature::getName()
346 {
347     return "Feature";
348 }
349
350 bool
351 FunctionBlockFeature::serializeChild( std::string basePath,
352                                       Util::IOSerialize& ser ) const
353 {
354     return true;
355 }
356
357 bool
358 FunctionBlockFeature::deserializeChild( std::string basePath,
359                                         Util::IODeserialize& deser,
360                                         AvDevice& unit )
361 {
362     return true;
363 }
364
365 ///////////////////////
366
367 FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer(
368     AVC::Subunit& subunit,
369     function_block_id_t id,
370     ESpecialPurpose purpose,
371     no_of_input_plugs_t nrOfInputPlugs,
372     no_of_output_plugs_t nrOfOutputPlugs,
373     int verbose )
374     : FunctionBlock( subunit,
375                      eFBT_AudioSubunitProcessing,
376                      ExtendedSubunitInfoCmd::ePT_EnhancedMixer,
377                      id,
378                      purpose,
379                      nrOfInputPlugs,
380                      nrOfOutputPlugs,
381                      verbose )
382 {
383 }
384
385 FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer(
386     const FunctionBlockEnhancedMixer& rhs )
387     : FunctionBlock( rhs )
388 {
389 }
390
391 FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer()
392     : FunctionBlock()
393 {
394 }
395
396 FunctionBlockEnhancedMixer::~FunctionBlockEnhancedMixer()
397 {
398 }
399
400 bool
401 FunctionBlockEnhancedMixer::discover()
402 {
403     if (!FunctionBlock::discover())
404         return false;
405
406     /*
407      * Disable discovering of enhanced mixer because all
408      * device out there do not use, and all implementations
409      * are buggy. So there is no point to use it.
410      * All 'mixer' functions are implemented with selector function blocks
411 */
412     AVC::FunctionBlockCmd fbCmd( m_subunit->getUnit().get1394Service(),
413                                  FunctionBlockCmd::eFBT_Processing,
414                                  m_id,
415                                  FunctionBlockCmd::eCA_Current);
416     fbCmd.setNodeId( m_subunit->getUnit().getConfigRom().getNodeId() );
417     fbCmd.setSubunitId( 0x00 );
418     fbCmd.setCommandType( AVCCommand::eCT_Status );
419     // fbCmd.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE );
420
421     // Ok, this enhanced  mixer setting here is just a hack, we need
422     // a sane way to set processing features (read pointer management)
423     AVC::FunctionBlockProcessingEnhancedMixer em;
424     delete fbCmd.m_pFBProcessing->m_pMixer;
425     fbCmd.m_pFBProcessing->m_pMixer = 0;
426     fbCmd.m_pFBProcessing->m_pEnhancedMixer = em.clone();
427
428     fbCmd.m_pFBProcessing->m_inputAudioChannelNumber = 0xff;
429     fbCmd.m_pFBProcessing->m_outputAudioChannelNumber = 0xff;
430    
431     if ( !fbCmd.fire() ) {
432         debugError( "cmd failed\n" );
433         return false;
434     }
435    
436     //     if ( getDebugLevel() >= DEBUG_LEVEL_NORMAL ) {
437     //         Util::Cmd::CoutSerializer se;
438     //         fbCmd.serialize( se );
439     //     }
440
441     if((fbCmd.getResponse() != AVCCommand::eR_Implemented)) {
442         debugWarning("fbCmd.getResponse() != AVCCommand::eR_Implemented\n");
443     }
444    
445     return true;
446 }
447
448
449 const char*
450 FunctionBlockEnhancedMixer::getName()
451 {
452     return "EnhancedMixer";
453 }
454
455 bool
456 FunctionBlockEnhancedMixer::serializeChild( std::string basePath,
457                                             Util::IOSerialize& ser ) const
458 {
459     return true;
460 }
461
462 bool
463 FunctionBlockEnhancedMixer::deserializeChild( std::string basePath,
464                                               Util::IODeserialize& deser,
465                                               AvDevice& unit )
466 {
467     return true;
468 }
469
470 ///////////////////////
471
472 FunctionBlockProcessing::FunctionBlockProcessing(
473     AVC::Subunit& subunit,
474     function_block_id_t id,
475     ESpecialPurpose purpose,
476     no_of_input_plugs_t nrOfInputPlugs,
477     no_of_output_plugs_t nrOfOutputPlugs,
478     int verbose )
479     : FunctionBlock( subunit,
480                      eFBT_AudioSubunitProcessing,
481                      0,
482                      id,
483                      purpose,
484                      nrOfInputPlugs,
485                      nrOfOutputPlugs,
486                      verbose )
487 {
488 }
489
490 FunctionBlockProcessing::FunctionBlockProcessing(
491     const FunctionBlockProcessing& rhs )
492     : FunctionBlock( rhs )
493 {
494 }
495
496 FunctionBlockProcessing::FunctionBlockProcessing()
497     : FunctionBlock()
498 {
499 }
500
501 FunctionBlockProcessing::~FunctionBlockProcessing()
502 {
503 }
504
505 const char*
506 FunctionBlockProcessing::getName()
507 {
508     return "Dummy Processing";
509 }
510
511 bool
512 FunctionBlockProcessing::serializeChild( std::string basePath,
513                                          Util::IOSerialize& ser ) const
514 {
515     return true;
516 }
517
518 bool
519 FunctionBlockProcessing::deserializeChild( std::string basePath,
520                                            Util::IODeserialize& deser,
521                                            AvDevice& unit )
522 {
523     return true;
524 }
525
526 ///////////////////////
527
528 FunctionBlockCodec::FunctionBlockCodec(
529     AVC::Subunit& subunit,
530     function_block_id_t id,
531     ESpecialPurpose purpose,
532     no_of_input_plugs_t nrOfInputPlugs,
533     no_of_output_plugs_t nrOfOutputPlugs,
534     int verbose )
535     : FunctionBlock( subunit,
536                      eFBT_AudioSubunitCodec,
537                      0,
538                      id,
539                      purpose,
540                      nrOfInputPlugs,
541                      nrOfOutputPlugs,
542                      verbose )
543 {
544 }
545
546 FunctionBlockCodec::FunctionBlockCodec( const FunctionBlockCodec& rhs )
547     : FunctionBlock( rhs )
548 {
549 }
550
551 FunctionBlockCodec::FunctionBlockCodec()
552     : FunctionBlock()
553 {
554 }
555
556 FunctionBlockCodec::~FunctionBlockCodec()
557 {
558 }
559
560 const char*
561 FunctionBlockCodec::getName()
562 {
563     return "Dummy Codec";
564 }
565
566 bool
567 FunctionBlockCodec::serializeChild( std::string basePath,
568                                     Util::IOSerialize& ser ) const
569 {
570     return true;
571 }
572
573 bool
574 FunctionBlockCodec::deserializeChild( std::string basePath,
575                                       Util::IODeserialize& deser,
576                                       AvDevice& unit )
577 {
578     return true;
579 }
580
581 }
Note: See TracBrowser for help on using the browser.