VirtualBox

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

Last change on this file since 49893 was 45136, checked in by vboxsync, 12 years ago

Devices/Audio: mangle symbols of libasound and libpulse, otherwise they can be resolved by dynamic libraries if -fvisibility is not supported

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.1 KB
Line 
1/* $Id: pulse_stubs.c 45136 2013-03-22 10:22:57Z vboxsync $ */
2/** @file
3 * Stubs for libpulse.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
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
18#include <iprt/assert.h>
19#include <iprt/ldr.h>
20#define LOG_GROUP LOG_GROUP_DEV_AUDIO
21#include <VBox/log.h>
22#include <VBox/err.h>
23
24#include <pulse/pulseaudio.h>
25
26#include "pulse_stubs.h"
27
28#define VBOX_PULSE_LIB "libpulse.so.0"
29
30#define PROXY_STUB(function, rettype, signature, shortsig) \
31 static rettype (*g_pfn_ ## function) signature; \
32 \
33 rettype VBox_##function signature; \
34 rettype VBox_##function signature \
35 { \
36 return g_pfn_ ## function shortsig; \
37 }
38
39#define PROXY_STUB_VOID(function, signature, shortsig) \
40 static void (*g_pfn_ ## function) signature; \
41 \
42 void VBox_##function signature; \
43 void VBox_##function signature \
44 { \
45 g_pfn_ ## function shortsig; \
46 }
47
48#if PA_PROTOCOL_VERSION >= 16
49PROXY_STUB (pa_stream_connect_playback, int,
50 (pa_stream *s, const char *dev, const pa_buffer_attr *attr,
51 pa_stream_flags_t flags, const pa_cvolume *volume, pa_stream *sync_stream),
52 (s, dev, attr, flags, volume, sync_stream))
53#else
54PROXY_STUB (pa_stream_connect_playback, int,
55 (pa_stream *s, const char *dev, const pa_buffer_attr *attr,
56 pa_stream_flags_t flags, pa_cvolume *volume, pa_stream *sync_stream),
57 (s, dev, attr, flags, volume, sync_stream))
58#endif
59PROXY_STUB (pa_stream_connect_record, int,
60 (pa_stream *s, const char *dev, const pa_buffer_attr *attr,
61 pa_stream_flags_t flags),
62 (s, dev, attr, flags))
63PROXY_STUB (pa_stream_disconnect, int,
64 (pa_stream *s),
65 (s))
66PROXY_STUB (pa_stream_get_sample_spec, const pa_sample_spec*,
67 (pa_stream *s),
68 (s))
69PROXY_STUB_VOID(pa_stream_set_latency_update_callback,
70 (pa_stream *p, pa_stream_notify_cb_t cb, void *userdata),
71 (p, cb, userdata))
72PROXY_STUB (pa_stream_write, int,
73 (pa_stream *p, const void *data, size_t bytes, pa_free_cb_t free_cb,
74 int64_t offset, pa_seek_mode_t seek),
75 (p, data, bytes, free_cb, offset, seek))
76PROXY_STUB_VOID(pa_stream_unref,
77 (pa_stream *s),
78 (s))
79PROXY_STUB (pa_stream_get_state, pa_stream_state_t,
80 (pa_stream *p),
81 (p))
82PROXY_STUB_VOID(pa_stream_set_state_callback,
83 (pa_stream *s, pa_stream_notify_cb_t cb, void *userdata),
84 (s, cb, userdata))
85PROXY_STUB (pa_stream_flush, pa_operation*,
86 (pa_stream *s, pa_stream_success_cb_t cb, void *userdata),
87 (s, cb, userdata))
88PROXY_STUB (pa_stream_drain, pa_operation*,
89 (pa_stream *s, pa_stream_success_cb_t cb, void *userdata),
90 (s, cb, userdata))
91PROXY_STUB (pa_stream_trigger, pa_operation*,
92 (pa_stream *s, pa_stream_success_cb_t cb, void *userdata),
93 (s, cb, userdata))
94PROXY_STUB (pa_stream_new, pa_stream*,
95 (pa_context *c, const char *name, const pa_sample_spec *ss,
96 const pa_channel_map *map),
97 (c, name, ss, map))
98PROXY_STUB (pa_stream_get_buffer_attr, const pa_buffer_attr*,
99 (pa_stream *s),
100 (s))
101PROXY_STUB (pa_stream_peek, int,
102 (pa_stream *p, const void **data, size_t *bytes),
103 (p, data, bytes))
104PROXY_STUB (pa_stream_cork, pa_operation*,
105 (pa_stream *s, int b, pa_stream_success_cb_t cb, void *userdata),
106 (s, b, cb, userdata))
107PROXY_STUB (pa_stream_drop, int,
108 (pa_stream *p),
109 (p))
110PROXY_STUB (pa_stream_writable_size, size_t,
111 (pa_stream *p),
112 (p))
113PROXY_STUB (pa_context_connect, int,
114 (pa_context *c, const char *server, pa_context_flags_t flags,
115 const pa_spawn_api *api),
116 (c, server, flags, api))
117PROXY_STUB_VOID(pa_context_disconnect,
118 (pa_context *c),
119 (c))
120PROXY_STUB (pa_context_get_state, pa_context_state_t,
121 (pa_context *c),
122 (c))
123PROXY_STUB_VOID(pa_context_unref,
124 (pa_context *c),
125 (c))
126PROXY_STUB (pa_context_errno, int,
127 (pa_context *c),
128 (c))
129PROXY_STUB (pa_context_new, pa_context*,
130 (pa_mainloop_api *mainloop, const char *name),
131 (mainloop, name))
132PROXY_STUB_VOID(pa_context_set_state_callback,
133 (pa_context *c, pa_context_notify_cb_t cb, void *userdata),
134 (c, cb, userdata))
135PROXY_STUB_VOID(pa_threaded_mainloop_stop,
136 (pa_threaded_mainloop *m),
137 (m))
138PROXY_STUB (pa_threaded_mainloop_get_api, pa_mainloop_api*,
139 (pa_threaded_mainloop *m),
140 (m))
141PROXY_STUB_VOID(pa_threaded_mainloop_free,
142 (pa_threaded_mainloop* m),
143 (m))
144PROXY_STUB_VOID(pa_threaded_mainloop_signal,
145 (pa_threaded_mainloop *m, int wait_for_accept),
146 (m, wait_for_accept))
147PROXY_STUB_VOID(pa_threaded_mainloop_unlock,
148 (pa_threaded_mainloop *m),
149 (m))
150PROXY_STUB (pa_threaded_mainloop_new, pa_threaded_mainloop *,
151 (void),
152 ())
153PROXY_STUB_VOID(pa_threaded_mainloop_wait,
154 (pa_threaded_mainloop *m),
155 (m))
156PROXY_STUB (pa_threaded_mainloop_start, int,
157 (pa_threaded_mainloop *m),
158 (m))
159PROXY_STUB_VOID(pa_threaded_mainloop_lock,
160 (pa_threaded_mainloop *m),
161 (m))
162PROXY_STUB (pa_bytes_per_second, size_t,
163 (const pa_sample_spec *spec),
164 (spec))
165PROXY_STUB (pa_frame_size, size_t,
166 (const pa_sample_spec *spec),
167 (spec))
168PROXY_STUB (pa_sample_format_to_string, const char*,
169 (pa_sample_format_t f),
170 (f))
171PROXY_STUB (pa_sample_spec_valid, int,
172 (const pa_sample_spec *spec),
173 (spec))
174PROXY_STUB (pa_channel_map_init_auto, pa_channel_map*,
175 (pa_channel_map *m, unsigned channels, pa_channel_map_def_t def),
176 (m, channels, def))
177PROXY_STUB_VOID(pa_operation_unref,
178 (pa_operation *o),
179 (o))
180PROXY_STUB (pa_operation_get_state, pa_operation_state_t,
181 (pa_operation *o),
182 (o))
183PROXY_STUB_VOID(pa_operation_cancel,
184 (pa_operation *o),
185 (o))
186PROXY_STUB (pa_strerror, const char*,
187 (int error),
188 (error))
189PROXY_STUB (pa_stream_readable_size, size_t,
190 (pa_stream *p),
191 (p))
192
193
194typedef struct
195{
196 const char *name;
197 void (**fn)(void);
198} SHARED_FUNC;
199
200#define ELEMENT(function) { #function , (void (**)(void)) & g_pfn_ ## function }
201static SHARED_FUNC SharedFuncs[] =
202{
203 ELEMENT(pa_stream_connect_playback),
204 ELEMENT(pa_stream_connect_record),
205 ELEMENT(pa_stream_disconnect),
206 ELEMENT(pa_stream_get_sample_spec),
207 ELEMENT(pa_stream_set_latency_update_callback),
208 ELEMENT(pa_stream_write),
209 ELEMENT(pa_stream_unref),
210 ELEMENT(pa_stream_get_state),
211 ELEMENT(pa_stream_set_state_callback),
212 ELEMENT(pa_stream_flush),
213 ELEMENT(pa_stream_drain),
214 ELEMENT(pa_stream_trigger),
215 ELEMENT(pa_stream_new),
216 ELEMENT(pa_stream_get_buffer_attr),
217 ELEMENT(pa_stream_peek),
218 ELEMENT(pa_stream_cork),
219 ELEMENT(pa_stream_drop),
220 ELEMENT(pa_stream_writable_size),
221 ELEMENT(pa_context_connect),
222 ELEMENT(pa_context_disconnect),
223 ELEMENT(pa_context_get_state),
224 ELEMENT(pa_context_unref),
225 ELEMENT(pa_context_errno),
226 ELEMENT(pa_context_new),
227 ELEMENT(pa_context_set_state_callback),
228 ELEMENT(pa_threaded_mainloop_stop),
229 ELEMENT(pa_threaded_mainloop_get_api),
230 ELEMENT(pa_threaded_mainloop_free),
231 ELEMENT(pa_threaded_mainloop_signal),
232 ELEMENT(pa_threaded_mainloop_unlock),
233 ELEMENT(pa_threaded_mainloop_new),
234 ELEMENT(pa_threaded_mainloop_wait),
235 ELEMENT(pa_threaded_mainloop_start),
236 ELEMENT(pa_threaded_mainloop_lock),
237 ELEMENT(pa_bytes_per_second),
238 ELEMENT(pa_frame_size),
239 ELEMENT(pa_sample_format_to_string),
240 ELEMENT(pa_sample_spec_valid),
241 ELEMENT(pa_channel_map_init_auto),
242 ELEMENT(pa_operation_unref),
243 ELEMENT(pa_operation_get_state),
244 ELEMENT(pa_operation_cancel),
245 ELEMENT(pa_strerror),
246 ELEMENT(pa_stream_readable_size)
247};
248#undef ELEMENT
249
250/**
251 * Try to dynamically load the PulseAudio libraries. This function is not
252 * thread-safe, and should be called before attempting to use any of the
253 * PulseAudio functions.
254 *
255 * @returns iprt status code
256 */
257int audioLoadPulseLib(void)
258{
259 int rc = VINF_SUCCESS;
260 unsigned i;
261 static enum { NO = 0, YES, FAIL } isLibLoaded = NO;
262 RTLDRMOD hLib;
263
264 LogFlowFunc(("\n"));
265 /* If this is not NO then the function has obviously been called twice,
266 which is likely to be a bug. */
267 if (NO != isLibLoaded)
268 {
269 AssertMsgFailed(("isLibLoaded == %s\n", YES == isLibLoaded ? "YES" : "NO"));
270 return YES == isLibLoaded ? VINF_SUCCESS : VERR_NOT_SUPPORTED;
271 }
272 isLibLoaded = FAIL;
273 rc = RTLdrLoad(VBOX_PULSE_LIB, &hLib);
274 if (RT_FAILURE(rc))
275 {
276 LogRelFunc(("Failed to load library %s\n", VBOX_PULSE_LIB));
277 return rc;
278 }
279 for (i=0; i<RT_ELEMENTS(SharedFuncs); i++)
280 {
281 rc = RTLdrGetSymbol(hLib, SharedFuncs[i].name, (void**)SharedFuncs[i].fn);
282 if (RT_FAILURE(rc))
283 return rc;
284 }
285 isLibLoaded = YES;
286 return rc;
287}
288
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