VirtualBox

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

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

pulse/alsa: resolve _all_ symbols during initialization, otherwise incompatible libraries might confuse the sound driver much later during runtime

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