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

Revision 413, 14.3 kB (checked in by pieterpalmers, 16 years ago)

- moved all generic IEEE1394 classes into libieee1394

src/libieee1394/ieee1394service.h
src/libieee1394/csr1212.h
src/libieee1394/configrom.cpp
src/libieee1394/configrom.h
src/libieee1394/ieee1394service.cpp
src/libieee1394/csr1212.c

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