VirtualBox

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

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

Audio: fix ALSA stub for snd_device_name_free_hint()

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