root/branches/streaming-rework/src/bebob/bebob_avplug_xml.cpp

Revision 404, 9.4 kB (checked in by pieterpalmers, 16 years ago)

- introduce support framework for DICE and Metric Halo
- change probe/discovery code to make adding devices easier
- made conditional compilation effectively work.

./configure now has the following switches:

--enable-bebob build BeBoB support (default=yes)
--enable-motu build Motu support (default=no)
--enable-dice build DICE support (default=no)
--enable-metric-halo build Metric Halo support (note: completely useless)

(default=no)

--enable-rme build RME support (note: completely useless)

(default=no)

--enable-bounce build Bounce device support (default=no)
--enable-all-devices build support for all supported devices (default=no)

these now turn on/off compilation effectively.

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