root/branches/echoaudio/src/bebob/bebob_functionblock.cpp

Revision 503, 14.3 kB (checked in by ppalmers, 16 years ago)

- put all libavc stuff into it's own name namespace (AVC)

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