root/trunk/libfreebob/src/freebob.cpp

Revision 165, 8.9 kB (checked in by wagi, 18 years ago)

2006-03-02 Daniel Wagner <wagi@monom.org>

  • configure.ac: bumb minor version to 0.4
  • src/libfreebobavc/avc_extended_cmd_generic.h: plugAddressPlugDirectionToString
    and plugAddressAddressModeToString added.
  • src/libfreebobavc/avc_extended_cmd_generic.cpp: Likewise.
  • src/avplug.h: Enum EAvPlugType renamed to EAvPlugAddressType.
    getPlugAddressType added. getPlugType returns now real plug type.
    (class AvPlugManager?): getPlugByType added.
  • src/avdevice.h: getPlugByType added.
  • src/avdevice.cpp: Likewise.
    (discoverSyncModes): Use getPlugByType instead
    of hardcoded id to find sync plugs.
  • src/devicemanager.h: Verbose argument not in constructor
    instead in discover method.
  • src/devicemanager.cpp: Likewise.
  • libfreebob/freebob.h (freebob_discover_devices): Verbose argument
    added.
  • src/libfreebobstreaming/freebob_streaming.c: Likewise.
  • src/freebob.cpp: Likewise.
  • tests/test-freebob.c: Likewise.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* freebob.h
2  * Copyright (C) 2005 Pieter Palmers, Daniel Wagner
3  *
4  * This file is part of FreeBoB
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  */
21
22 #include "config.h"
23
24 #include "libfreebob/freebob.h"
25 #include "libfreebob/xmlparser.h"
26
27 #include "debugmodule/debugmodule.h"
28 #include "fbtypes.h"
29 #include "devicemanager.h"
30 #include "avdevice.h"
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <libxml/xmlmemory.h>
36 #include <libxml/parser.h>
37
38 DECLARE_GLOBAL_DEBUG_MODULE;
39 IMPL_GLOBAL_DEBUG_MODULE( FreeBob, DEBUG_LEVEL_VERBOSE );
40
41 const char*
42 freebob_get_version() {
43     return PACKAGE_STRING;
44 }
45
46 freebob_handle_t
47 freebob_new_handle( int port )
48 {
49     freebob_handle_t handle = new struct freebob_handle;
50     if (! handle ) {
51         debugFatal( "Could not allocate memory for new handle\n" );
52         return 0;
53     }
54
55     handle->m_deviceManager = new DeviceManager();
56     if ( !handle->m_deviceManager ) {
57         debugFatal( "Could not allocate device manager\n" );
58         delete handle;
59         return 0;
60     }
61     if ( !handle->m_deviceManager->initialize( port ) ) {
62         debugFatal( "Could not initialize device manager\n" );
63         delete handle->m_deviceManager;
64         delete handle;
65         return 0;
66     }
67     return handle;
68 }
69
70 int
71 freebob_destroy_handle( freebob_handle_t freebob_handle )
72 {
73     delete freebob_handle->m_deviceManager;
74     delete freebob_handle;
75     return 0;
76 }
77
78 int
79 freebob_discover_devices( freebob_handle_t freebob_handle, int verbose )
80 {
81     return freebob_handle->m_deviceManager->discover(verbose)? 0 : -1;
82 }
83
84 freebob_connection_info_t*
85 freebob_get_connection_info( freebob_handle_t freebob_handle,
86                              int node_id,
87                              enum freebob_direction direction )
88 {
89     xmlDocPtr doc;
90     doc = freebob_handle->m_deviceManager->getXmlDescription();
91     if ( !doc ) {
92         debugFatal( "Could not get XML description\n" );
93         return 0;
94     }
95
96     return freebob_xmlparse_get_connection_info( doc, node_id, direction );
97 }
98
99 freebob_supported_stream_format_info_t*
100 freebob_get_supported_stream_format_info( freebob_handle_t freebob_handle,
101                                           int node_id,
102                                           enum freebob_direction direction )
103 {
104     xmlDocPtr doc;
105     doc = freebob_handle->m_deviceManager->getXmlDescription();
106     if ( !doc ) {
107         debugFatal( "Could not get XML description\n" );
108         return 0;
109     }
110
111     return freebob_xmlparse_get_stream_formats( doc, node_id, direction );
112 }
113
114 int
115 freebob_node_is_valid_freebob_device( freebob_handle_t freebob_handle, int node_id )
116 {
117     return freebob_handle->m_deviceManager->isValidNode( node_id );
118 }
119
120 int
121 freebob_get_nb_devices_on_bus( freebob_handle_t freebob_handle )
122 {
123     return freebob_handle->m_deviceManager->getNbDevices();
124 }
125
126 int
127 freebob_get_device_node_id( freebob_handle_t freebob_handle, int device_nr )
128 {
129     return freebob_handle->m_deviceManager->getDeviceNodeId(device_nr);
130 }
131
132 int
133 freebob_set_samplerate( freebob_handle_t freebob_handle, int node_id, int samplerate )
134 {
135     AvDevice* avDevice = freebob_handle->m_deviceManager->getAvDevice( node_id );
136     if ( avDevice ) {
137         if ( avDevice->setSamplingFrequency( parseSampleRate( samplerate ) ) ) {
138             return freebob_handle->m_deviceManager->discover(0)? 1 : 0;
139         }
140     }
141     return 0;
142 }
143
144 void
145 freebob_free_connection_info( freebob_connection_info_t* connection_info )
146 {
147     if ( !connection_info ) {
148         return;
149     }
150
151     for ( int i = 0; i < connection_info->nb_connections; ++i ) {
152         freebob_free_connection_spec( connection_info->connections[i] );
153     }
154
155     free( connection_info->connections );
156     free( connection_info );
157 }
158
159 void
160 freebob_free_connection_spec( freebob_connection_spec_t* connection_spec )
161 {
162     if ( !connection_spec ) {
163         return;
164     }
165
166     freebob_free_stream_info( connection_spec->stream_info );
167     free( connection_spec );
168 }
169
170 void freebob_free_stream_info( freebob_stream_info_t* stream_info )
171 {
172     if ( !stream_info ) {
173         return;
174     }
175
176     for ( int i = 0; i < stream_info->nb_streams; ++i ) {
177         freebob_free_stream_spec( stream_info->streams[i] );
178     }
179
180     free(stream_info->streams);
181     free(stream_info);
182 }
183
184 void freebob_free_stream_spec( freebob_stream_spec_t* stream_spec )
185 {
186     if ( !stream_spec ) {
187         return;
188     }
189
190     free( stream_spec );
191 }
192
193 void
194 freebob_free_supported_stream_format_info( freebob_supported_stream_format_info_t* stream_info )
195 {
196     if ( !stream_info ) {
197         return;
198     }
199
200     for ( int i = 0; i < stream_info->nb_formats; ++i ) {
201         freebob_free_supported_stream_format_spec( stream_info->formats[i] );
202     }
203
204     free(stream_info->formats);
205     free(stream_info);
206 }
207
208 void
209 freebob_free_supported_stream_format_spec( freebob_supported_stream_format_spec_t* stream_spec )
210 {
211     if ( !stream_spec ) {
212         return;
213     }
214
215     free( stream_spec );
216 }
217
218 void
219 freebob_print_connection_info( freebob_connection_info_t* connection_info )
220 {
221     if ( !connection_info ) {
222         fprintf( stderr, "connection_info==NULL\n" );
223         return;
224     }
225
226     printf( "Direction:              %d (%s)\n\n", connection_info->direction,
227             connection_info->direction? "playback" : "capture" );
228
229     puts( "Connection Info" );
230     puts( "===============\n" );
231
232     printf("Number of connections:  %d\n\n",
233            connection_info->nb_connections );
234
235     for ( int i = 0; i < connection_info->nb_connections; ++i) {
236         freebob_connection_spec_t* connection_spec
237             = connection_info->connections[i];
238
239
240         if ( connection_spec ) {
241             printf( "  Connection %2d\n", i );
242             printf( "  -------------\n" );
243             printf( "    [%2d] Id:         %d\n", i, connection_spec->id );
244             printf( "    [%2d] Port:       %d\n", i, connection_spec->port );
245             printf( "    [%2d] Node:       %d\n", i, connection_spec->node );
246             printf( "    [%2d] Plug:       %d\n", i, connection_spec->plug );
247             printf( "    [%2d] Dimension:  %d\n", i, connection_spec->dimension );
248             printf( "    [%2d] Samplerate: %d\n", i, connection_spec->samplerate );
249             printf( "    [%2d] IsoChannel: %d\n", i, connection_spec->iso_channel );
250             printf( "    [%2d] IsMaster:   %d\n", i, connection_spec->is_master );
251
252             if ( connection_info->connections[i]->stream_info ) {
253                 printf("    [%2d] Number of stream infos: %d\n\n",
254                        i, connection_spec->stream_info->nb_streams );
255
256                 printf("    StreamId  Position Location Format Type DPort Name\n");
257                 printf("    --------------------------------------------------\n");
258
259                 for ( int j = 0;
260                       j < connection_spec->stream_info->nb_streams;
261                       ++j )
262                 {
263                     freebob_stream_spec_t* stream_spec
264                         = connection_spec->stream_info->streams[j];
265
266                     printf("    [%2d]:[%2d] "
267                            "0x%02x     0x%02x     0x%02x   0x%02x 0x%02x  %s\n",
268                            i, j,
269                            stream_spec->position,
270                            stream_spec->location,
271                            stream_spec->format,
272                            stream_spec->type,
273                            stream_spec->destination_port,
274                            stream_spec->name );
275                 }
276             }
277         }
278         printf( "\n" );
279     }
280
281     return;
282 }
283
284 void
285 freebob_print_supported_stream_format_info( freebob_supported_stream_format_info_t* stream_info )
286 {
287     if ( !stream_info ) {
288         fprintf( stderr, "stream_info==NULL\n" );
289         return;
290     }
291
292     printf( "Direction:              %d (%s)\n\n", stream_info->direction,
293             stream_info->direction? "playback" : "capture" );
294
295     printf( "Samplerate AudioChannels MidiChannels\n" );
296     printf( "-------------------------------------\n" );
297     for ( int i = 0; i < stream_info->nb_formats; ++i) {
298         freebob_supported_stream_format_spec_t* format_spec
299             = stream_info->formats[i];
300
301         if ( format_spec ) {
302             printf( "%05d      %02d            %02d\n",
303                     format_spec->samplerate,
304                     format_spec->nb_audio_channels,
305                     format_spec->nb_midi_channels );
306         }
307     }
308
309     return;
310 }
311
312 /* debug function */
313 void
314 freebob_print_xml_description( freebob_handle_t freebob_handle,
315                              int node_id,
316                              enum freebob_direction direction )
317 {
318     xmlDocPtr doc;
319     doc = freebob_handle->m_deviceManager->getXmlDescription();
320     if ( !doc ) {
321         debugFatal( "Could not get XML description\n" );
322         return;
323     }
324
325     xmlChar* xmlbuff;
326     int buffersize;
327     xmlDocDumpFormatMemory( doc, &xmlbuff, &buffersize, 1 );
328
329         printf("%s\n",(char *)xmlbuff);
330
331         xmlFree(xmlbuff);
332         xmlFree(doc);
333     return;
334 }
Note: See TracBrowser for help on using the browser.