VirtualBox

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

Last change on this file since 6127 was 6127, checked in by vboxsync, 17 years ago

export PulseAudio backend

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