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

Revision 516, 14.5 kB (checked in by wagi, 15 years ago)

- some de/serialing bugs found and fixed
- caching enabled for bebob devices

(finally online again! big thanks to my free wireless internet provider. s/he is finally back from
her/his holiday :)

Line 
1 /*
2  * Copyright (C) 2005-2007 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 library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
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 IMPL_DEBUG_MODULE( BeBoB::FunctionBlock, BeBoB::FunctionBlock, DEBUG_LEVEL_NORMAL );
30
31 BeBoB::FunctionBlock::FunctionBlock(
32     AvDeviceSubunit& subunit,
33     function_block_type_t type,
34     function_block_type_t subtype,
35     function_block_id_t id,
36     ESpecialPurpose purpose,
37     no_of_input_plugs_t nrOfInputPlugs,
38     no_of_output_plugs_t nrOfOutputPlugs,
39     int verbose )
40     : m_subunit( &subunit )
41     , m_type( type )
42     , m_subtype( subtype )
43     , m_id( id )
44     , m_purpose( purpose )
45     , m_nrOfInputPlugs( nrOfInputPlugs )
46     , m_nrOfOutputPlugs( nrOfOutputPlugs )
47     , m_verbose( verbose )
48 {
49     setDebugLevel( verbose );
50 }
51
52 BeBoB::FunctionBlock::FunctionBlock( const FunctionBlock& rhs )
53     : m_subunit( rhs.m_subunit )
54     , m_type( rhs.m_type )
55     , m_subtype( rhs.m_subtype )
56     , m_id( rhs.m_id )
57     , m_purpose( rhs.m_purpose )
58     , m_nrOfInputPlugs( rhs.m_nrOfInputPlugs )
59     , m_nrOfOutputPlugs( rhs.m_nrOfOutputPlugs )
60     , m_verbose( rhs.m_verbose )
61 {
62 }
63
64 BeBoB::FunctionBlock::FunctionBlock()
65 {
66 }
67
68 BeBoB::FunctionBlock::~FunctionBlock()
69 {
70     for ( AvPlugVector::iterator it = m_plugs.begin();
71           it != m_plugs.end();
72           ++it )
73     {
74         delete *it;
75     }
76
77 }
78
79 bool
80 BeBoB::FunctionBlock::discover()
81 {
82     debugOutput( DEBUG_LEVEL_NORMAL,
83                  "discover function block %s (nr of input plugs = %d, "
84                  "nr of output plugs = %d)\n",
85                  getName(),
86                  m_nrOfInputPlugs,
87                  m_nrOfOutputPlugs );
88
89     if ( !discoverPlugs( AvPlug::eAPD_Input, m_nrOfInputPlugs ) ) {
90         debugError( "Could not discover input plug for '%s'\n",
91                     getName() );
92         return false;
93     }
94
95     if ( !discoverPlugs( AvPlug::eAPD_Output, m_nrOfOutputPlugs ) ) {
96         debugError( "Could not discover output plugs for '%s'\n",
97                     getName() );
98         return false;
99     }
100
101     return true;
102 }
103
104 bool
105 BeBoB::FunctionBlock::discoverPlugs( AvPlug::EAvPlugDirection plugDirection,
106                                      plug_id_t plugMaxId )
107 {
108     for ( int plugId = 0; plugId < plugMaxId; ++plugId ) {
109         AvPlug* plug = new AvPlug(
110             m_subunit->getAvDevice().get1394Service(),
111             m_subunit->getAvDevice().getConfigRom(),
112             m_subunit->getAvDevice().getPlugManager(),
113             m_subunit->getSubunitType(),
114             m_subunit->getSubunitId(),
115             m_type,
116             m_id,
117             AvPlug::eAPA_FunctionBlockPlug,
118             plugDirection,
119             plugId,
120             m_verbose );
121
122         if ( !plug || !plug->discover() ) {
123             debugError( "plug discovering failed for plug %d\n",
124                         plugId );
125             delete plug;
126             return false;
127         }
128
129         debugOutput( DEBUG_LEVEL_NORMAL, "plug '%s' found\n",
130                      plug->getName() );
131         m_plugs.push_back( plug );
132     }
133
134     return true;
135 }
136
137 bool
138 BeBoB::FunctionBlock::discoverConnections()
139 {
140     debugOutput( DEBUG_LEVEL_VERBOSE,
141                  "discover connections function block %s\n",
142                  getName() );
143
144     for ( AvPlugVector::iterator it = m_plugs.begin();
145           it != m_plugs.end();
146           ++it )
147     {
148         AvPlug* plug = *it;
149         if ( !plug->discoverConnections() ) {
150             debugError( "Could not discover plug connections\n" );
151             return false;
152         }
153     }
154     return true;
155 }
156
157 bool
158 serializeAvPlugVector( Glib::ustring basePath,
159                        Util::IOSerialize& ser,
160                        const BeBoB::AvPlugVector& vec )
161 {
162     bool result = true;
163     int i = 0;
164     for ( BeBoB::AvPlugVector::const_iterator it = vec.begin();
165           it != vec.end();
166           ++it )
167     {
168         std::ostringstream strstrm;
169         strstrm << basePath << i;
170         result &= ser.write( strstrm.str(), ( *it )->getGlobalId() );
171         i++;
172     }
173     return result;
174 }
175
176 bool
177 deserializeAvPlugVector( Glib::ustring basePath,
178                          Util::IODeserialize& deser,
179                          BeBoB::AvDevice& avDevice,
180                          BeBoB::AvPlugVector& vec )
181 {
182     int i = 0;
183     bool bFinished = false;
184     bool result = true;
185     do {
186         plug_id_t plugId;
187         std::ostringstream strstrm;
188         strstrm << basePath << i;
189
190         if ( deser.isExisting( strstrm.str() ) ) {
191             result &= deser.read( strstrm.str(), plugId );
192             BeBoB::AvPlug* pPlug = avDevice.getPlugManager().getPlug( plugId );
193
194             if ( result && pPlug ) {
195                 vec.push_back( pPlug );
196                 i++;
197             } else {
198                 bFinished = true;
199             }
200         } else {
201             bFinished = true;
202         }
203     } while ( !bFinished );
204
205     return result;
206 }
207
208 bool
209 BeBoB::FunctionBlock::serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const
210 {
211     bool result;
212
213     result  = ser.write( basePath + "m_type", m_type );
214     result &= ser.write( basePath + "m_subtype", m_subtype );
215     result &= ser.write( basePath + "m_id", m_id );
216     result &= ser.write( basePath + "m_purpose", m_purpose );
217     result &= ser.write( basePath + "m_nrOfInputPlugs", m_nrOfInputPlugs );
218     result &= ser.write( basePath + "m_nrOfOutputPlugs", m_nrOfOutputPlugs );
219     result &= ser.write( basePath + "m_verbose", m_verbose );
220     result &= serializeAvPlugVector( basePath + "m_plugs", ser, m_plugs );
221
222     return result;
223 }
224
225 BeBoB::FunctionBlock*
226 BeBoB::FunctionBlock::deserialize( Glib::ustring basePath,
227                                    Util::IODeserialize& deser,
228                                    AvDevice& avDevice,
229                                    AvDeviceSubunit& subunit )
230 {
231     bool result;
232     function_block_type_t type;
233     function_block_type_t subtype;
234     FunctionBlock* pFB = 0;
235
236     result  = deser.read( basePath + "m_type", type );
237     result &= deser.read( basePath + "m_subtype", subtype );
238     if ( !result ) {
239         return 0;
240     }
241
242     switch ( type ) {
243     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitSelector:
244         pFB = new FunctionBlockSelector;
245         break;
246     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitFeature:
247         pFB = new FunctionBlockFeature;
248         break;
249     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitProcessing:
250         if ( subtype == ExtendedSubunitInfoCmd::ePT_EnhancedMixer ) {
251             pFB = new FunctionBlockEnhancedMixer;
252         } else {
253             pFB = new FunctionBlockProcessing;
254         }
255         break;
256     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitCodec:
257         pFB = new FunctionBlockCodec;
258         break;
259     default:
260         pFB = 0;
261     }
262
263     if ( !pFB ) {
264         return 0;
265     }
266
267     pFB->m_subunit = &subunit;
268     pFB->m_type = type;
269     pFB->m_subtype = subtype;
270
271     result &= deser.read( basePath + "m_id", pFB->m_id );
272     result &= deser.read( basePath + "m_purpose", pFB->m_purpose );
273     result &= deser.read( basePath + "m_nrOfInputPlugs", pFB->m_nrOfInputPlugs );
274     result &= deser.read( basePath + "m_nrOfOutputPlugs", pFB->m_nrOfOutputPlugs );
275     result &= deser.read( basePath + "m_verbose", pFB->m_verbose );
276     result &= deserializeAvPlugVector( basePath + "m_plugs", deser, avDevice, pFB->m_plugs );
277
278     return 0;
279 }
280
281 ///////////////////////
282
283 BeBoB::FunctionBlockSelector::FunctionBlockSelector(
284     AvDeviceSubunit& subunit,
285     function_block_id_t id,
286     ESpecialPurpose purpose,
287     no_of_input_plugs_t nrOfInputPlugs,
288     no_of_output_plugs_t nrOfOutputPlugs,
289     int verbose )
290     : FunctionBlock( subunit,
291                      eFBT_AudioSubunitSelector,
292                      0,
293                      id,
294                      purpose,
295                      nrOfInputPlugs,
296                      nrOfOutputPlugs,
297                      verbose )
298 {
299 }
300
301 BeBoB::FunctionBlockSelector::FunctionBlockSelector(
302     const FunctionBlockSelector& rhs )
303     : FunctionBlock( rhs )
304 {
305 }
306
307 BeBoB::FunctionBlockSelector::FunctionBlockSelector()
308     : FunctionBlock()
309 {
310 }
311
312 BeBoB::FunctionBlockSelector::~FunctionBlockSelector()
313 {
314 }
315
316 const char*
317 BeBoB::FunctionBlockSelector::getName()
318 {
319     return "Selector";
320 }
321
322 bool
323 BeBoB::FunctionBlockSelector::serializeChild( Glib::ustring basePath,
324                                               Util::IOSerialize& ser ) const
325 {
326     return true;
327 }
328
329 bool
330 BeBoB::FunctionBlockSelector::deserializeChild( Glib::ustring basePath,
331                                                 Util::IODeserialize& deser,
332                                                 AvDevice& avDevice )
333 {
334     return true;
335 }
336
337 ///////////////////////
338
339 BeBoB::FunctionBlockFeature::FunctionBlockFeature(
340     AvDeviceSubunit& subunit,
341     function_block_id_t id,
342     ESpecialPurpose purpose,
343     no_of_input_plugs_t nrOfInputPlugs,
344     no_of_output_plugs_t nrOfOutputPlugs,
345     int verbose )
346     : FunctionBlock( subunit,
347                      eFBT_AudioSubunitFeature,
348                      0,
349                      id,
350                      purpose,
351                      nrOfInputPlugs,
352                      nrOfOutputPlugs,
353                      verbose )
354 {
355 }
356
357 BeBoB::FunctionBlockFeature::FunctionBlockFeature(
358     const FunctionBlockFeature& rhs )
359     : FunctionBlock( rhs )
360 {
361 }
362
363 BeBoB::FunctionBlockFeature::FunctionBlockFeature()
364     : FunctionBlock()
365 {
366 }
367
368 BeBoB::FunctionBlockFeature::~FunctionBlockFeature()
369 {
370 }
371
372 const char*
373 BeBoB::FunctionBlockFeature::getName()
374 {
375     return "Feature";
376 }
377
378 bool
379 BeBoB::FunctionBlockFeature::serializeChild( Glib::ustring basePath,
380                                              Util::IOSerialize& ser ) const
381 {
382     return true;
383 }
384
385 bool
386 BeBoB::FunctionBlockFeature::deserializeChild( Glib::ustring basePath,
387                                                Util::IODeserialize& deser,
388                                                AvDevice& avDevice )
389 {
390     return true;
391 }
392
393 ///////////////////////
394
395 BeBoB::FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer(
396     AvDeviceSubunit& subunit,
397     function_block_id_t id,
398     ESpecialPurpose purpose,
399     no_of_input_plugs_t nrOfInputPlugs,
400     no_of_output_plugs_t nrOfOutputPlugs,
401     int verbose )
402     : FunctionBlock( subunit,
403                      eFBT_AudioSubunitProcessing,
404                      ExtendedSubunitInfoCmd::ePT_EnhancedMixer,
405                      id,
406                      purpose,
407                      nrOfInputPlugs,
408                      nrOfOutputPlugs,
409                      verbose )
410 {
411 }
412
413 BeBoB::FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer(
414     const FunctionBlockEnhancedMixer& rhs )
415     : FunctionBlock( rhs )
416 {
417 }
418
419 BeBoB::FunctionBlockEnhancedMixer::FunctionBlockEnhancedMixer()
420     : FunctionBlock()
421 {
422 }
423
424 BeBoB::FunctionBlockEnhancedMixer::~FunctionBlockEnhancedMixer()
425 {
426 }
427
428 const char*
429 BeBoB::FunctionBlockEnhancedMixer::getName()
430 {
431     return "EnhancedMixer";
432 }
433
434 bool
435 BeBoB::FunctionBlockEnhancedMixer::serializeChild( Glib::ustring basePath,
436                                                    Util::IOSerialize& ser ) const
437 {
438     return true;
439 }
440
441 bool
442 BeBoB::FunctionBlockEnhancedMixer::deserializeChild( Glib::ustring basePath,
443                                                      Util::IODeserialize& deser,
444                                                      AvDevice& avDevice )
445 {
446     return true;
447 }
448
449 ///////////////////////
450
451 BeBoB::FunctionBlockProcessing::FunctionBlockProcessing(
452     AvDeviceSubunit& subunit,
453     function_block_id_t id,
454     ESpecialPurpose purpose,
455     no_of_input_plugs_t nrOfInputPlugs,
456     no_of_output_plugs_t nrOfOutputPlugs,
457     int verbose )
458     : FunctionBlock( subunit,
459                      eFBT_AudioSubunitProcessing,
460                      0,
461                      id,
462                      purpose,
463                      nrOfInputPlugs,
464                      nrOfOutputPlugs,
465                      verbose )
466 {
467 }
468
469 BeBoB::FunctionBlockProcessing::FunctionBlockProcessing(
470     const FunctionBlockProcessing& rhs )
471     : FunctionBlock( rhs )
472 {
473 }
474
475 BeBoB::FunctionBlockProcessing::FunctionBlockProcessing()
476     : FunctionBlock()
477 {
478 }
479
480 BeBoB::FunctionBlockProcessing::~FunctionBlockProcessing()
481 {
482 }
483
484 const char*
485 BeBoB::FunctionBlockProcessing::getName()
486 {
487     return "Dummy Processing";
488 }
489
490 bool
491 BeBoB::FunctionBlockProcessing::serializeChild( Glib::ustring basePath,
492                                                 Util::IOSerialize& ser ) const
493 {
494     return true;
495 }
496
497 bool
498 BeBoB::FunctionBlockProcessing::deserializeChild( Glib::ustring basePath,
499                                                   Util::IODeserialize& deser,
500                                                   AvDevice& avDevice )
501 {
502     return true;
503 }
504
505 ///////////////////////
506
507 BeBoB::FunctionBlockCodec::FunctionBlockCodec(
508     AvDeviceSubunit& subunit,
509     function_block_id_t id,
510     ESpecialPurpose purpose,
511     no_of_input_plugs_t nrOfInputPlugs,
512     no_of_output_plugs_t nrOfOutputPlugs,
513     int verbose )
514     : FunctionBlock( subunit,
515                      eFBT_AudioSubunitCodec,
516                      0,
517                      id,
518                      purpose,
519                      nrOfInputPlugs,
520                      nrOfOutputPlugs,
521                      verbose )
522 {
523 }
524
525 BeBoB::FunctionBlockCodec::FunctionBlockCodec( const FunctionBlockCodec& rhs )
526     : FunctionBlock( rhs )
527 {
528 }
529
530 BeBoB::FunctionBlockCodec::FunctionBlockCodec()
531     : FunctionBlock()
532 {
533 }
534
535 BeBoB::FunctionBlockCodec::~FunctionBlockCodec()
536 {
537 }
538
539 const char*
540 BeBoB::FunctionBlockCodec::getName()
541 {
542     return "Dummy Codec";
543 }
544
545 bool
546 BeBoB::FunctionBlockCodec::serializeChild( Glib::ustring basePath,
547                                            Util::IOSerialize& ser ) const
548 {
549     return true;
550 }
551
552 bool
553 BeBoB::FunctionBlockCodec::deserializeChild( Glib::ustring basePath,
554                                              Util::IODeserialize& deser,
555                                              AvDevice& avDevice )
556 {
557     return true;
558 }
Note: See TracBrowser for help on using the browser.