VirtualBox

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

Last change on this file since 34828 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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