root/branches/libffado-2.0-with-panning/src/libavc/audiosubunit/avc_function_block.cpp

Revision 1338, 22.5 kB (checked in by wagi, 12 years ago)

- Add AV/C command for LRBalance feature function block
- Expose for each found feature function block one level feature

function mixer element and one left right balance feature
function mixer element.

- Add 'Volume' or 'LRBalance' as dbus

Line 
1 /*
2  * Copyright (C) 2005-2008 by Daniel Wagner
3  * Copyright (C) 2005-2008 by Pieter Palmers
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 2 of the License, or
13  * (at your option) version 3 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #include "avc_function_block.h"
26 #include "libutil/cmd_serialize.h"
27 #include "libieee1394/ieee1394service.h"
28
29
30 namespace AVC {
31
32
33 /////////////////////////////////
34
35 FunctionBlockFeatureVolume::FunctionBlockFeatureVolume()
36     : IBusData()
37     , m_controlDataLength( 2 )
38     , m_volume( 0 )
39 {
40 }
41
42 FunctionBlockFeatureVolume::FunctionBlockFeatureVolume( const FunctionBlockFeatureVolume& rhs )
43     : m_controlDataLength( rhs.m_controlDataLength )
44     , m_volume( rhs.m_volume )
45 {
46 }
47
48 FunctionBlockFeatureVolume::~FunctionBlockFeatureVolume()
49 {
50 }
51
52 bool
53 FunctionBlockFeatureVolume::serialize( Util::Cmd::IOSSerialize& se )
54 {
55     bool bStatus;
56     byte_t val;
57     bStatus = se.write( m_controlDataLength,  "FunctionBlockFeatureVolume controlDataLength" );
58     val = (byte_t)(m_volume >> 8);
59     bStatus &= se.write( val,                  "FunctionBlockFeatureVolume volume high" );
60     val = m_volume & 0xff;
61     bStatus &= se.write( val,                  "FunctionBlockFeatureVolume volume low" );
62
63     return bStatus;
64 }
65
66 bool
67 FunctionBlockFeatureVolume::deserialize( Util::Cmd::IISDeserialize& de )
68 {
69     bool bStatus;
70     byte_t val;
71     bStatus = de.read( &m_controlDataLength );
72     bStatus &= de.read( &val );
73     m_volume = val << 8;
74     bStatus &= de.read( &val );
75     m_volume |= val;
76
77     return bStatus;
78 }
79
80 FunctionBlockFeatureVolume*
81 FunctionBlockFeatureVolume::clone() const
82 {
83     return new FunctionBlockFeatureVolume( *this );
84 }
85
86 /////////////////////////////////
87
88 FunctionBlockFeatureLRBalance::FunctionBlockFeatureLRBalance()
89     : IBusData()
90     , m_controlDataLength( 2 )
91     , m_lrBalance( 0 )
92 {
93 }
94
95 FunctionBlockFeatureLRBalance::FunctionBlockFeatureLRBalance( const FunctionBlockFeatureLRBalance& rhs )
96     : m_controlDataLength( rhs.m_controlDataLength )
97     , m_lrBalance( rhs.m_lrBalance )
98 {
99 }
100
101 FunctionBlockFeatureLRBalance::~FunctionBlockFeatureLRBalance()
102 {
103 }
104
105 bool
106 FunctionBlockFeatureLRBalance::serialize( Util::Cmd::IOSSerialize& se )
107 {
108     bool bStatus;
109     byte_t val;
110     bStatus = se.write( m_controlDataLength,  "FunctionBlockFeatureLRBalance controlDataLength" );
111     val = (byte_t)(m_lrBalance >> 8);
112     bStatus &= se.write( val,                 "FunctionBlockFeatureLRBalance LR Balance high" );
113     val = m_lrBalance & 0xff;
114     bStatus &= se.write( val,                 "FunctionBlockFeatureLRBalance LR Balance low" );
115
116     return bStatus;
117 }
118
119 bool
120 FunctionBlockFeatureLRBalance::deserialize( Util::Cmd::IISDeserialize& de )
121 {
122     bool bStatus;
123     byte_t val;
124     bStatus = de.read( &m_controlDataLength );
125     bStatus &= de.read( &val );
126     m_lrBalance = val << 8;
127     bStatus &= de.read( &val );
128     m_lrBalance |= val;
129
130     return bStatus;
131 }
132
133 FunctionBlockFeatureLRBalance*
134 FunctionBlockFeatureLRBalance::clone() const
135 {
136     return new FunctionBlockFeatureLRBalance( *this );
137 }
138
139 /////////////////////////////////
140
141 FunctionBlockProcessingMixer::FunctionBlockProcessingMixer()
142     : IBusData()
143     , m_controlSelector( FunctionBlockProcessing::eCSE_Processing_Mixer )
144 {
145 }
146
147 FunctionBlockProcessingMixer::FunctionBlockProcessingMixer( const FunctionBlockProcessingMixer& rhs )
148     : m_controlSelector( rhs.m_controlSelector )
149 {
150 }
151
152 FunctionBlockProcessingMixer::~FunctionBlockProcessingMixer()
153 {
154 }
155
156 bool
157 FunctionBlockProcessingMixer::serialize( Util::Cmd::IOSSerialize& se )
158 {
159     bool bStatus;
160     bStatus = se.write( m_controlSelector,    "FunctionBlockProcessingMixer controlSelector" );
161
162     return bStatus;
163 }
164
165 bool
166 FunctionBlockProcessingMixer::deserialize( Util::Cmd::IISDeserialize& de )
167 {
168     bool bStatus;
169     bStatus = de.read( &m_controlSelector );
170
171     return bStatus;
172 }
173
174 FunctionBlockProcessingMixer*
175 FunctionBlockProcessingMixer::clone() const
176 {
177     return new FunctionBlockProcessingMixer( *this );
178 }
179
180 /////////////////////////////////
181
182 FunctionBlockProcessingEnhancedMixer::FunctionBlockProcessingEnhancedMixer()
183     : IBusData()
184     , m_controlSelector( FunctionBlockProcessing::eCSE_Processing_EnhancedMixer )
185     , m_statusSelector( eSS_ProgramableState )
186     , m_controlDataLength( 0 )
187 {
188 }
189
190 FunctionBlockProcessingEnhancedMixer::FunctionBlockProcessingEnhancedMixer(
191     const FunctionBlockProcessingEnhancedMixer& rhs )
192     : m_controlSelector( rhs.m_controlSelector )
193     , m_statusSelector( rhs.m_statusSelector )
194 {
195 }
196
197 FunctionBlockProcessingEnhancedMixer::~FunctionBlockProcessingEnhancedMixer()
198 {
199 }
200
201 bool
202 FunctionBlockProcessingEnhancedMixer::serialize( Util::Cmd::IOSSerialize& se )
203 {
204     int todo,done;
205     bool bStatus;
206     byte_t data_length_hi, data_length_lo;
207    
208     bStatus  = se.write( m_controlSelector, "FunctionBlockProcessingEnhancedMixer controlSelector" );
209     bStatus &= se.write( m_statusSelector,  "FunctionBlockProcessingEnhancedMixer statusSelector" );
210    
211     switch (m_statusSelector) {
212         case eSS_ProgramableState:
213             m_controlDataLength=m_LevelData.size();
214             data_length_hi=(m_controlDataLength >> 8);
215             data_length_lo=(m_controlDataLength & 0xFF);
216             bStatus &= se.write( data_length_hi,  "FunctionBlockProcessingEnhancedMixer controlDataLengthHi" );
217             bStatus &= se.write( data_length_lo,  "FunctionBlockProcessingEnhancedMixer controlDataLengthLo" );
218
219             for (int i=0;i<m_controlDataLength/8;i++) {
220                 byte_t value=0;
221                
222                 for (int j=0;j<8;j++) {
223                     control_data_ext_length_t bit_value=m_ProgramableStateData.at(i*8+j);
224                     value |= bit_value << (7-j);
225                 }
226                
227                 bStatus &= se.write( value,  "FunctionBlockProcessingEnhancedMixer data" );
228             }
229            
230             todo=m_controlDataLength%8;
231             done=m_controlDataLength-todo;
232             if (todo) {
233                 byte_t value=0;
234                 for (int j=0;j<todo;j++) {
235                     control_data_ext_length_t bit_value=m_ProgramableStateData.at(done*8+j);
236                     value |= bit_value << (7-j);
237                 }
238                 bStatus &= se.write( value,  "FunctionBlockProcessingEnhancedMixer data" );
239             }
240             break;
241         case eSS_Level:
242             m_controlDataLength=m_LevelData.size()/2;
243             data_length_hi=(m_controlDataLength >> 8);
244             data_length_lo=(m_controlDataLength & 0xFF);
245             bStatus &= se.write( data_length_hi,  "FunctionBlockProcessingEnhancedMixer controlDataLengthHi" );
246             bStatus &= se.write( data_length_lo,  "FunctionBlockProcessingEnhancedMixer controlDataLengthLo" );
247
248             for (int i=0;i<m_controlDataLength/2;i++) {
249                 mixer_level_t value=m_LevelData.at(i);
250                 byte_t value_hi=value >> 8;
251                 byte_t value_lo=value & 0xFF;
252                
253                 bStatus &= se.write( value_hi,  "FunctionBlockProcessingEnhancedMixer data" );
254                 bStatus &= se.write( value_lo,  "FunctionBlockProcessingEnhancedMixer data" );
255             }
256             break;
257     }
258     return bStatus;
259 }
260
261 bool
262 FunctionBlockProcessingEnhancedMixer::deserialize( Util::Cmd::IISDeserialize& de )
263 {
264     int todo;
265     bool bStatus;
266     bStatus  = de.read( &m_controlSelector );
267
268     // NOTE: the returned value is currently bogus, so overwrite it
269     m_controlSelector=FunctionBlockProcessing::eCSE_Processing_EnhancedMixer;
270
271     bStatus &= de.read( &m_statusSelector );
272
273     // same here
274     m_statusSelector = eSS_Level;
275     //m_statusSelector = eSS_ProgramableState;
276
277     byte_t data_length_hi;
278     byte_t data_length_lo;
279     bStatus &= de.read( &data_length_hi );
280     bStatus &= de.read( &data_length_lo );
281
282     m_controlDataLength = (data_length_hi << 8) + data_length_lo;
283     printf("m_controlDataLength = %d\n", m_controlDataLength);
284     switch (m_statusSelector) {
285         case eSS_ProgramableState:
286             m_ProgramableStateData.clear();
287             for (int i=0;i<m_controlDataLength/8;i++) {
288                 byte_t value;
289                 bStatus &= de.read( &value);
290
291                 for (int j=7;j>=0;j--) {
292                     byte_t bit_value;
293                     bit_value=(((1<<j) & value) ? 1 : 0);
294                     m_ProgramableStateData.push_back(bit_value);
295                 }
296             }
297
298             todo=m_controlDataLength%8;
299             if (todo) {
300                 byte_t value;
301                 bStatus &= de.read( &value);
302
303                 for (int j=7;j>7-todo;j--) {
304                     byte_t bit_value;
305                     bit_value=(((1<<j) & value) ? 1 : 0);
306                     m_ProgramableStateData.push_back(bit_value);
307                 }
308             }
309             break;
310         case eSS_Level:
311             m_LevelData.clear();
312             for (int i = 0; i < m_controlDataLength/2; i++) {
313                 byte_t mixer_value_hi = 0;
314                 byte_t mixer_value_lo = 0;
315                 bStatus &= de.read( &mixer_value_hi);
316                 bStatus &= de.read( &mixer_value_lo);
317
318                 mixer_level_t value = (mixer_value_hi << 8) + mixer_value_lo;
319
320                 printf("value = %x\n", value);
321                 m_LevelData.push_back(value);
322             }
323             break;
324     }
325
326     return bStatus;
327 }
328
329 FunctionBlockProcessingEnhancedMixer*
330 FunctionBlockProcessingEnhancedMixer::clone() const
331 {
332     return new FunctionBlockProcessingEnhancedMixer( *this );
333 }
334
335
336 /////////////////////////////////
337 /////////////////////////////////
338
339 FunctionBlockSelector::FunctionBlockSelector()
340     : IBusData()
341     , m_selectorLength( 0x02 )
342     , m_inputFbPlugNumber( 0x00 )
343     , m_controlSelector( eCSE_Selector_Selector )
344 {
345 }
346
347 FunctionBlockSelector::FunctionBlockSelector( const FunctionBlockSelector& rhs )
348     : IBusData()
349     , m_selectorLength( rhs.m_selectorLength )
350     , m_inputFbPlugNumber( rhs.m_inputFbPlugNumber )
351     , m_controlSelector( rhs.m_controlSelector )
352 {
353 }
354
355 FunctionBlockSelector::~FunctionBlockSelector()
356 {
357 }
358
359 bool
360 FunctionBlockSelector::serialize( Util::Cmd::IOSSerialize& se )
361 {
362     bool bStatus;
363     bStatus  = se.write( m_selectorLength,    "FunctionBlockSelector selectorLength" );
364     bStatus &= se.write( m_inputFbPlugNumber, "FunctionBlockSelector inputFbPlugNumber" );
365     bStatus &= se.write( m_controlSelector,   "FunctionBlockSelector controlSelector" );
366
367     return bStatus;
368 }
369
370 bool
371 FunctionBlockSelector::deserialize( Util::Cmd::IISDeserialize& de )
372 {
373     bool bStatus;
374     bStatus  = de.read( &m_selectorLength );
375     bStatus &= de.read( &m_inputFbPlugNumber );
376     bStatus &= de.read( &m_controlSelector );
377
378     return bStatus;
379 }
380
381 FunctionBlockSelector*
382 FunctionBlockSelector::clone() const
383 {
384     return new FunctionBlockSelector( *this );
385 }
386
387 /////////////////////////////////
388
389 FunctionBlockFeature::FunctionBlockFeature()
390     : IBusData()
391     , m_selectorLength( 0x02 )
392     , m_audioChannelNumber( 0x00 )
393     , m_controlSelector( eCSE_Feature_Unknown )
394     , m_pVolume( 0 )
395     , m_pLRBalance( 0 )
396 {
397 }
398
399 FunctionBlockFeature::FunctionBlockFeature( const FunctionBlockFeature& rhs )
400     : IBusData()
401     , m_selectorLength( rhs.m_selectorLength )
402     , m_audioChannelNumber( rhs.m_audioChannelNumber )
403     , m_controlSelector( rhs.m_controlSelector )
404 {
405     if ( rhs.m_pVolume ) {
406         m_pVolume = new FunctionBlockFeatureVolume( *rhs.m_pVolume );
407     } else if ( rhs.m_pLRBalance ) {
408         m_pLRBalance = new FunctionBlockFeatureLRBalance( *rhs.m_pLRBalance );
409     }
410 }
411
412 FunctionBlockFeature::~FunctionBlockFeature()
413 {
414     delete m_pVolume;
415     m_pVolume = 0;
416     delete m_pLRBalance;
417     m_pLRBalance = 0;
418 }
419
420 bool
421 FunctionBlockFeature::serialize( Util::Cmd::IOSSerialize& se )
422 {
423     bool bStatus;
424     bStatus  = se.write( m_selectorLength,     "FunctionBlockFeature selectorLength" );
425     bStatus &= se.write( m_audioChannelNumber, "FunctionBlockFeature audioChannelNumber" );
426     bStatus &= se.write( m_controlSelector,    "FunctionBlockFeature controlSelector" );
427
428     switch( m_controlSelector ) {
429     case eCSE_Feature_Volume:
430         bStatus &= m_pVolume->serialize( se );
431         break;
432     case eCSE_Feature_LRBalance:
433         bStatus &= m_pLRBalance->serialize( se );
434         break;
435     case eCSE_Feature_Mute:
436     case eCSE_Feature_FRBalance:
437     case eCSE_Feature_Bass:
438     case eCSE_Feature_Mid:
439     case eCSE_Feature_Treble:
440     case eCSE_Feature_GEQ:
441     case eCSE_Feature_AGC:
442     case eCSE_Feature_Delay:
443     case eCSE_Feature_BassBoost:
444     case eCSE_Feature_Loudness:
445     default:
446         bStatus = false;
447     }
448
449     return bStatus;
450 }
451
452 bool
453 FunctionBlockFeature::deserialize( Util::Cmd::IISDeserialize& de )
454 {
455     bool bStatus;
456     bStatus  = de.read( &m_selectorLength );
457     bStatus &= de.read( &m_audioChannelNumber );
458     bStatus &= de.read( &m_controlSelector );
459
460     switch( m_controlSelector ) {
461     case eCSE_Feature_Volume:
462         bStatus &= m_pVolume->deserialize( de );
463         break;
464     case eCSE_Feature_LRBalance:
465         bStatus &= m_pLRBalance->deserialize( de );
466         break;
467     case eCSE_Feature_Mute:
468     case eCSE_Feature_FRBalance:
469     case eCSE_Feature_Bass:
470     case eCSE_Feature_Mid:
471     case eCSE_Feature_Treble:
472     case eCSE_Feature_GEQ:
473     case eCSE_Feature_AGC:
474     case eCSE_Feature_Delay:
475     case eCSE_Feature_BassBoost:
476     case eCSE_Feature_Loudness:
477     default:
478         bStatus = false;
479     }
480
481     return bStatus;
482 }
483
484 FunctionBlockFeature*
485 FunctionBlockFeature::clone() const
486 {
487     return new FunctionBlockFeature( *this );
488 }
489
490 /////////////////////////////////
491
492 FunctionBlockProcessing::FunctionBlockProcessing()
493     : IBusData()
494     , m_selectorLength( 0x04 )
495     , m_fbInputPlugNumber( 0x00 )
496     , m_inputAudioChannelNumber( 0x00 )
497     , m_outputAudioChannelNumber( 0x00 )
498     , m_pMixer( 0 )
499     , m_pEnhancedMixer( 0 )
500 {
501 }
502
503 FunctionBlockProcessing::FunctionBlockProcessing( const FunctionBlockProcessing& rhs )
504     : m_selectorLength( rhs.m_selectorLength )
505     , m_fbInputPlugNumber( rhs.m_fbInputPlugNumber )
506     , m_inputAudioChannelNumber( rhs.m_inputAudioChannelNumber )
507     , m_outputAudioChannelNumber( rhs.m_outputAudioChannelNumber )
508 {
509     if ( rhs.m_pMixer ) {
510         m_pMixer = new FunctionBlockProcessingMixer( *rhs.m_pMixer );
511     } else if ( rhs.m_pEnhancedMixer ) {
512         m_pEnhancedMixer = new FunctionBlockProcessingEnhancedMixer( *rhs.m_pEnhancedMixer );
513     }
514 }
515
516 FunctionBlockProcessing::~FunctionBlockProcessing()
517 {
518     delete m_pMixer;
519     m_pMixer = 0;
520     delete m_pEnhancedMixer;
521     m_pEnhancedMixer = 0;
522 }
523
524 bool
525 FunctionBlockProcessing::serialize( Util::Cmd::IOSSerialize& se )
526 {
527     bool bStatus;
528     bStatus  = se.write( m_selectorLength,     "FunctionBlockProcessing selectorLength" );
529     bStatus &= se.write( m_fbInputPlugNumber,  "FunctionBlockProcessing fbInputPlugNumber" );
530     bStatus &= se.write( m_inputAudioChannelNumber,  "FunctionBlockProcessing inputAudioChannelNumber" );
531     bStatus &= se.write( m_outputAudioChannelNumber, "FunctionBlockProcessing outputAudioChannelNumber" );
532
533     if ( m_pMixer ) {
534         bStatus &= m_pMixer->serialize( se );
535     } else if ( m_pEnhancedMixer ) {
536         bStatus &= m_pEnhancedMixer->serialize( se );
537     } else {
538         bStatus = false;
539     }
540
541     return bStatus;
542 }
543
544 bool
545 FunctionBlockProcessing::deserialize( Util::Cmd::IISDeserialize& de )
546 {
547     // NOTE: apparently the fbCmd of the STATUS type,
548     // with EnhancedMixer controlSelector returns with this
549     // controlSelector type changed to Mixer, making it
550     // impossible to choose the correct response handler
551     // based upon the response only.
552    
553     // HACK: we assume that it is the same as the sent one
554     // we also look at our data structure to figure out what we sent
555     byte_t controlSelector=eCSE_Processing_Unknown;
556     if(m_pMixer) {
557         controlSelector=eCSE_Processing_Mixer;
558     } else if(m_pEnhancedMixer) {
559         controlSelector=eCSE_Processing_EnhancedMixer;
560     }
561    
562     bool bStatus;
563     bStatus  = de.read( &m_selectorLength );
564     bStatus &= de.read( &m_fbInputPlugNumber );
565     bStatus &= de.read( &m_inputAudioChannelNumber );
566     bStatus &= de.read( &m_outputAudioChannelNumber );
567
568     byte_t controlSelector_response;
569     bStatus &= de.peek( &controlSelector_response );
570 /*    debugOutput(DEBUG_LEVEL_VERBOSE,"ctrlsel: orig = %02X, resp = %02X\n",
571         controlSelector, controlSelector_response);*/
572    
573     switch( controlSelector ) {
574     case eCSE_Processing_Mixer:
575         if ( !m_pMixer ) {
576             m_pMixer = new FunctionBlockProcessingMixer;
577         }
578         bStatus &= m_pMixer->deserialize( de );
579         break;
580     case eCSE_Processing_EnhancedMixer:
581         if ( !m_pEnhancedMixer ) {
582             m_pEnhancedMixer = new FunctionBlockProcessingEnhancedMixer;
583         }
584         bStatus &= m_pEnhancedMixer->deserialize( de );
585         break;
586     case eCSE_Processing_Enable:
587     case eCSE_Processing_Mode:
588     default:
589         bStatus = false;
590     }
591
592     byte_t tmp;
593     if (de.peek(&tmp)) {
594         debugOutput(DEBUG_LEVEL_VERBOSE,"Unprocessed bytes:\n");
595         while (de.read(&tmp)) {
596             debugOutput(DEBUG_LEVEL_VERBOSE," %02X\n",tmp);
597         }
598     }
599
600     return bStatus;
601 }
602
603 FunctionBlockProcessing*
604 FunctionBlockProcessing::clone() const
605 {
606     return new FunctionBlockProcessing( *this );
607 }
608
609 /////////////////////////////////
610
611 FunctionBlockCodec::FunctionBlockCodec()
612     : IBusData()
613 {
614 }
615
616 FunctionBlockCodec::FunctionBlockCodec( const FunctionBlockCodec& rhs )
617     : IBusData()
618 {
619 }
620
621 FunctionBlockCodec::~FunctionBlockCodec()
622 {
623 }
624
625 bool
626 FunctionBlockCodec::serialize( Util::Cmd::IOSSerialize& se )
627 {
628     return false;
629 }
630
631 bool
632 FunctionBlockCodec::deserialize( Util::Cmd::IISDeserialize& de )
633 {
634     return false;
635 }
636
637 FunctionBlockCodec*
638 FunctionBlockCodec::clone() const
639 {
640     return new FunctionBlockCodec( *this );
641 }
642
643 /////////////////////////////////
644 /////////////////////////////////
645
646 FunctionBlockCmd::FunctionBlockCmd( Ieee1394Service& ieee1394service,
647                                     EFunctionBlockType eType,
648                                     function_block_id_t id,
649                                     EControlAttribute eCtrlAttrib )
650     : AVCCommand( ieee1394service, AVC1394_FUNCTION_BLOCK_CMD )
651     , m_functionBlockType( eType )
652     , m_functionBlockId( id )
653     , m_controlAttribute( eCtrlAttrib )
654     , m_pFBSelector( 0 )
655     , m_pFBFeature( 0 )
656     , m_pFBProcessing( 0 )
657     , m_pFBCodec( 0 )
658 {
659     setSubunitType( eST_Audio );
660
661     switch( m_functionBlockType ) {
662         case eFBT_Selector:
663             m_pFBSelector = new FunctionBlockSelector;
664             break;
665         case eFBT_Feature:
666             m_pFBFeature = new FunctionBlockFeature;
667             break;
668         case eFBT_Processing:
669             m_pFBProcessing = new FunctionBlockProcessing;
670             break;
671         case eFBT_Codec:
672             m_pFBCodec = new FunctionBlockCodec;
673             break;
674     }
675 }
676
677 FunctionBlockCmd::FunctionBlockCmd( const FunctionBlockCmd& rhs )
678     : AVCCommand( rhs )
679     , m_functionBlockType( rhs.m_functionBlockType )
680     , m_functionBlockId( rhs.m_functionBlockId )
681     , m_controlAttribute( rhs.m_controlAttribute )
682     , m_pFBSelector( new FunctionBlockSelector( *rhs.m_pFBSelector ) )
683     , m_pFBFeature( new FunctionBlockFeature( *rhs.m_pFBFeature ) )
684     , m_pFBProcessing( new FunctionBlockProcessing( *rhs.m_pFBProcessing ) )
685     , m_pFBCodec( new FunctionBlockCodec( *rhs.m_pFBCodec ) )
686 {
687 }
688
689 FunctionBlockCmd::~FunctionBlockCmd()
690 {
691     delete m_pFBSelector;
692     m_pFBSelector = 0;
693     delete m_pFBFeature;
694     m_pFBFeature = 0;
695     delete m_pFBProcessing;
696     m_pFBProcessing = 0;
697     delete m_pFBCodec;
698     m_pFBCodec = 0;
699 }
700
701 bool
702 FunctionBlockCmd::serialize( Util::Cmd::IOSSerialize& se )
703 {
704     bool bStatus;
705     bStatus  = AVCCommand::serialize( se );
706     bStatus &= se.write( m_functionBlockType, "FunctionBlockCmd functionBlockType" );
707     bStatus &= se.write( m_functionBlockId,   "FunctionBlockCmd functionBlockId" );
708     bStatus &= se.write( m_controlAttribute,  "FunctionBlockCmd controlAttribute" );
709
710     switch( m_functionBlockType ) {
711         case eFBT_Selector:
712             if ( m_pFBSelector ) {
713                 bStatus &= m_pFBSelector->serialize( se );
714             } else {
715                 bStatus = false;
716             }
717             break;
718         case eFBT_Feature:
719             if ( m_pFBFeature ) {
720                 bStatus &= m_pFBFeature->serialize( se );
721             } else {
722                 bStatus = false;
723             }
724             break;
725         case eFBT_Processing:
726             if ( m_pFBProcessing ) {
727                 bStatus &= m_pFBProcessing->serialize( se );
728             } else {
729                 bStatus = false;
730             }
731             break;
732         case eFBT_Codec:
733             if ( m_pFBCodec ) {
734                 bStatus &= m_pFBCodec->serialize( se );
735             } else {
736                 bStatus = false;
737             }
738             break;
739         default:
740             bStatus = false;
741     }
742
743     return bStatus;
744 }
745
746 bool
747 FunctionBlockCmd::deserialize( Util::Cmd::IISDeserialize& de )
748 {
749     bool bStatus;
750     bStatus  = AVCCommand::deserialize( de );
751
752     bStatus &= de.read( &m_functionBlockType );
753     bStatus &= de.read( &m_functionBlockId );
754     bStatus &= de.read( &m_controlAttribute );
755
756     switch( m_functionBlockType ) {
757         case eFBT_Selector:
758             if ( !m_pFBSelector ) {
759                 m_pFBSelector = new FunctionBlockSelector;
760             }
761             bStatus &= m_pFBSelector->deserialize( de );
762             break;
763         case eFBT_Feature:
764             if ( !m_pFBFeature ) {
765                 m_pFBFeature = new FunctionBlockFeature;
766             }
767             bStatus &= m_pFBFeature->deserialize( de );
768             break;
769         case eFBT_Processing:
770             if ( !m_pFBProcessing ) {
771                 m_pFBProcessing = new FunctionBlockProcessing;
772             }
773             bStatus &= m_pFBProcessing->deserialize( de );
774             break;
775         case eFBT_Codec:
776             if ( !m_pFBCodec ) {
777                 m_pFBCodec = new FunctionBlockCodec;
778             }
779             bStatus &= m_pFBCodec->deserialize( de );
780             break;
781         default:
782             bStatus = false;
783     }
784
785     return bStatus;
786 }
787
788 FunctionBlockCmd*
789 FunctionBlockCmd::clone() const
790 {
791     return new FunctionBlockCmd( *this );
792 }
793
794 }
Note: See TracBrowser for help on using the browser.