VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio_old/pulse_stubs.c@ 62518

Last change on this file since 62518 was 62518, checked in by vboxsync, 8 years ago

(C) 2016

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