1
/* $Id: alsa_stubs.c $ */
7
* Copyright (C) 2006-2010 Oracle Corporation
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.
18
#include <iprt/assert.h>
20
#define LOG_GROUP LOG_GROUP_DEV_AUDIO
24
#include <alsa/asoundlib.h>
26
#include "alsa_stubs.h"
28
#define VBOX_ALSA_LIB "libasound.so.2"
30
#define PROXY_STUB(function, rettype, signature, shortsig) \
31
static rettype (*pfn_ ## function) signature; \
33
rettype VBox_##function signature; \
34
rettype VBox_##function signature \
36
return pfn_ ## function shortsig; \
39
PROXY_STUB(snd_pcm_hw_params_any, int,
40
(snd_pcm_t *pcm, snd_pcm_hw_params_t *params),
42
PROXY_STUB(snd_pcm_close, int, (snd_pcm_t *pcm), (pcm))
43
PROXY_STUB(snd_pcm_avail_update, snd_pcm_sframes_t, (snd_pcm_t *pcm),
45
PROXY_STUB(snd_pcm_hw_params_set_channels_near, int,
46
(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val),
48
PROXY_STUB(snd_pcm_hw_params_set_period_time_near, int,
49
(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir),
50
(pcm, params, val, dir))
51
PROXY_STUB(snd_pcm_prepare, int, (snd_pcm_t *pcm), (pcm))
52
PROXY_STUB(snd_pcm_sw_params_sizeof, size_t, (void), ())
53
PROXY_STUB(snd_pcm_hw_params_set_period_size_near, int,
54
(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir),
55
(pcm, params, val, dir))
56
PROXY_STUB(snd_pcm_hw_params_get_period_size, int,
57
(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir),
58
(params, frames, dir))
59
PROXY_STUB(snd_pcm_hw_params, int,
60
(snd_pcm_t *pcm, snd_pcm_hw_params_t *params),
62
PROXY_STUB(snd_pcm_hw_params_sizeof, size_t, (void), ())
63
PROXY_STUB(snd_pcm_state, snd_pcm_state_t, (snd_pcm_t *pcm), (pcm))
64
PROXY_STUB(snd_pcm_open, int,
65
(snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode),
66
(pcm, name, stream, mode))
67
PROXY_STUB(snd_lib_error_set_handler, int, (snd_lib_error_handler_t handler),
69
PROXY_STUB(snd_pcm_sw_params, int,
70
(snd_pcm_t *pcm, snd_pcm_sw_params_t *params),
72
PROXY_STUB(snd_pcm_hw_params_get_period_size_min, int,
73
(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir),
74
(params, frames, dir))
75
PROXY_STUB(snd_pcm_writei, snd_pcm_sframes_t,
76
(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size),
78
PROXY_STUB(snd_pcm_readi, snd_pcm_sframes_t,
79
(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size),
81
PROXY_STUB(snd_strerror, const char *, (int errnum), (errnum))
82
PROXY_STUB(snd_pcm_drop, int, (snd_pcm_t *pcm), (pcm))
83
PROXY_STUB(snd_pcm_resume, int, (snd_pcm_t *pcm), (pcm))
84
PROXY_STUB(snd_pcm_hw_params_get_buffer_size, int,
85
(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val),
87
PROXY_STUB(snd_pcm_hw_params_set_rate_near, int,
88
(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir),
89
(pcm, params, val, dir))
90
PROXY_STUB(snd_pcm_hw_params_set_access, int,
91
(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t _access),
92
(pcm, params, _access))
93
PROXY_STUB(snd_pcm_hw_params_set_buffer_time_near, int,
94
(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir),
95
(pcm, params, val, dir))
96
PROXY_STUB(snd_pcm_hw_params_set_buffer_size_near, int,
97
(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val),
99
PROXY_STUB(snd_pcm_hw_params_get_buffer_size_min, int,
100
(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val),
102
PROXY_STUB(snd_pcm_hw_params_set_format, int,
103
(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val),
105
PROXY_STUB(snd_pcm_sw_params_current, int,
106
(snd_pcm_t *pcm, snd_pcm_sw_params_t *params),
108
PROXY_STUB(snd_pcm_sw_params_set_start_threshold, int,
109
(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val),
118
#define ELEMENT(function) { #function , (void (**)(void)) & pfn_ ## function }
119
static SHARED_FUNC SharedFuncs[] =
121
ELEMENT(snd_pcm_hw_params_any),
122
ELEMENT(snd_pcm_close),
123
ELEMENT(snd_pcm_avail_update),
124
ELEMENT(snd_pcm_hw_params_set_channels_near),
125
ELEMENT(snd_pcm_hw_params_set_period_time_near),
126
ELEMENT(snd_pcm_prepare),
127
ELEMENT(snd_pcm_sw_params_sizeof),
128
ELEMENT(snd_pcm_hw_params_set_period_size_near),
129
ELEMENT(snd_pcm_hw_params_get_period_size),
130
ELEMENT(snd_pcm_hw_params),
131
ELEMENT(snd_pcm_hw_params_sizeof),
132
ELEMENT(snd_pcm_state),
133
ELEMENT(snd_pcm_open),
134
ELEMENT(snd_lib_error_set_handler),
135
ELEMENT(snd_pcm_sw_params),
136
ELEMENT(snd_pcm_hw_params_get_period_size_min),
137
ELEMENT(snd_pcm_writei),
138
ELEMENT(snd_pcm_readi),
139
ELEMENT(snd_strerror),
140
ELEMENT(snd_pcm_drop),
141
ELEMENT(snd_pcm_resume),
142
ELEMENT(snd_pcm_hw_params_get_buffer_size),
143
ELEMENT(snd_pcm_hw_params_set_rate_near),
144
ELEMENT(snd_pcm_hw_params_set_access),
145
ELEMENT(snd_pcm_hw_params_set_buffer_time_near),
146
ELEMENT(snd_pcm_hw_params_set_buffer_size_near),
147
ELEMENT(snd_pcm_hw_params_get_buffer_size_min),
148
ELEMENT(snd_pcm_hw_params_set_format),
149
ELEMENT(snd_pcm_sw_params_current),
150
ELEMENT(snd_pcm_sw_params_set_start_threshold),
155
* Try to dynamically load the ALSA libraries. This function is not
156
* thread-safe, and should be called before attempting to use any of the
159
* @returns iprt status code
161
int audioLoadAlsaLib(void)
163
int rc = VINF_SUCCESS;
165
static enum { NO = 0, YES, FAIL } isLibLoaded = NO;
169
/* If this is not NO then the function has obviously been called twice,
170
which is likely to be a bug. */
171
if (NO != isLibLoaded)
173
AssertMsgFailed(("isLibLoaded == %s\n", YES == isLibLoaded ? "YES" : "NO"));
174
return YES == isLibLoaded ? VINF_SUCCESS : VERR_NOT_SUPPORTED;
177
rc = RTLdrLoad(VBOX_ALSA_LIB, &hLib);
180
LogRelFunc(("Failed to load library %s\n", VBOX_ALSA_LIB));
183
for (i=0; i<RT_ELEMENTS(SharedFuncs); i++)
185
rc = RTLdrGetSymbol(hLib, SharedFuncs[i].name, (void**)SharedFuncs[i].fn);