root/branches/echoaudio/src/libavc/audiosubunit/avc_audiosubunit.cpp

Revision 508, 11.7 kB (checked in by ppalmers, 16 years ago)

splitted avc_subunit.cpp into separate files per subunit type

Line 
1 /*
2  * Copyright (C)      2007 by Pieter Palmers
3  * Copyright (C) 2005-2007 by Daniel Wagner
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 library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License version 2.1, as published by the Free Software Foundation;
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22  * MA 02110-1301 USA
23  */
24
25 #include "avc_audiosubunit.h"
26 #include "../general/avc_subunit.h"
27
28 #warning merge with bebob functionblock
29 #include "bebob/bebob_functionblock.h"
30 #include "../audiosubunit/avc_function_block.h"
31
32
33 #include <sstream>
34
35 namespace AVC {
36
37 ////////////////////////////////////////////
38
39 SubunitAudio::SubunitAudio( Unit& unit, subunit_t id )
40     : Subunit( unit, eST_Audio, id )
41 {
42 }
43
44 SubunitAudio::SubunitAudio()
45     : Subunit()
46 {
47 }
48
49 SubunitAudio::~SubunitAudio()
50 {
51     for ( BeBoB::FunctionBlockVector::iterator it = m_functions.begin();
52           it != m_functions.end();
53           ++it )
54     {
55         delete *it;
56     }
57 }
58
59 bool
60 SubunitAudio::discover()
61 {
62     debugOutput(DEBUG_LEVEL_NORMAL, "Discovering Audio Subunit...\n");
63    
64     if ( !Subunit::discover() ) {
65         return false;
66     }
67
68 //     if ( !discoverBeBoB::FunctionBlocks() ) {
69 //         debugError( "function block discovering failed\n" );
70 //         return false;
71 //     }
72
73     return true;
74 }
75
76
77 const char*
78 SubunitAudio::getName()
79 {
80     return "AudioSubunit";
81 }
82
83 // bool
84 // SubunitAudio::discoverConnections()
85 // {
86 //     debugOutput(DEBUG_LEVEL_NORMAL, "Discovering connections...\n");
87 //     if ( !Subunit::discoverConnections() ) {
88 //         return false;
89 //     }
90 //
91 //     for ( BeBoB::FunctionBlockVector::iterator it = m_functions.begin();
92 //           it != m_functions.end();
93 //           ++it )
94 //     {
95 //         BeBoB::FunctionBlock* function = *it;
96 //         if ( !function->discoverConnections() ) {
97 //             debugError( "functionblock connection discovering failed ('%s')\n",
98 //                         function->getName() );
99 //             return false;
100 //         }
101 //     }
102 //
103 //     return true;
104 // }
105 // bool
106 // SubunitAudio::discoverBeBoB::FunctionBlocks()
107 // {
108 //     debugOutput( DEBUG_LEVEL_NORMAL,
109 //                  "Discovering function blocks...\n");
110 //
111 //     if ( !discoverBeBoB::FunctionBlocksDo(
112 //              ExtendedSubunitInfoCmd::eFBT_AudioSubunitSelector) )
113 //     {
114 //         debugError( "Could not discover function block selector\n" );
115 //         return false;
116 //     }
117 //     if ( !discoverBeBoB::FunctionBlocksDo(
118 //              ExtendedSubunitInfoCmd::eFBT_AudioSubunitFeature) )
119 //     {
120 //         debugError( "Could not discover function block feature\n" );
121 //         return false;
122 //     }
123 //     if ( !discoverBeBoB::FunctionBlocksDo(
124 //              ExtendedSubunitInfoCmd::eFBT_AudioSubunitProcessing) )
125 //     {
126 //         debugError( "Could not discover function block processing\n" );
127 //         return false;
128 //     }
129 //     if ( !discoverBeBoB::FunctionBlocksDo(
130 //              ExtendedSubunitInfoCmd::eFBT_AudioSubunitCodec) )
131 //     {
132 //         debugError( "Could not discover function block codec\n" );
133 //         return false;
134 //     }
135 //
136 //     // print a function block list
137 // #ifdef DEBUG
138 //     if (getDebugLevel() >= DEBUG_LEVEL_NORMAL) {
139 //     
140 //         for ( BeBoB::FunctionBlockVector::iterator it = m_functions.begin();
141 //             it != m_functions.end();
142 //             ++it )
143 //         {
144 //             debugOutput(DEBUG_LEVEL_NORMAL, "%20s FB, type 0x%X, id=%d\n",
145 //                 (*it)->getName(),
146 //                 (*it)->getType(),
147 //                 (*it)->getId());
148 //         }
149 //     }
150 // #endif
151 //
152 //     return true;
153 // }
154 //
155 // bool
156 // SubunitAudio::discoverBeBoB::FunctionBlocksDo(
157 //     ExtendedSubunitInfoCmd::EBeBoB::FunctionBlockType fbType )
158 // {
159 //     int page = 0;
160 //     bool cmdSuccess = false;
161 //     bool finished = false;
162 //
163 //     do {
164 //         ExtendedSubunitInfoCmd
165 //             extSubunitInfoCmd( m_unit->get1394Service() );
166 //         extSubunitInfoCmd.setNodeId( m_unit->getConfigRom().getNodeId() );
167 //         extSubunitInfoCmd.setCommandType( AVCCommand::eCT_Status );
168 //         extSubunitInfoCmd.setSubunitId( getSubunitId() );
169 //         extSubunitInfoCmd.setSubunitType( getSubunitType() );
170 //         extSubunitInfoCmd.setVerbose( m_verboseLevel );
171 //
172 //         extSubunitInfoCmd.m_fbType = fbType;
173 //         extSubunitInfoCmd.m_page = page;
174 //
175 //         cmdSuccess = extSubunitInfoCmd.fire();
176 //         if ( cmdSuccess
177 //              && ( extSubunitInfoCmd.getResponse()
178 //                   == AVCCommand::eR_Implemented ) )
179 //         {
180 //             for ( ExtendedSubunitInfoPageDataVector::iterator it =
181 //                       extSubunitInfoCmd.m_infoPageDatas.begin();
182 //                   cmdSuccess
183 //                       && ( it != extSubunitInfoCmd.m_infoPageDatas.end() );
184 //                   ++it )
185 //             {
186 //                 cmdSuccess = createBeBoB::FunctionBlock( fbType, **it );
187 //             }
188 //             if ( ( extSubunitInfoCmd.m_infoPageDatas.size() != 0 )
189 //                  && ( extSubunitInfoCmd.m_infoPageDatas.size() == 5 ) )
190 //             {
191 //                 page++;
192 //             } else {
193 //                 finished = true;
194 //             }
195 //         } else {
196 //             finished = true;
197 //         }
198 //     } while ( cmdSuccess && !finished );
199 //
200 //     return cmdSuccess;
201 // }
202 //
203 // bool
204 // SubunitAudio::createBeBoB::FunctionBlock(
205 //     ExtendedSubunitInfoCmd::EBeBoB::FunctionBlockType fbType,
206 //     ExtendedSubunitInfoPageData& data )
207 // {
208 //     BeBoB::FunctionBlock::ESpecialPurpose purpose
209 //         = convertSpecialPurpose(  data.m_functionBlockSpecialPupose );
210 //
211 //     BeBoB::FunctionBlock* fb = 0;
212 //
213 //     switch ( fbType ) {
214 //     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitSelector:
215 //     {
216 //         fb = new BeBoB::FunctionBlockSelector( *this,
217 //                                         data.m_functionBlockId,
218 //                                         purpose,
219 //                                         data.m_noOfInputPlugs,
220 //                                         data.m_noOfOutputPlugs,
221 //                                         m_verboseLevel );
222 //     }
223 //     break;
224 //     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitFeature:
225 //     {
226 //         fb = new BeBoB::FunctionBlockFeature( *this,
227 //                                        data.m_functionBlockId,
228 //                                        purpose,
229 //                                        data.m_noOfInputPlugs,
230 //                                        data.m_noOfOutputPlugs,
231 //                                        m_verboseLevel );
232 //     }
233 //     break;
234 //     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitProcessing:
235 //     {
236 //         switch ( data.m_functionBlockType ) {
237 //         case ExtendedSubunitInfoCmd::ePT_EnhancedMixer:
238 //         {
239 //             fb = new BeBoB::FunctionBlockEnhancedMixer( *this,
240 //                                                  data.m_functionBlockId,
241 //                                                  purpose,
242 //                                                  data.m_noOfInputPlugs,
243 //                                                  data.m_noOfOutputPlugs,
244 //                                                  m_verboseLevel );
245 //         }
246 //         break;
247 //         case ExtendedSubunitInfoCmd::ePT_Mixer:
248 //         case ExtendedSubunitInfoCmd::ePT_Generic:
249 //         case ExtendedSubunitInfoCmd::ePT_UpDown:
250 //         case ExtendedSubunitInfoCmd::ePT_DolbyProLogic:
251 //         case ExtendedSubunitInfoCmd::ePT_3DStereoExtender:
252 //         case ExtendedSubunitInfoCmd::ePT_Reverberation:
253 //         case ExtendedSubunitInfoCmd::ePT_Chorus:
254 //         case ExtendedSubunitInfoCmd::ePT_DynamicRangeCompression:
255 //         default:
256 //             fb = new BeBoB::FunctionBlockProcessing( *this,
257 //                                               data.m_functionBlockId,
258 //                                               purpose,
259 //                                               data.m_noOfInputPlugs,
260 //                                               data.m_noOfOutputPlugs,
261 //                                               m_verboseLevel );
262 //             debugWarning( "Dummy function block processing created. "
263 //                           "Implementation is missing\n" );
264 //         }
265 //     }
266 //     break;
267 //     case ExtendedSubunitInfoCmd::eFBT_AudioSubunitCodec:
268 //     {
269 //         fb = new BeBoB::FunctionBlockCodec( *this,
270 //                                      data.m_functionBlockId,
271 //                                      purpose,
272 //                                      data.m_noOfInputPlugs,
273 //                                      data.m_noOfOutputPlugs,
274 //                                      m_verboseLevel );
275 //         debugWarning( "Dummy function block codec created. "
276 //                       "Implementation is missing\n" );
277 //     }
278 //     break;
279 //     default:
280 //         debugError( "Unhandled function block type found\n" );
281 //         return false;
282 //     }
283 //
284 //     if ( !fb ) {
285 //         debugError( "Could create function block\n" );
286 //         return false;
287 //     }
288 //     if ( !fb->discover() ) {
289 //         debugError( "Could not discover function block %s\n",
290 //                     fb->getName() );
291 //         delete fb;
292 //         return false;
293 //     }
294 //     m_functions.push_back( fb );
295 //
296 //     return true;
297 // }
298 //
299 // BeBoB::FunctionBlock::ESpecialPurpose
300 // SubunitAudio::convertSpecialPurpose(
301 //     function_block_special_purpose_t specialPurpose )
302 // {
303 //     BeBoB::FunctionBlock::ESpecialPurpose p;
304 //     switch ( specialPurpose ) {
305 //     case ExtendedSubunitInfoPageData::eSP_InputGain:
306 //         p  = BeBoB::FunctionBlock::eSP_InputGain;
307 //         break;
308 //     case ExtendedSubunitInfoPageData::eSP_OutputVolume:
309 //         p = BeBoB::FunctionBlock::eSP_OutputVolume;
310 //     break;
311 //     default:
312 //         p = BeBoB::FunctionBlock::eSP_NoSpecialPurpose;
313 //     }
314 //     return p;
315 // }
316 //
317 bool
318 SubunitAudio::serializeChild( Glib::ustring basePath,
319                                              Util::IOSerialize& ser ) const
320 {
321     bool result = true;
322     int i = 0;
323
324     for ( BeBoB::FunctionBlockVector::const_iterator it = m_functions.begin();
325           it != m_functions.end();
326           ++it )
327     {
328         BeBoB::FunctionBlock* pFB = *it;
329         std::ostringstream strstrm;
330         strstrm << basePath << "BeBoB::FunctionBlock" << i << "/";
331
332         result &= pFB->serialize( strstrm.str() , ser );
333
334         i++;
335     }
336
337     return result;
338 }
339
340 bool
341 SubunitAudio::deserializeChild( Glib::ustring basePath,
342                                                Util::IODeserialize& deser,
343                                                Unit& unit )
344 {
345     int i = 0;
346     bool bFinished = false;
347     do {
348         std::ostringstream strstrm;
349         strstrm << basePath << "BeBoB::FunctionBlock" << i << "/";
350         BeBoB::FunctionBlock* pFB = BeBoB::FunctionBlock::deserialize( strstrm.str(),
351                                                          deser,
352                                                          unit,
353                                                          *this );
354         if ( pFB ) {
355             m_functions.push_back( pFB );
356             i++;
357         } else {
358             bFinished = true;
359         }
360     } while ( !bFinished );
361
362     return true;
363 }
364
365 }
Note: See TracBrowser for help on using the browser.