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

Revision 187, 8.6 kB (checked in by wagi, 18 years ago)

2006-05-04 Daniel Wagner <wagi@monom.org>

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