root/trunk/libfreebob/src/bebob/bebob_avplug_xml.cpp

Revision 375, 9.3 kB (checked in by wagi, 17 years ago)

AVCCommand: All AVC commants take a reference instead a pointer to 1394 service
BeBoB::AvDevice?: PreSonus? FIREBOX id added

De/Serialize all AvPlugs? through AvPlugManager?
AvPlugManager? can't be a member because of serialization

Line 
1 /* bebob_avplug_xml.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
21 // AvPlug XML stuff
22
23 #include "bebob/bebob_avplug.h"
24 #include "configrom.h"
25
26 #include "libfreebobavc/ieee1394service.h"
27
28 namespace BeBoB {
29
30 bool
31 AvPlug::addXmlDescription( xmlNodePtr connectionSet )
32 {
33     char* result;
34
35     int direction;
36     switch ( m_direction ) {
37         case 0:
38             direction = FREEBOB_PLAYBACK;
39             break;
40         case 1:
41             direction = FREEBOB_CAPTURE;
42             break;
43     default:
44         debugError( "plug direction invalid (%d)\n",
45                     m_direction );
46         return false;
47     }
48
49     asprintf( &result, "%d",  direction );
50     if ( !xmlNewChild( connectionSet,
51                        0,
52                        BAD_CAST "Direction",
53                        BAD_CAST result ) )
54     {
55         debugError( "Couldn't create 'Direction' node\n" );
56         free( result );
57         return false;
58     }
59     free( result );
60
61     xmlNodePtr connection = xmlNewChild( connectionSet, 0,
62                                          BAD_CAST "Connection", 0 );
63     if ( !connection ) {
64         debugError( "Couldn't create 'Connection' node for "
65                     "direction %d\n", m_direction );
66         return false;
67     }
68
69     /*
70     asprintf( &result, "%08x%08x",
71               ( quadlet_t )( m_configRom->getGuid() >> 32 ),
72               ( quadlet_t )( m_configRom->getGuid() & 0xfffffff ) );
73     if ( !xmlNewChild( connection,  0,
74                        BAD_CAST "GUID",  BAD_CAST result ) ) {
75         debugError( "Couldn't create 'GUID' node\n" );
76         return false;
77     }
78     */
79
80     asprintf( &result, "%d", m_p1394Service->getPort() );
81     if ( !xmlNewChild( connection,  0,
82                        BAD_CAST "Port",  BAD_CAST result ) ) {
83         debugError( "Couldn't create 'Port' node\n" );
84         free( result );
85         return false;
86     }
87     free( result );
88
89     asprintf( &result, "%d",  m_pConfigRom->getNodeId() );
90     if ( !xmlNewChild( connection,  0,
91                        BAD_CAST "Node",  BAD_CAST result ) ) {
92         debugError( "Couldn't create 'Node' node\n" );
93         free( result );
94         return false;
95     }
96     free( result );
97
98
99     asprintf( &result, "%d",  m_nrOfChannels );
100     if ( !xmlNewChild( connection,  0,
101                        BAD_CAST "Dimension",  BAD_CAST result ) ) {
102         debugError( "Couldn't create 'Dimension' node\n" );
103         free( result );
104         return false;
105     }
106     free( result );
107
108     asprintf( &result, "%d",  getSampleRate() );
109     if ( !xmlNewChild( connection,  0,
110                        BAD_CAST "Samplerate",  BAD_CAST result ) ) {
111         debugError( "Couldn't create 'Samplerate' node\n" );
112         free( result );
113         return false;
114     }
115     free( result );
116
117     if ( !xmlNewChild( connection,  0,
118                        BAD_CAST "IsoChannel", BAD_CAST "-1" ) )
119     {
120         debugError( "Couldn't create 'IsoChannel' node\n" );
121         return false;
122     }
123
124     xmlNodePtr streams = xmlNewChild( connection,  0,
125                                       BAD_CAST "Streams",  0 );
126     if ( !streams ) {
127         debugError( "Couldn't create 'Streams' node for "
128                     "direction %d\n", m_direction );
129         return false;
130     }
131
132     for ( AvPlug::ClusterInfoVector::const_iterator it = m_clusterInfos.begin();
133           it != m_clusterInfos.end();
134           ++it )
135     {
136         const AvPlug::ClusterInfo* clusterInfo = &( *it );
137
138         AvPlug::ChannelInfoVector channelInfos = clusterInfo->m_channelInfos;
139         for ( AvPlug::ChannelInfoVector::const_iterator it = channelInfos.begin();
140               it != channelInfos.end();
141               ++it )
142         {
143             const AvPlug::ChannelInfo* channelInfo = &( *it );
144
145             xmlNodePtr stream = xmlNewChild( streams,  0,
146                                              BAD_CAST "Stream",  0 );
147             if ( !stream ) {
148                 debugError( "Coulnd't create 'Stream' node" );
149                 return false;
150             }
151
152             // \todo: iec61883 backend expects indexing starting from 0
153             // but bebob reports it starting from 1. Decide where
154             // and how to handle this
155             asprintf( &result, "%d", channelInfo->m_streamPosition - 1 );
156             if ( !xmlNewChild( stream,  0,
157                                BAD_CAST "Position",  BAD_CAST result ) )
158             {
159                 debugError( "Couldn't create 'Position' node" );
160                 free( result );
161                 return false;
162             }
163             free( result );
164
165             asprintf( &result, "%d", channelInfo->m_location );
166             if ( !xmlNewChild( stream,  0,
167                                BAD_CAST "Location",  BAD_CAST result ) )
168             {
169                 debugError( "Couldn't create 'Location' node" );
170                 free( result );
171                 return false;
172             }
173             free( result );
174
175             asprintf( &result, "%d", clusterInfo->m_streamFormat );
176             if ( !xmlNewChild( stream,  0,
177                                BAD_CAST "Format",  BAD_CAST result ) )
178             {
179                 debugError( "Couldn't create 'Format' node" );
180                 free( result );
181                 return false;
182             }
183             free( result );
184
185             asprintf( &result, "%d", clusterInfo->m_portType );
186             if ( !xmlNewChild( stream,  0,
187                                BAD_CAST "Type",  BAD_CAST result ) )
188             {
189                 debugError( "Couldn't create 'Type' node" );
190                 free( result );
191                 return false;
192             }
193             free( result );
194
195
196             // \todo XXX: What do to do with DestinationPort value??
197             asprintf( &result, "%d", 0 );
198             if ( !xmlNewChild( stream,  0,
199                                BAD_CAST "DestinationPort",  BAD_CAST result ) )
200             {
201                 debugError( "Couldn't create 'DestinationPort' node" );
202                 free( result );
203                 return false;
204             }
205             free( result );
206
207             if ( !xmlNewChild( stream,  0,
208                                BAD_CAST "Name",
209                                BAD_CAST channelInfo->m_name.c_str() ) )
210             {
211                 debugError( "Couldn't create 'Name' node" );
212                 return false;
213             }
214         }
215     }
216
217     return true;
218 }
219
220
221 bool
222 AvPlug::addXmlDescriptionStreamFormats( xmlNodePtr streamFormatNode )
223 {
224     int direction;
225     switch ( m_direction ) {
226         case 0:
227             direction = FREEBOB_PLAYBACK;
228             break;
229         case 1:
230             direction = FREEBOB_CAPTURE;
231             break;
232     default:
233         debugError( "addXmlDescriptionStreamFormats: plug direction invalid (%d)\n",
234                     m_direction );
235         return false;
236     }
237
238     char* result;
239     asprintf( &result, "%d",  direction );
240     if ( !xmlNewChild( streamFormatNode,
241                        0,
242                        BAD_CAST "Direction",
243                        BAD_CAST result ) )
244     {
245         debugError( "addXmlDescriptionStreamFormats: Could not  create 'Direction' node\n" );
246         free( result );
247         return false;
248     }
249     free( result );
250
251
252     for ( FormatInfoVector::iterator it =
253               m_formatInfos.begin();
254           it != m_formatInfos.end();
255           ++it )
256     {
257         AvPlug::FormatInfo formatInfo = *it;
258         xmlNodePtr formatNode = xmlNewChild( streamFormatNode, 0,
259                                              BAD_CAST "Format", 0 );
260         if ( !formatNode ) {
261             debugError( "addXmlDescriptionStreamFormats: Could not create 'Format' node\n" );
262             return false;
263         }
264
265         asprintf( &result, "%d",
266                   convertESamplingFrequency( static_cast<ESamplingFrequency>( formatInfo.m_samplingFrequency ) ) );
267         if ( !xmlNewChild( formatNode,  0,
268                            BAD_CAST "Samplerate",  BAD_CAST result ) )
269         {
270             debugError( "Couldn't create 'Samplerate' node\n" );
271             free( result );
272             return false;
273         }
274         free( result );
275
276         asprintf( &result, "%d",  formatInfo.m_audioChannels );
277         if ( !xmlNewChild( formatNode,  0,
278                            BAD_CAST "AudioChannels",  BAD_CAST result ) )
279         {
280             debugError( "Couldn't create 'AudioChannels' node\n" );
281             free( result );
282             return false;
283         }
284         free( result );
285
286         asprintf( &result, "%d",  formatInfo.m_midiChannels );
287         if ( !xmlNewChild( formatNode,  0,
288                            BAD_CAST "MidiChannels",  BAD_CAST result ) )
289         {
290             debugError( "Couldn't create 'MidiChannels' node\n" );
291             free( result );
292             return false;
293         }
294     }
295
296     return true;
297 }
298
299 }
Note: See TracBrowser for help on using the browser.