VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/pulse_stubs.c@ 14683

Last change on this file since 14683 was 13510, checked in by vboxsync, 16 years ago

warning

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 KB
Line 
1/** @file
2 *
3 * Stubs for libpulse.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#include <iprt/assert.h>
23#include <iprt/ldr.h>
24#define LOG_GROUP LOG_GROUP_DEV_AUDIO
25#include <VBox/log.h>
26#include <VBox/err.h>
27
28#include <pulse/pulseaudio.h>
29
30#include "pulse_stubs.h"
31
32#define VBOX_PULSE_LIB "libpulse.so.0"
33
34#define PROXY_STUB(function, rettype, signature, shortsig) \
35void (*function ## _fn)(void); \
36rettype function signature \
37{ return ( (rettype (*) signature) function ## _fn ) shortsig; }
38
39#define PROXY_STUB_VOID(function, signature, shortsig) \
40void (*function ## _fn)(void); \
41void function signature \
42{ ( (void (*) signature) function ## _fn ) shortsig; }
43
44PROXY_STUB (pa_stream_connect_playback, int,
45 (pa_stream *s, const char *dev, const pa_buffer_attr *attr,
46 pa_stream_flags_t flags, pa_cvolume *volume, pa_stream *sync_stream),
47 (s, dev, attr, flags, volume, sync_stream))
48PROXY_STUB (pa_stream_connect_record, int,
49 (pa_stream *s, const char *dev, const pa_buffer_attr *attr,
50 pa_stream_flags_t flags),
51 (s, dev, attr, flags))
52PROXY_STUB (pa_stream_disconnect, int,
53 (pa_stream *s),
54 (s))
55PROXY_STUB (pa_stream_get_sample_spec, const pa_sample_spec*,
56 (pa_stream *s),
57 (s))
58PROXY_STUB_VOID(pa_stream_set_latency_update_callback,
59 (pa_stream *p, pa_stream_notify_cb_t cb, void *userdata),
60 (p, cb, userdata))
61PROXY_STUB (pa_stream_write, int,
62 (pa_stream *p, const void *data, size_t bytes, pa_free_cb_t free_cb,
63 int64_t offset, pa_seek_mode_t seek),
64 (p, data, bytes, free_cb, offset, seek))
65PROXY_STUB_VOID(pa_stream_unref,
66 (pa_stream *s),
67 (s))
68PROXY_STUB (pa_stream_get_state, pa_stream_state_t,
69 (pa_stream *p),
70 (p))
71PROXY_STUB_VOID(pa_stream_set_state_callback,
72 (pa_stream *s, pa_stream_notify_cb_t cb, void *userdata),
73 (s, cb, userdata))
74PROXY_STUB (pa_stream_flush, pa_operation*,
75 (pa_stream *s, pa_stream_success_cb_t cb, void *userdata),
76 (s, cb, userdata))
77PROXY_STUB (pa_stream_new, pa_stream*,
78 (pa_context *c, const char *name, const pa_sample_spec *ss,
79 const pa_channel_map *map),
80 (c, name, ss, map))
81PROXY_STUB (pa_stream_get_buffer_attr, const pa_buffer_attr*,
82 (pa_stream *s),
83 (s))
84PROXY_STUB (pa_stream_peek, int,
85 (pa_stream *p, const void **data, size_t *bytes),
86 (p, data, bytes))
87PROXY_STUB (pa_stream_cork, pa_operation*,
88 (pa_stream *s, int b, pa_stream_success_cb_t cb, void *userdata),
89 (s, b, cb, userdata))
90PROXY_STUB (pa_stream_drop, int,
91 (pa_stream *p),
92 (p))
93PROXY_STUB (pa_stream_trigger, pa_operation*,
94 (pa_stream *s, pa_stream_success_cb_t cb, void *userdata),
95 (s, cb, userdata))
96PROXY_STUB (pa_stream_writable_size, size_t,
97 (pa_stream *p),
98 (p))
99PROXY_STUB (pa_context_connect, int,
100 (pa_context *c, const char *server, pa_context_flags_t flags,
101 const pa_spawn_api *api),
102 (c, server, flags, api))
103PROXY_STUB_VOID(pa_context_disconnect,
104 (pa_context *c),
105 (c))
106PROXY_STUB (pa_context_get_state, pa_context_state_t,
107 (pa_context *c),
108 (c))
109PROXY_STUB_VOID(pa_context_unref,
110 (pa_context *c),
111 (c))
112PROXY_STUB (pa_context_errno, int,
113 (pa_context *c),
114 (c))
115PROXY_STUB (pa_context_new, pa_context*,
116 (pa_mainloop_api *mainloop, const char *name),
117 (mainloop, name))
118PROXY_STUB_VOID(pa_context_set_state_callback,
119 (pa_context *c, pa_context_notify_cb_t cb, void *userdata),
120 (c, cb, userdata))
121PROXY_STUB_VOID(pa_threaded_mainloop_stop,
122 (pa_threaded_mainloop *m),
123 (m))
124PROXY_STUB (pa_threaded_mainloop_get_api, pa_mainloop_api*,
125 (pa_threaded_mainloop *m),
126 (m))
127PROXY_STUB_VOID(pa_threaded_mainloop_free,
128 (pa_threaded_mainloop* m),
129 (m))
130PROXY_STUB_VOID(pa_threaded_mainloop_signal,
131 (pa_threaded_mainloop *m, int wait_for_accept),
132 (m, wait_for_accept))
133PROXY_STUB_VOID(pa_threaded_mainloop_unlock,
134 (pa_threaded_mainloop *m),
135 (m))
136PROXY_STUB (pa_threaded_mainloop_new, pa_threaded_mainloop *,
137 (void),
138 ())
139PROXY_STUB_VOID(pa_threaded_mainloop_wait,
140 (pa_threaded_mainloop *m),
141 (m))
142PROXY_STUB (pa_threaded_mainloop_start, int,
143 (pa_threaded_mainloop *m),
144 (m))
145PROXY_STUB_VOID(pa_threaded_mainloop_lock,
146 (pa_threaded_mainloop *m),
147 (m))
148PROXY_STUB (pa_bytes_per_second, size_t,
149 (const pa_sample_spec *spec),
150 (spec))
151PROXY_STUB (pa_sample_format_to_string, const char*,
152 (pa_sample_format_t f),
153 (f))
154PROXY_STUB (pa_sample_spec_valid, int,
155 (const pa_sample_spec *spec),
156 (spec))
157PROXY_STUB (pa_channel_map_init_auto, pa_channel_map*,
158 (pa_channel_map *m, unsigned channels, pa_channel_map_def_t def),
159 (m, channels, def))
160PROXY_STUB_VOID(pa_operation_unref,
161 (pa_operation *o),
162 (o))
163PROXY_STUB (pa_strerror, const char*,
164 (int error),
165 (error))
166
167
168typedef struct
169{
170 const char *name;
171 void (**fn)(void);
172} SHARED_FUNC;
173
174#define ELEMENT(s) { #s , & s ## _fn }
175static SHARED_FUNC SharedFuncs[] =
176{
177 ELEMENT(pa_stream_connect_playback),
178 ELEMENT(pa_stream_connect_record),
179 ELEMENT(pa_stream_disconnect),
180 ELEMENT(pa_stream_get_sample_spec),
181 ELEMENT(pa_stream_set_latency_update_callback),
182 ELEMENT(pa_stream_write),
183 ELEMENT(pa_stream_unref),
184 ELEMENT(pa_stream_get_state),
185 ELEMENT(pa_stream_set_state_callback),
186 ELEMENT(pa_stream_flush),
187 ELEMENT(pa_stream_new),
188 ELEMENT(pa_stream_get_buffer_attr),
189 ELEMENT(pa_stream_peek),
190 ELEMENT(pa_stream_cork),
191 ELEMENT(pa_stream_drop),
192 ELEMENT(pa_stream_trigger),
193 ELEMENT(pa_stream_writable_size),
194 ELEMENT(pa_context_connect),
195 ELEMENT(pa_context_disconnect),
196 ELEMENT(pa_context_get_state),
197 ELEMENT(pa_context_unref),
198 ELEMENT(pa_context_errno),
199 ELEMENT(pa_context_new),
200 ELEMENT(pa_context_set_state_callback),
201 ELEMENT(pa_threaded_mainloop_stop),
202 ELEMENT(pa_threaded_mainloop_get_api),
203 ELEMENT(pa_threaded_mainloop_free),
204 ELEMENT(pa_threaded_mainloop_signal),
205 ELEMENT(pa_threaded_mainloop_unlock),
206 ELEMENT(pa_threaded_mainloop_new),
207 ELEMENT(pa_threaded_mainloop_wait),
208 ELEMENT(pa_threaded_mainloop_start),
209 ELEMENT(pa_threaded_mainloop_lock),
210 ELEMENT(pa_bytes_per_second),
211 ELEMENT(pa_sample_format_to_string),
212 ELEMENT(pa_sample_spec_valid),
213 ELEMENT(pa_channel_map_init_auto),
214 ELEMENT(pa_operation_unref),
215 ELEMENT(pa_strerror),
216};
217#undef ELEMENT
218
219/**
220 * Try to dynamically load the PulseAudio libraries. This function is not
221 * thread-safe, and should be called before attempting to use any of the
222 * PulseAudio functions.
223 *
224 * @returns iprt status code
225 */
226int audioLoadPulseLib(void)
227{
228 int rc = VINF_SUCCESS;
229 unsigned i;
230 static enum { NO = 0, YES, FAIL } isLibLoaded = NO;
231 RTLDRMOD hLib;
232
233 LogFlowFunc(("\n"));
234 /* If this is not NO then the function has obviously been called twice,
235 which is likely to be a bug. */
236 if (NO != isLibLoaded)
237 {
238 AssertMsgFailed(("isLibLoaded == %s\n", YES == isLibLoaded ? "YES" : "NO"));
239 return YES == isLibLoaded ? VINF_SUCCESS : VERR_NOT_SUPPORTED;
240 }
241 isLibLoaded = FAIL;
242 rc = RTLdrLoad(VBOX_PULSE_LIB, &hLib);
243 if (RT_FAILURE(rc))
244 {
245 LogRelFunc(("Failed to load library %s\n", VBOX_PULSE_LIB));
246 return rc;
247 }
248 for (i=0; i<RT_ELEMENTS(SharedFuncs); i++)
249 {
250 rc = RTLdrGetSymbol(hLib, SharedFuncs[i].name, (void**)SharedFuncs[i].fn);
251 if (RT_FAILURE(rc))
252 return rc;
253 }
254 isLibLoaded = YES;
255 return rc;
256}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette