VirtualBox

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

Last change on this file since 88037 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 KB
Line 
1/* $Id: alsa_stubs.c 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * Stubs for libasound.
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#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 <iprt/errcore.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_get_start_threshold, int,
139 (const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val),
140 (params, val))
141PROXY_STUB(snd_pcm_sw_params_set_avail_min, 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_set_start_threshold, int,
145 (snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val),
146 (pcm, params, val))
147PROXY_STUB(snd_pcm_sw_params_sizeof, size_t, (void), ())
148
149typedef struct
150{
151 const char *name;
152 void (**fn)(void);
153} SHARED_FUNC;
154
155#define ELEMENT(function) { #function , (void (**)(void)) & pfn_ ## function }
156static SHARED_FUNC SharedFuncs[] =
157{
158 ELEMENT(snd_lib_error_set_handler),
159 ELEMENT(snd_strerror),
160
161 ELEMENT(snd_device_name_hint),
162 ELEMENT(snd_device_name_get_hint),
163 ELEMENT(snd_device_name_free_hint),
164
165 ELEMENT(snd_pcm_avail_update),
166 ELEMENT(snd_pcm_close),
167 ELEMENT(snd_pcm_delay),
168 ELEMENT(snd_pcm_drain),
169 ELEMENT(snd_pcm_drop),
170 ELEMENT(snd_pcm_nonblock),
171 ELEMENT(snd_pcm_open),
172 ELEMENT(snd_pcm_prepare),
173 ELEMENT(snd_pcm_resume),
174 ELEMENT(snd_pcm_state),
175
176 ELEMENT(snd_pcm_readi),
177 ELEMENT(snd_pcm_start),
178 ELEMENT(snd_pcm_writei),
179
180 ELEMENT(snd_pcm_hw_params),
181 ELEMENT(snd_pcm_hw_params_any),
182 ELEMENT(snd_pcm_hw_params_sizeof),
183 ELEMENT(snd_pcm_hw_params_get_buffer_size),
184 ELEMENT(snd_pcm_hw_params_get_buffer_size_min),
185 ELEMENT(snd_pcm_hw_params_get_period_size_min),
186 ELEMENT(snd_pcm_hw_params_set_access),
187 ELEMENT(snd_pcm_hw_params_set_buffer_size_near),
188 ELEMENT(snd_pcm_hw_params_set_buffer_time_near),
189 ELEMENT(snd_pcm_hw_params_set_channels_near),
190 ELEMENT(snd_pcm_hw_params_set_format),
191 ELEMENT(snd_pcm_hw_params_get_period_size),
192 ELEMENT(snd_pcm_hw_params_set_period_size_near),
193 ELEMENT(snd_pcm_hw_params_set_period_time_near),
194 ELEMENT(snd_pcm_hw_params_set_rate_near),
195
196 ELEMENT(snd_pcm_sw_params),
197 ELEMENT(snd_pcm_sw_params_current),
198 ELEMENT(snd_pcm_sw_params_get_start_threshold),
199 ELEMENT(snd_pcm_sw_params_set_avail_min),
200 ELEMENT(snd_pcm_sw_params_set_start_threshold),
201 ELEMENT(snd_pcm_sw_params_sizeof),
202};
203#undef ELEMENT
204
205/**
206 * Try to dynamically load the ALSA libraries. This function is not
207 * thread-safe, and should be called before attempting to use any of the
208 * ALSA functions.
209 *
210 * @returns iprt status code
211 */
212int audioLoadAlsaLib(void)
213{
214 int rc = VINF_SUCCESS;
215 unsigned i;
216 static enum { NO = 0, YES, FAIL } isLibLoaded = NO;
217 RTLDRMOD hLib;
218
219 LogFlowFunc(("\n"));
220 /* If this is not NO then the function has obviously been called twice,
221 which is likely to be a bug. */
222 if (NO != isLibLoaded)
223 {
224 AssertMsgFailed(("isLibLoaded == %s\n", YES == isLibLoaded ? "YES" : "NO"));
225 return YES == isLibLoaded ? VINF_SUCCESS : VERR_NOT_SUPPORTED;
226 }
227 isLibLoaded = FAIL;
228 rc = RTLdrLoad(VBOX_ALSA_LIB, &hLib);
229 if (RT_FAILURE(rc))
230 {
231 LogRelFunc(("Failed to load library %s\n", VBOX_ALSA_LIB));
232 return rc;
233 }
234 for (i=0; i<RT_ELEMENTS(SharedFuncs); i++)
235 {
236 rc = RTLdrGetSymbol(hLib, SharedFuncs[i].name, (void**)SharedFuncs[i].fn);
237 if (RT_FAILURE(rc))
238 return rc;
239 }
240 isLibLoaded = YES;
241 return rc;
242}
243
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