VirtualBox

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

Last change on this file since 87854 was 86496, checked in by vboxsync, 4 years ago

Devices/pulse_stubs.c: Use RTLdrLoadSystemEx w/ RTLDRLOAD_FLAGS_NO_UNLOAD so it doesn't get flagged as a leak. Cleaned up the code a little. bugref:9841

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.6 KB
Line 
1/* $Id: pulse_stubs.c 86496 2020-10-08 13:48:53Z vboxsync $ */
2/** @file
3 * Stubs for libpulse.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_DRV_HOST_AUDIO
23#include <iprt/assert.h>
24#include <iprt/ldr.h>
25#include <VBox/log.h>
26#include <iprt/err.h>
27
28#include <pulse/pulseaudio.h>
29
30#include "pulse_stubs.h"
31
32
33/*********************************************************************************************************************************
34* Defined Constants And Macros *
35*********************************************************************************************************************************/
36#define VBOX_PULSE_LIB "libpulse.so.0"
37
38#define PROXY_STUB(function, rettype, signature, shortsig) \
39 static rettype (*g_pfn_ ## function) signature; \
40 \
41 rettype VBox_##function signature; \
42 rettype VBox_##function signature \
43 { \
44 return g_pfn_ ## function shortsig; \
45 }
46
47#define PROXY_STUB_VOID(function, signature, shortsig) \
48 static void (*g_pfn_ ## function) signature; \
49 \
50 void VBox_##function signature; \
51 void VBox_##function signature \
52 { \
53 g_pfn_ ## function shortsig; \
54 }
55
56PROXY_STUB (pa_bytes_per_second, size_t,
57 (const pa_sample_spec *spec),
58 (spec))
59PROXY_STUB (pa_bytes_to_usec, pa_usec_t,
60 (uint64_t l, const pa_sample_spec *spec),
61 (l, spec))
62PROXY_STUB (pa_channel_map_init_auto, pa_channel_map*,
63 (pa_channel_map *m, unsigned channels, pa_channel_map_def_t def),
64 (m, channels, def))
65
66PROXY_STUB (pa_context_connect, int,
67 (pa_context *c, const char *server, pa_context_flags_t flags,
68 const pa_spawn_api *api),
69 (c, server, flags, api))
70PROXY_STUB_VOID(pa_context_disconnect,
71 (pa_context *c),
72 (c))
73PROXY_STUB (pa_context_get_server_info, pa_operation*,
74 (pa_context *c, pa_server_info_cb_t cb, void *userdata),
75 (c, cb, userdata))
76PROXY_STUB (pa_context_get_sink_info_by_name, pa_operation*,
77 (pa_context *c, const char *name, pa_sink_info_cb_t cb, void *userdata),
78 (c, name, cb, userdata))
79PROXY_STUB (pa_context_get_source_info_by_name, pa_operation*,
80 (pa_context *c, const char *name, pa_source_info_cb_t cb, void *userdata),
81 (c, name, cb, userdata))
82PROXY_STUB (pa_context_get_state, pa_context_state_t,
83 (pa_context *c),
84 (c))
85PROXY_STUB_VOID(pa_context_unref,
86 (pa_context *c),
87 (c))
88PROXY_STUB (pa_context_errno, int,
89 (pa_context *c),
90 (c))
91PROXY_STUB (pa_context_new, pa_context*,
92 (pa_mainloop_api *mainloop, const char *name),
93 (mainloop, name))
94PROXY_STUB_VOID(pa_context_set_state_callback,
95 (pa_context *c, pa_context_notify_cb_t cb, void *userdata),
96 (c, cb, userdata))
97
98PROXY_STUB (pa_frame_size, size_t,
99 (const pa_sample_spec *spec),
100 (spec))
101PROXY_STUB (pa_get_library_version, const char *, (void), ())
102PROXY_STUB_VOID(pa_operation_unref,
103 (pa_operation *o),
104 (o))
105PROXY_STUB (pa_operation_get_state, pa_operation_state_t,
106 (pa_operation *o),
107 (o))
108PROXY_STUB_VOID(pa_operation_cancel,
109 (pa_operation *o),
110 (o))
111
112PROXY_STUB (pa_rtclock_now, pa_usec_t,
113 (void),
114 ())
115PROXY_STUB (pa_sample_format_to_string, const char*,
116 (pa_sample_format_t f),
117 (f))
118PROXY_STUB (pa_sample_spec_valid, int,
119 (const pa_sample_spec *spec),
120 (spec))
121PROXY_STUB (pa_strerror, const char*,
122 (int error),
123 (error))
124
125#if PA_PROTOCOL_VERSION >= 16
126PROXY_STUB (pa_stream_connect_playback, int,
127 (pa_stream *s, const char *dev, const pa_buffer_attr *attr,
128 pa_stream_flags_t flags, const pa_cvolume *volume, pa_stream *sync_stream),
129 (s, dev, attr, flags, volume, sync_stream))
130#else
131PROXY_STUB (pa_stream_connect_playback, int,
132 (pa_stream *s, const char *dev, const pa_buffer_attr *attr,
133 pa_stream_flags_t flags, pa_cvolume *volume, pa_stream *sync_stream),
134 (s, dev, attr, flags, volume, sync_stream))
135#endif
136PROXY_STUB (pa_stream_connect_record, int,
137 (pa_stream *s, const char *dev, const pa_buffer_attr *attr,
138 pa_stream_flags_t flags),
139 (s, dev, attr, flags))
140PROXY_STUB (pa_stream_disconnect, int,
141 (pa_stream *s),
142 (s))
143PROXY_STUB (pa_stream_get_sample_spec, const pa_sample_spec*,
144 (pa_stream *s),
145 (s))
146PROXY_STUB_VOID(pa_stream_set_latency_update_callback,
147 (pa_stream *p, pa_stream_notify_cb_t cb, void *userdata),
148 (p, cb, userdata))
149PROXY_STUB (pa_stream_write, int,
150 (pa_stream *p, const void *data, size_t bytes, pa_free_cb_t free_cb,
151 int64_t offset, pa_seek_mode_t seek),
152 (p, data, bytes, free_cb, offset, seek))
153PROXY_STUB_VOID(pa_stream_unref,
154 (pa_stream *s),
155 (s))
156PROXY_STUB (pa_stream_get_state, pa_stream_state_t,
157 (pa_stream *p),
158 (p))
159PROXY_STUB (pa_stream_get_latency, int,
160 (pa_stream *s, pa_usec_t *r_usec, int *negative),
161 (s, r_usec, negative))
162PROXY_STUB (pa_stream_get_timing_info, pa_timing_info*,
163 (pa_stream *s),
164 (s))
165PROXY_STUB (pa_stream_readable_size, size_t,
166 (pa_stream *p),
167 (p))
168PROXY_STUB (pa_stream_set_buffer_attr, pa_operation *,
169 (pa_stream *s, const pa_buffer_attr *attr, pa_stream_success_cb_t cb, void *userdata),
170 (s, attr, cb, userdata))
171PROXY_STUB_VOID(pa_stream_set_state_callback,
172 (pa_stream *s, pa_stream_notify_cb_t cb, void *userdata),
173 (s, cb, userdata))
174PROXY_STUB_VOID(pa_stream_set_underflow_callback,
175 (pa_stream *s, pa_stream_notify_cb_t cb, void *userdata),
176 (s, cb, userdata))
177PROXY_STUB_VOID(pa_stream_set_overflow_callback,
178 (pa_stream *s, pa_stream_notify_cb_t cb, void *userdata),
179 (s, cb, userdata))
180PROXY_STUB_VOID(pa_stream_set_write_callback,
181 (pa_stream *s, pa_stream_request_cb_t cb, void *userdata),
182 (s, cb, userdata))
183PROXY_STUB (pa_stream_flush, pa_operation*,
184 (pa_stream *s, pa_stream_success_cb_t cb, void *userdata),
185 (s, cb, userdata))
186PROXY_STUB (pa_stream_drain, pa_operation*,
187 (pa_stream *s, pa_stream_success_cb_t cb, void *userdata),
188 (s, cb, userdata))
189PROXY_STUB (pa_stream_trigger, pa_operation*,
190 (pa_stream *s, pa_stream_success_cb_t cb, void *userdata),
191 (s, cb, userdata))
192PROXY_STUB (pa_stream_new, pa_stream*,
193 (pa_context *c, const char *name, const pa_sample_spec *ss,
194 const pa_channel_map *map),
195 (c, name, ss, map))
196PROXY_STUB (pa_stream_get_buffer_attr, const pa_buffer_attr*,
197 (pa_stream *s),
198 (s))
199PROXY_STUB (pa_stream_peek, int,
200 (pa_stream *p, const void **data, size_t *bytes),
201 (p, data, bytes))
202PROXY_STUB (pa_stream_cork, pa_operation*,
203 (pa_stream *s, int b, pa_stream_success_cb_t cb, void *userdata),
204 (s, b, cb, userdata))
205PROXY_STUB (pa_stream_drop, int,
206 (pa_stream *p),
207 (p))
208PROXY_STUB (pa_stream_writable_size, size_t,
209 (pa_stream *p),
210 (p))
211
212PROXY_STUB_VOID(pa_threaded_mainloop_stop,
213 (pa_threaded_mainloop *m),
214 (m))
215PROXY_STUB (pa_threaded_mainloop_get_api, pa_mainloop_api*,
216 (pa_threaded_mainloop *m),
217 (m))
218PROXY_STUB_VOID(pa_threaded_mainloop_free,
219 (pa_threaded_mainloop* m),
220 (m))
221PROXY_STUB_VOID(pa_threaded_mainloop_signal,
222 (pa_threaded_mainloop *m, int wait_for_accept),
223 (m, wait_for_accept))
224PROXY_STUB_VOID(pa_threaded_mainloop_unlock,
225 (pa_threaded_mainloop *m),
226 (m))
227PROXY_STUB (pa_threaded_mainloop_new, pa_threaded_mainloop *,
228 (void),
229 ())
230PROXY_STUB_VOID(pa_threaded_mainloop_wait,
231 (pa_threaded_mainloop *m),
232 (m))
233PROXY_STUB (pa_threaded_mainloop_start, int,
234 (pa_threaded_mainloop *m),
235 (m))
236PROXY_STUB_VOID(pa_threaded_mainloop_lock,
237 (pa_threaded_mainloop *m),
238 (m))
239
240PROXY_STUB (pa_usec_to_bytes, size_t,
241 (pa_usec_t t, const pa_sample_spec *spec),
242 (t, spec))
243
244#define FUNC_ENTRY(function) { #function , (void (**)(void)) & g_pfn_ ## function }
245static struct
246{
247 const char *pszName;
248 void (**pfn)(void);
249} const g_aImportedFunctions[] =
250{
251 FUNC_ENTRY(pa_bytes_per_second),
252 FUNC_ENTRY(pa_bytes_to_usec),
253 FUNC_ENTRY(pa_channel_map_init_auto),
254
255 FUNC_ENTRY(pa_context_connect),
256 FUNC_ENTRY(pa_context_disconnect),
257 FUNC_ENTRY(pa_context_get_server_info),
258 FUNC_ENTRY(pa_context_get_sink_info_by_name),
259 FUNC_ENTRY(pa_context_get_source_info_by_name),
260 FUNC_ENTRY(pa_context_get_state),
261 FUNC_ENTRY(pa_context_unref),
262 FUNC_ENTRY(pa_context_errno),
263 FUNC_ENTRY(pa_context_new),
264 FUNC_ENTRY(pa_context_set_state_callback),
265
266 FUNC_ENTRY(pa_frame_size),
267 FUNC_ENTRY(pa_get_library_version),
268 FUNC_ENTRY(pa_operation_unref),
269 FUNC_ENTRY(pa_operation_get_state),
270 FUNC_ENTRY(pa_operation_cancel),
271 FUNC_ENTRY(pa_rtclock_now),
272 FUNC_ENTRY(pa_sample_format_to_string),
273 FUNC_ENTRY(pa_sample_spec_valid),
274 FUNC_ENTRY(pa_strerror),
275
276 FUNC_ENTRY(pa_stream_connect_playback),
277 FUNC_ENTRY(pa_stream_connect_record),
278 FUNC_ENTRY(pa_stream_disconnect),
279 FUNC_ENTRY(pa_stream_get_sample_spec),
280 FUNC_ENTRY(pa_stream_set_latency_update_callback),
281 FUNC_ENTRY(pa_stream_write),
282 FUNC_ENTRY(pa_stream_unref),
283 FUNC_ENTRY(pa_stream_get_state),
284 FUNC_ENTRY(pa_stream_get_latency),
285 FUNC_ENTRY(pa_stream_get_timing_info),
286 FUNC_ENTRY(pa_stream_readable_size),
287 FUNC_ENTRY(pa_stream_set_buffer_attr),
288 FUNC_ENTRY(pa_stream_set_state_callback),
289 FUNC_ENTRY(pa_stream_set_underflow_callback),
290 FUNC_ENTRY(pa_stream_set_overflow_callback),
291 FUNC_ENTRY(pa_stream_set_write_callback),
292 FUNC_ENTRY(pa_stream_flush),
293 FUNC_ENTRY(pa_stream_drain),
294 FUNC_ENTRY(pa_stream_trigger),
295 FUNC_ENTRY(pa_stream_new),
296 FUNC_ENTRY(pa_stream_get_buffer_attr),
297 FUNC_ENTRY(pa_stream_peek),
298 FUNC_ENTRY(pa_stream_cork),
299 FUNC_ENTRY(pa_stream_drop),
300 FUNC_ENTRY(pa_stream_writable_size),
301
302 FUNC_ENTRY(pa_threaded_mainloop_stop),
303 FUNC_ENTRY(pa_threaded_mainloop_get_api),
304 FUNC_ENTRY(pa_threaded_mainloop_free),
305 FUNC_ENTRY(pa_threaded_mainloop_signal),
306 FUNC_ENTRY(pa_threaded_mainloop_unlock),
307 FUNC_ENTRY(pa_threaded_mainloop_new),
308 FUNC_ENTRY(pa_threaded_mainloop_wait),
309 FUNC_ENTRY(pa_threaded_mainloop_start),
310 FUNC_ENTRY(pa_threaded_mainloop_lock),
311
312 FUNC_ENTRY(pa_usec_to_bytes)
313};
314#undef FUNC_ENTRY
315
316/**
317 * Try to dynamically load the PulseAudio libraries. This function is not
318 * thread-safe, and should be called before attempting to use any of the
319 * PulseAudio functions.
320 *
321 * @returns iprt status code
322 */
323int audioLoadPulseLib(void)
324{
325 static volatile int g_rc = VERR_IPE_UNINITIALIZED_STATUS;
326 RTLDRMOD hLib;
327 int rc;
328
329 LogFlowFunc(("\n"));
330
331 /* If this is not VERR_IPE_UNINITIALIZED_STATUS then the function has
332 obviously been called twice, which is likely to be a bug. */
333 rc = g_rc;
334 AssertMsgReturn(rc == VERR_IPE_UNINITIALIZED_STATUS, ("g_rc=%Rrc\n", rc), rc);
335
336 rc = RTLdrLoadSystemEx(VBOX_PULSE_LIB, RTLDRLOAD_FLAGS_NO_UNLOAD, &hLib);
337 if (RT_SUCCESS(rc))
338 {
339 unsigned i;
340 for (i = 0; i < RT_ELEMENTS(g_aImportedFunctions); i++)
341 {
342 rc = RTLdrGetSymbol(hLib, g_aImportedFunctions[i].pszName, (void **)g_aImportedFunctions[i].pfn);
343 if (RT_FAILURE(rc))
344 {
345 LogRelFunc(("Failed to resolve function #%u: '%s' (%Rrc)\n", i, g_aImportedFunctions[i].pszName, rc));
346 break;
347 }
348 }
349 }
350 else
351 LogRelFunc(("Failed to load library %s: %Rrc\n", VBOX_PULSE_LIB, rc));
352 g_rc = rc;
353 return rc;
354}
355
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