root/branches/streaming-rework/src/bebob/bebob_functionblock.cpp

Revision 407, 14.3 kB (checked in by pieterpalmers, 17 years ago)

- Changed the way the device class configure options are handled. Now they are handled in the makefiles instead of the source files. The only source file that still contains the #ifdef's is devicemanager.cpp, to conditionally include the device class include files and to conditionally probe the classes that might be supported.
- added a configure option to disable the compilation of the test programs in tests/
- cleaned up the ADMTP transmit streamprocessor. Now it sends silenced packets when in the disabled state, instead of no-data packets
- added a getNodeID() to ieee1394service
- made comments in ieee1394service.h doxygen compliant

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