VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/alsa_stubs.c@ 73529

Last change on this file since 73529 was 73161, checked in by vboxsync, 6 years ago

Audio/ALSA: Re-ordered / cleaned up stubs and mangling. No new functions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1/* $Id: alsa_stubs.c 73161 2018-07-16 16:24:17Z vboxsync $ */
2/** @file
3 * Stubs for libasound.
4 */
5
6/*
7 * Copyright (C) 2006-2018 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 <alsa/asoundlib.h>
24
25#include "alsa_stubs.h"
26
27#define VBOX_ALSA_LIB "libasound.so.2"
28
29#define PROXY_STUB(function, rettype, signature, shortsig) \
30 static rettype (*pfn_ ## function) signature; \
31 \
32 rettype VBox_##function signature; \
33 rettype VBox_##function signature \
34 { \
35 return pfn_ ## function shortsig; \
36 }
37
38PROXY_STUB(snd_lib_error_set_handler, int, (snd_lib_error_handler_t handler),
39 (handler))
40PROXY_STUB(snd_strerror, const char *, (int errnum), (errnum))
41
42PROXY_STUB(snd_device_name_hint, int,
43 (int card, const char *iface, void ***hints),
44 (card, iface, hints))
45PROXY_STUB(snd_device_name_free_hint, int,
46 (void **hints),
47 (hints))
48PROXY_STUB(snd_device_name_get_hint, char *,
49 (const void *hint, const char *id),
50 (hint, id))
51
52/*
53 * PCM
54 */
55
56PROXY_STUB(snd_pcm_avail_update, snd_pcm_sframes_t, (snd_pcm_t *pcm),
57 (pcm))
58PROXY_STUB(snd_pcm_close, int, (snd_pcm_t *pcm), (pcm))
59PROXY_STUB(snd_pcm_delay, int, (snd_pcm_t *pcm, snd_pcm_sframes_t *frames),
60 (pcm, frames))
61PROXY_STUB(snd_pcm_nonblock, int, (snd_pcm_t *pcm, int *onoff),
62 (pcm, onoff))
63PROXY_STUB(snd_pcm_drain, int, (snd_pcm_t *pcm),
64 (pcm))
65PROXY_STUB(snd_pcm_drop, int, (snd_pcm_t *pcm), (pcm))
66PROXY_STUB(snd_pcm_open, int,
67 (snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode),
68 (pcm, name, stream, mode))
69PROXY_STUB(snd_pcm_prepare, int, (snd_pcm_t *pcm), (pcm))
70PROXY_STUB(snd_pcm_readi, snd_pcm_sframes_t,
71 (snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size),
72 (pcm, buffer, size))
73PROXY_STUB(snd_pcm_resume, int, (snd_pcm_t *pcm), (pcm))
74PROXY_STUB(snd_pcm_state, snd_pcm_state_t, (snd_pcm_t *pcm), (pcm))
75PROXY_STUB(snd_pcm_writei, snd_pcm_sframes_t,
76 (snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size),
77 (pcm, buffer, size))
78PROXY_STUB(snd_pcm_start, int, (snd_pcm_t *pcm), (pcm))
79
80/*
81 * HW
82 */
83
84PROXY_STUB(snd_pcm_hw_params, int,
85 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params),
86 (pcm, params))
87PROXY_STUB(snd_pcm_hw_params_any, int,
88 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params),
89 (pcm, params))
90PROXY_STUB(snd_pcm_hw_params_get_buffer_size, int,
91 (const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val),
92 (params, val))
93PROXY_STUB(snd_pcm_hw_params_get_buffer_size_min, int,
94 (const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val),
95 (params, val))
96PROXY_STUB(snd_pcm_hw_params_get_period_size, int,
97 (const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir),
98 (params, frames, dir))
99PROXY_STUB(snd_pcm_hw_params_get_period_size_min, int,
100 (const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir),
101 (params, frames, dir))
102PROXY_STUB(snd_pcm_hw_params_set_rate_near, int,
103 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir),
104 (pcm, params, val, dir))
105PROXY_STUB(snd_pcm_hw_params_set_access, int,
106 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t _access),
107 (pcm, params, _access))
108PROXY_STUB(snd_pcm_hw_params_set_buffer_time_near, int,
109 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir),
110 (pcm, params, val, dir))
111PROXY_STUB(snd_pcm_hw_params_set_buffer_size_near, int,
112 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val),
113 (pcm, params, val))
114PROXY_STUB(snd_pcm_hw_params_set_channels_near, int,
115 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val),
116 (pcm, params, val))
117PROXY_STUB(snd_pcm_hw_params_set_period_size_near, int,
118 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir),
119 (pcm, params, val, dir))
120PROXY_STUB(snd_pcm_hw_params_set_period_time_near, int,
121 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir),
122 (pcm, params, val, dir))
123PROXY_STUB(snd_pcm_hw_params_sizeof, size_t, (void), ())
124PROXY_STUB(snd_pcm_hw_params_set_format, int,
125 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val),
126 (pcm, params, val))
127
128/*
129 * SW
130 */
131
132PROXY_STUB(snd_pcm_sw_params, int,
133 (snd_pcm_t *pcm, snd_pcm_sw_params_t *params),
134 (pcm, params))
135PROXY_STUB(snd_pcm_sw_params_current, int,
136 (snd_pcm_t *pcm, snd_pcm_sw_params_t *params),
137 (pcm, params))
138PROXY_STUB(snd_pcm_sw_params_set_avail_min, int,
139 (snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val),
140 (pcm, params, val))
141PROXY_STUB(snd_pcm_sw_params_set_start_threshold, int,
142 (snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val),
143 (pcm, params, val))
144PROXY_STUB(snd_pcm_sw_params_sizeof, size_t, (void), ())
145
146typedef struct
147{
148 const char *name;
149 void (**fn)(void);
150} SHARED_FUNC;
151
152#define ELEMENT(function) { #function , (void (**)(void)) & pfn_ ## function }
153static SHARED_FUNC SharedFuncs[] =
154{
155 ELEMENT(snd_lib_error_set_handler),
156 ELEMENT(snd_strerror),
157
158 ELEMENT(snd_device_name_hint),
159 ELEMENT(snd_device_name_get_hint),
160 ELEMENT(snd_device_name_free_hint),
161
162 ELEMENT(snd_pcm_avail_update),
163 ELEMENT(snd_pcm_close),
164 ELEMENT(snd_pcm_delay),
165 ELEMENT(snd_pcm_drain),
166 ELEMENT(snd_pcm_drop),
167 ELEMENT(snd_pcm_nonblock),
168 ELEMENT(snd_pcm_open),
169 ELEMENT(snd_pcm_prepare),
170 ELEMENT(snd_pcm_resume),
171 ELEMENT(snd_pcm_state),
172
173 ELEMENT(snd_pcm_readi),
174 ELEMENT(snd_pcm_start),
175 ELEMENT(snd_pcm_writei),
176
177 ELEMENT(snd_pcm_hw_params),
178 ELEMENT(snd_pcm_hw_params_any),
179 ELEMENT(snd_pcm_hw_params_sizeof),
180 ELEMENT(snd_pcm_hw_params_get_buffer_size),
181 ELEMENT(snd_pcm_hw_params_get_buffer_size_min),
182 ELEMENT(snd_pcm_hw_params_get_period_size_min),
183 ELEMENT(snd_pcm_hw_params_set_access),
184 ELEMENT(snd_pcm_hw_params_set_buffer_size_near),
185 ELEMENT(snd_pcm_hw_params_set_buffer_time_near),
186 ELEMENT(snd_pcm_hw_params_set_channels_near),
187 ELEMENT(snd_pcm_hw_params_set_format),
188 ELEMENT(snd_pcm_hw_params_get_period_size),
189 ELEMENT(snd_pcm_hw_params_set_period_size_near),
190 ELEMENT(snd_pcm_hw_params_set_period_time_near),
191 ELEMENT(snd_pcm_hw_params_set_rate_near),
192
193 ELEMENT(snd_pcm_sw_params),
194 ELEMENT(snd_pcm_sw_params_current),
195 ELEMENT(snd_pcm_sw_params_set_start_threshold),
196 ELEMENT(snd_pcm_sw_params_set_avail_min),
197 ELEMENT(snd_pcm_sw_params_sizeof),
198};
199#undef ELEMENT
200
201/**
202 * Try to dynamically load the ALSA libraries. This function is not
203 * thread-safe, and should be called before attempting to use any of the
204 * ALSA functions.
205 *
206 * @returns iprt status code
207 */
208int audioLoadAlsaLib(void)
209{
210 int rc = VINF_SUCCESS;
211 unsigned i;
212 static enum { NO = 0, YES, FAIL } isLibLoaded = NO;
213 RTLDRMOD hLib;
214
215 LogFlowFunc(("\n"));
216 /* If this is not NO then the function has obviously been called twice,
217 which is likely to be a bug. */
218 if (NO != isLibLoaded)
219 {
220 AssertMsgFailed(("isLibLoaded == %s\n", YES == isLibLoaded ? "YES" : "NO"));
221 return YES == isLibLoaded ? VINF_SUCCESS : VERR_NOT_SUPPORTED;
222 }
223 isLibLoaded = FAIL;
224 rc = RTLdrLoad(VBOX_ALSA_LIB, &hLib);
225 if (RT_FAILURE(rc))
226 {
227 LogRelFunc(("Failed to load library %s\n", VBOX_ALSA_LIB));
228 return rc;
229 }
230 for (i=0; i<RT_ELEMENTS(SharedFuncs); i++)
231 {
232 rc = RTLdrGetSymbol(hLib, SharedFuncs[i].name, (void**)SharedFuncs[i].fn);
233 if (RT_FAILURE(rc))
234 return rc;
235 }
236 isLibLoaded = YES;
237 return rc;
238}
239
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