root/branches/libfreebob-2.0/src/libfreebobavc/avc_function_block.cpp

Revision 336, 15.2 kB (checked in by pieterpalmers, 17 years ago)

- Merged the developments on trunk since branch-off:

branch occurred at rev 194
svn merge -r 194:HEAD https://svn.sourceforge.net/svnroot/freebob/trunk/libfreebob

- Modified libfreebobavc to use the messagebuffer for debug info.
- This should compile and run

Line 
1 /* avc_function_block.cpp
2  * Copyright (C) 2006 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
21 #include "avc_function_block.h"
22 #include "serialize.h"
23 #include "ieee1394service.h"
24
25
26 /////////////////////////////////
27
28 FunctionBlockFeatureVolume::FunctionBlockFeatureVolume()
29     : IBusData()
30     , m_controlSelector( FunctionBlockFeature::eCSE_Feature_Volume )
31     , m_controlDataLength( 2 )
32     , m_volume( 0 )
33 {
34 }
35
36 FunctionBlockFeatureVolume::FunctionBlockFeatureVolume( const FunctionBlockFeatureVolume& rhs )
37     : m_controlSelector( rhs.m_controlSelector )
38     , m_controlDataLength( rhs.m_controlDataLength )
39     , m_volume( rhs.m_volume )
40 {
41 }
42
43 FunctionBlockFeatureVolume::~FunctionBlockFeatureVolume()
44 {
45 }
46
47 bool
48 FunctionBlockFeatureVolume::serialize( IOSSerialize& se )
49 {
50     bool bStatus;
51     byte_t val;
52     bStatus = se.write( m_controlSelector,    "FunctionBlockFeatureVolume controlSelector" );
53     bStatus &= se.write( m_controlDataLength,  "FunctionBlockFeatureVolume controlDataLength" );
54     val = (byte_t)(m_volume >> 8);
55     bStatus &= se.write( val,                  "FunctionBlockFeatureVolume volume high" );
56     val = m_volume & 0xff;
57     bStatus &= se.write( val,                  "FunctionBlockFeatureVolume volume low" );
58
59     return bStatus;
60 }
61
62 bool
63 FunctionBlockFeatureVolume::deserialize( IISDeserialize& de )
64 {
65     bool bStatus;
66     byte_t val;
67     bStatus = de.read( &m_controlSelector );
68     bStatus &= de.read( &m_controlDataLength );
69     bStatus &= de.read( &val );
70     m_volume = val << 8;
71     bStatus &= de.read( &val );
72     m_volume |= val;
73
74     return bStatus;
75 }
76
77 FunctionBlockFeatureVolume*
78 FunctionBlockFeatureVolume::clone() const
79 {
80     return new FunctionBlockFeatureVolume( *this );
81 }
82
83 /////////////////////////////////
84
85 FunctionBlockProcessingMixer::FunctionBlockProcessingMixer()
86     : IBusData()
87     , m_controlSelector( FunctionBlockProcessing::eCSE_Processing_Mixer )
88 {
89 }
90
91 FunctionBlockProcessingMixer::FunctionBlockProcessingMixer( const FunctionBlockProcessingMixer& rhs )
92     : m_controlSelector( rhs.m_controlSelector )
93 {
94 }
95
96 FunctionBlockProcessingMixer::~FunctionBlockProcessingMixer()
97 {
98 }
99
100 bool
101 FunctionBlockProcessingMixer::serialize( IOSSerialize& se )
102 {
103     bool bStatus;
104     bStatus = se.write( m_controlSelector,    "FunctionBlockProcessingMixer controlSelector" );
105
106     return bStatus;
107 }
108
109 bool
110 FunctionBlockProcessingMixer::deserialize( IISDeserialize& de )
111 {
112     bool bStatus;
113     bStatus = de.read( &m_controlSelector );
114
115     return bStatus;
116 }
117
118 FunctionBlockProcessingMixer*
119 FunctionBlockProcessingMixer::clone() const
120 {
121     return new FunctionBlockProcessingMixer( *this );
122 }
123
124 /////////////////////////////////
125
126 FunctionBlockProcessingEnhancedMixer::FunctionBlockProcessingEnhancedMixer()
127     : IBusData()
128     , m_controlSelector( FunctionBlockProcessing::eCSE_Processing_EnhancedMixer )
129     , m_statusSelector( eSS_ProgramableState )
130 {
131 }
132
133 FunctionBlockProcessingEnhancedMixer::FunctionBlockProcessingEnhancedMixer(
134     const FunctionBlockProcessingEnhancedMixer& rhs )
135     : m_controlSelector( rhs.m_controlSelector )
136     , m_statusSelector( rhs.m_statusSelector )
137 {
138 }
139
140 FunctionBlockProcessingEnhancedMixer::~FunctionBlockProcessingEnhancedMixer()
141 {
142 }
143
144 bool
145 FunctionBlockProcessingEnhancedMixer::serialize( IOSSerialize& se )
146 {
147     bool bStatus;
148     bStatus  = se.write( m_controlSelector, "FunctionBlockProcessingEnhancedMixer controlSelector" );
149     bStatus &= se.write( m_statusSelector,  "FunctionBlockProcessingEnhancedMixer statusSelector" );
150
151     return bStatus;
152 }
153
154 bool
155 FunctionBlockProcessingEnhancedMixer::deserialize( IISDeserialize& de )
156 {
157     bool bStatus;
158     bStatus  = de.read( &m_controlSelector );
159     bStatus &= de.read( &m_statusSelector );
160
161     return bStatus;
162 }
163
164 FunctionBlockProcessingEnhancedMixer*
165 FunctionBlockProcessingEnhancedMixer::clone() const
166 {
167     return new FunctionBlockProcessingEnhancedMixer( *this );
168 }
169
170
171 /////////////////////////////////
172 /////////////////////////////////
173
174 FunctionBlockSelector::FunctionBlockSelector()
175     : IBusData()
176     , m_selectorLength( 0x02 )
177     , m_inputFbPlugNumber( 0x00 )
178     , m_controlSelector( eCSE_Selector_Selector )
179 {
180 }
181
182 FunctionBlockSelector::FunctionBlockSelector( const FunctionBlockSelector& rhs )
183     : IBusData()
184     , m_selectorLength( rhs.m_selectorLength )
185     , m_inputFbPlugNumber( rhs.m_inputFbPlugNumber )
186     , m_controlSelector( rhs.m_controlSelector )
187 {
188 }
189
190 FunctionBlockSelector::~FunctionBlockSelector()
191 {
192 }
193
194 bool
195 FunctionBlockSelector::serialize( IOSSerialize& se )
196 {
197     bool bStatus;
198     bStatus  = se.write( m_selectorLength,    "FunctionBlockSelector selectorLength" );
199     bStatus &= se.write( m_inputFbPlugNumber, "FunctionBlockSelector inputFbPlugNumber" );
200     bStatus &= se.write( m_controlSelector,   "FunctionBlockSelector controlSelector" );
201
202     return bStatus;
203 }
204
205 bool
206 FunctionBlockSelector::deserialize( IISDeserialize& de )
207 {
208     bool bStatus;
209     bStatus  = de.read( &m_selectorLength );
210     bStatus &= de.read( &m_inputFbPlugNumber );
211     bStatus &= de.read( &m_controlSelector );
212
213     return bStatus;
214 }
215
216 FunctionBlockSelector*
217 FunctionBlockSelector::clone() const
218 {
219     return new FunctionBlockSelector( *this );
220 }
221
222 /////////////////////////////////
223
224 FunctionBlockFeature::FunctionBlockFeature()
225     : IBusData()
226     , m_selectorLength( 0x02 )
227     , m_audioChannelNumber( 0x00 )
228     , m_pVolume( 0 )
229 {
230 }
231
232 FunctionBlockFeature::FunctionBlockFeature( const FunctionBlockFeature& rhs )
233     : IBusData()
234     , m_selectorLength( rhs.m_selectorLength )
235     , m_audioChannelNumber( rhs.m_audioChannelNumber )
236 {
237     if ( rhs.m_pVolume ) {
238         m_pVolume = new FunctionBlockFeatureVolume( *rhs.m_pVolume );
239     }
240 }
241
242 FunctionBlockFeature::~FunctionBlockFeature()
243 {
244     delete m_pVolume;
245     m_pVolume = 0;
246 }
247
248 bool
249 FunctionBlockFeature::serialize( IOSSerialize& se )
250 {
251     bool bStatus;
252     bStatus  = se.write( m_selectorLength,     "FunctionBlockFeature selectorLength" );
253     bStatus &= se.write( m_audioChannelNumber, "FunctionBlockFeature audioChannelNumber" );
254
255     if ( m_pVolume ) {
256         bStatus &= m_pVolume->serialize( se );
257     } else {
258         bStatus = false;
259     }
260
261     return bStatus;
262 }
263
264 bool
265 FunctionBlockFeature::deserialize( IISDeserialize& de )
266 {
267     bool bStatus;
268     bStatus  = de.read( &m_selectorLength );
269     bStatus &= de.read( &m_audioChannelNumber );
270
271     byte_t controlSelector;
272     bStatus &= de.peek( &controlSelector );
273     switch( controlSelector ) {
274     case eCSE_Feature_Volume:
275         if ( !m_pVolume ) {
276             m_pVolume = new FunctionBlockFeatureVolume;
277         }
278         bStatus &= m_pVolume->deserialize( de );
279         break;
280     case eCSE_Feature_Mute:
281     case eCSE_Feature_LRBalance:
282     case eCSE_Feature_FRBalance:
283     case eCSE_Feature_Bass:
284     case eCSE_Feature_Mid:
285     case eCSE_Feature_Treble:
286     case eCSE_Feature_GEQ:
287     case eCSE_Feature_AGC:
288     case eCSE_Feature_Delay:
289     case eCSE_Feature_BassBoost:
290     case eCSE_Feature_Loudness:
291     default:
292         bStatus = false;
293     }
294
295     return bStatus;
296 }
297
298 FunctionBlockFeature*
299 FunctionBlockFeature::clone() const
300 {
301     return new FunctionBlockFeature( *this );
302 }
303
304 /////////////////////////////////
305
306 FunctionBlockProcessing::FunctionBlockProcessing()
307     : IBusData()
308     , m_selectorLength( 0x04 )
309     , m_fbInputPlugNumber( 0x00 )
310     , m_inputAudioChannelNumber( 0x00 )
311     , m_outputAudioChannelNumber( 0x00 )
312     , m_pMixer( 0 )
313     , m_pEnhancedMixer( 0 )
314 {
315 }
316
317 FunctionBlockProcessing::FunctionBlockProcessing( const FunctionBlockProcessing& rhs )
318     : m_selectorLength( rhs.m_selectorLength )
319     , m_fbInputPlugNumber( rhs.m_fbInputPlugNumber )
320     , m_inputAudioChannelNumber( rhs.m_inputAudioChannelNumber )
321     , m_outputAudioChannelNumber( rhs.m_outputAudioChannelNumber )
322 {
323     if ( rhs.m_pMixer ) {
324         m_pMixer = new FunctionBlockProcessingMixer( *rhs.m_pMixer );
325     } else if ( rhs.m_pEnhancedMixer ) {
326         m_pEnhancedMixer = new FunctionBlockProcessingEnhancedMixer( *rhs.m_pEnhancedMixer );
327     }
328 }
329
330 FunctionBlockProcessing::~FunctionBlockProcessing()
331 {
332     delete m_pMixer;
333     m_pMixer = 0;
334     delete m_pEnhancedMixer;
335     m_pEnhancedMixer = 0;
336 }
337
338 bool
339 FunctionBlockProcessing::serialize( IOSSerialize& se )
340 {
341     bool bStatus;
342     bStatus  = se.write( m_selectorLength,     "FunctionBlockProcessing selectorLength" );
343     bStatus &= se.write( m_fbInputPlugNumber,  "FunctionBlockProcessing fbInputPlugNumber" );
344     bStatus &= se.write( m_inputAudioChannelNumber,  "FunctionBlockProcessing inputAudioChannelNumber" );
345     bStatus &= se.write( m_outputAudioChannelNumber, "FunctionBlockProcessing outputAudioChannelNumber" );
346
347     if ( m_pMixer ) {
348         bStatus &= m_pMixer->serialize( se );
349     } else if ( m_pEnhancedMixer ) {
350         bStatus &= m_pEnhancedMixer->serialize( se );
351     } else {
352         bStatus = false;
353     }
354
355     return bStatus;
356 }
357
358 bool
359 FunctionBlockProcessing::deserialize( IISDeserialize& de )
360 {
361     bool bStatus;
362     bStatus  = de.read( &m_selectorLength );
363     bStatus &= de.read( &m_fbInputPlugNumber );
364     bStatus &= de.read( &m_inputAudioChannelNumber );
365     bStatus &= de.read( &m_outputAudioChannelNumber );
366
367     byte_t controlSelector;
368     bStatus &= de.peek( &controlSelector );
369     switch( controlSelector ) {
370     case eCSE_Processing_Mixer:
371         if ( !m_pMixer ) {
372             m_pMixer = new FunctionBlockProcessingMixer;
373         }
374         bStatus &= m_pMixer->deserialize( de );
375         break;
376     case eCSE_Processing_EnhancedMixer:
377         if ( !m_pEnhancedMixer ) {
378             m_pEnhancedMixer = new FunctionBlockProcessingEnhancedMixer;
379         }
380         bStatus &= m_pEnhancedMixer->deserialize( de );
381         break;
382     case eCSE_Processing_Enable:
383     case eCSE_Processing_Mode:
384     default:
385         bStatus = false;
386     }
387
388     return bStatus;
389 }
390
391 FunctionBlockProcessing*
392 FunctionBlockProcessing::clone() const
393 {
394     return new FunctionBlockProcessing( *this );
395 }
396
397 /////////////////////////////////
398
399 FunctionBlockCodec::FunctionBlockCodec()
400     : IBusData()
401 {
402 }
403
404 FunctionBlockCodec::FunctionBlockCodec( const FunctionBlockCodec& rhs )
405     : IBusData()
406 {
407 }
408
409 FunctionBlockCodec::~FunctionBlockCodec()
410 {
411 }
412
413 bool
414 FunctionBlockCodec::serialize( IOSSerialize& se )
415 {
416     return false;
417 }
418
419 bool
420 FunctionBlockCodec::deserialize( IISDeserialize& de )
421 {
422     return false;
423 }
424
425 FunctionBlockCodec*
426 FunctionBlockCodec::clone() const
427 {
428     return new FunctionBlockCodec( *this );
429 }
430
431 /////////////////////////////////
432 /////////////////////////////////
433
434 FunctionBlockCmd::FunctionBlockCmd( Ieee1394Service* ieee1394service,
435                                     EFunctionBlockType eType,
436                                     function_block_id_t id,
437                                     EControlAttribute eCtrlAttrib )
438     : AVCCommand( ieee1394service, AVC1394_FUNCTION_BLOCK_CMD )
439     , m_functionBlockType( eType )
440     , m_functionBlockId( id )
441     , m_controlAttribute( eCtrlAttrib )
442     , m_pFBSelector( 0 )
443     , m_pFBFeature( 0 )
444     , m_pFBProcessing( 0 )
445     , m_pFBCodec( 0 )
446 {
447     setSubunitType( eST_Audio );
448
449     switch( m_functionBlockType ) {
450         case eFBT_Selector:
451             m_pFBSelector = new FunctionBlockSelector;
452             break;
453         case eFBT_Feature:
454             m_pFBFeature = new FunctionBlockFeature;
455             break;
456         case eFBT_Processing:
457             m_pFBProcessing = new FunctionBlockProcessing;
458             break;
459         case eFBT_Codec:
460             m_pFBCodec = new FunctionBlockCodec;
461             break;
462     }
463 }
464
465 FunctionBlockCmd::FunctionBlockCmd( const FunctionBlockCmd& rhs )
466     : AVCCommand( rhs )
467     , m_functionBlockType( rhs.m_functionBlockType )
468     , m_functionBlockId( rhs.m_functionBlockId )
469     , m_controlAttribute( rhs.m_controlAttribute )
470     , m_pFBSelector( new FunctionBlockSelector( *rhs.m_pFBSelector ) )
471     , m_pFBFeature( new FunctionBlockFeature( *rhs.m_pFBFeature ) )
472     , m_pFBProcessing( new FunctionBlockProcessing( *rhs.m_pFBProcessing ) )
473     , m_pFBCodec( new FunctionBlockCodec( *rhs.m_pFBCodec ) )
474 {
475 }
476
477 FunctionBlockCmd::~FunctionBlockCmd()
478 {
479     delete m_pFBSelector;
480     m_pFBSelector = 0;
481     delete m_pFBFeature;
482     m_pFBFeature = 0;
483     delete m_pFBProcessing;
484     m_pFBProcessing = 0;
485     delete m_pFBCodec;
486     m_pFBCodec = 0;
487 }
488
489 bool
490 FunctionBlockCmd::serialize( IOSSerialize& se )
491 {
492     bool bStatus;
493     bStatus  = AVCCommand::serialize( se );
494     bStatus &= se.write( m_functionBlockType, "FunctionBlockCmd functionBlockType" );
495     bStatus &= se.write( m_functionBlockId,   "FunctionBlockCmd functionBlockId" );
496     bStatus &= se.write( m_controlAttribute,  "FunctionBlockCmd controlAttribute" );
497
498     switch( m_functionBlockType ) {
499         case eFBT_Selector:
500             if ( m_pFBSelector ) {
501                 bStatus &= m_pFBSelector->serialize( se );
502             } else {
503                 bStatus = false;
504             }
505             break;
506         case eFBT_Feature:
507             if ( m_pFBFeature ) {
508                 bStatus &= m_pFBFeature->serialize( se );
509             } else {
510                 bStatus = false;
511             }
512             break;
513         case eFBT_Processing:
514             if ( m_pFBProcessing ) {
515                 bStatus &= m_pFBProcessing->serialize( se );
516             } else {
517                 bStatus = false;
518             }
519             break;
520         case eFBT_Codec:
521             if ( m_pFBCodec ) {
522                 bStatus &= m_pFBCodec->serialize( se );
523             } else {
524                 bStatus = false;
525             }
526             break;
527         default:
528             bStatus = false;
529     }
530
531     return bStatus;
532 }
533
534 bool
535 FunctionBlockCmd::deserialize( IISDeserialize& de )
536 {
537     bool bStatus;
538     bStatus  = AVCCommand::deserialize( de );
539
540     bStatus &= de.read( &m_functionBlockType );
541     bStatus &= de.read( &m_functionBlockId );
542     bStatus &= de.read( &m_controlAttribute );
543
544     switch( m_functionBlockType ) {
545         case eFBT_Selector:
546             if ( !m_pFBSelector ) {
547                 m_pFBSelector = new FunctionBlockSelector;
548             }
549             bStatus &= m_pFBSelector->deserialize( de );
550             break;
551         case eFBT_Feature:
552             if ( !m_pFBFeature ) {
553                 m_pFBFeature = new FunctionBlockFeature;
554             }
555             bStatus &= m_pFBFeature->deserialize( de );
556             break;
557         case eFBT_Processing:
558             if ( !m_pFBProcessing ) {
559                 m_pFBProcessing = new FunctionBlockProcessing;
560             }
561             bStatus &= m_pFBProcessing->deserialize( de );
562             break;
563         case eFBT_Codec:
564             if ( !m_pFBCodec ) {
565                 m_pFBCodec = new FunctionBlockCodec;
566             }
567             bStatus &= m_pFBCodec->deserialize( de );
568             break;
569         default:
570             bStatus = false;
571     }
572
573     return bStatus;
574 }
575
576 FunctionBlockCmd*
577 FunctionBlockCmd::clone() const
578 {
579     return new FunctionBlockCmd( *this );
580 }
Note: See TracBrowser for help on using the browser.