root/trunk/libffado/src/libavc/audiosubunit/avc_function_block.cpp

Revision 2090, 21.7 kB (checked in by jwoithe, 11 years ago)

Fixes to the AVC EnhancedMixer? functional block which are needed for use with the M-Audio Ozonic. This patch has only been tested against an Ozonic, so it's probably wise for owners of other Bebob-based devices to test this to ensure there are no regressions. From Orania in ticket #341.

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