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

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

CVS-SVN migration developer public sync patch

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