VirtualBox

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

Last change on this file since 55747 was 45136, checked in by vboxsync, 12 years ago

Devices/Audio: mangle symbols of libasound and libpulse, otherwise they can be resolved by dynamic libraries if -fvisibility is not supported

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1/* $Id: alsa_stubs.c 45136 2013-03-22 10:22:57Z vboxsync $ */
2/** @file
3 * Stubs for libasound.
4 */
5
6/*
7 * Copyright (C) 2006-2010 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
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) \
31 static rettype (*pfn_ ## function) signature; \
32 \
33 rettype VBox_##function signature; \
34 rettype VBox_##function signature \
35 { \
36 return pfn_ ## function shortsig; \
37 }
38
39PROXY_STUB(snd_pcm_hw_params_any, int,
40 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params),
41 (pcm, params))
42PROXY_STUB(snd_pcm_close, int, (snd_pcm_t *pcm), (pcm))
43PROXY_STUB(snd_pcm_avail_update, snd_pcm_sframes_t, (snd_pcm_t *pcm),
44 (pcm))
45PROXY_STUB(snd_pcm_hw_params_set_channels_near, int,
46 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val),
47 (pcm, params, val))
48PROXY_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))
51PROXY_STUB(snd_pcm_prepare, int, (snd_pcm_t *pcm), (pcm))
52PROXY_STUB(snd_pcm_sw_params_sizeof, size_t, (void), ())
53PROXY_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))
56PROXY_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))
59PROXY_STUB(snd_pcm_hw_params, int,
60 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params),
61 (pcm, params))
62PROXY_STUB(snd_pcm_hw_params_sizeof, size_t, (void), ())
63PROXY_STUB(snd_pcm_state, snd_pcm_state_t, (snd_pcm_t *pcm), (pcm))
64PROXY_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))
67PROXY_STUB(snd_lib_error_set_handler, int, (snd_lib_error_handler_t handler),
68 (handler))
69PROXY_STUB(snd_pcm_sw_params, int,
70 (snd_pcm_t *pcm, snd_pcm_sw_params_t *params),
71 (pcm, params))
72PROXY_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))
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_readi, snd_pcm_sframes_t,
79 (snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size),
80 (pcm, buffer, size))
81PROXY_STUB(snd_strerror, const char *, (int errnum), (errnum))
82PROXY_STUB(snd_pcm_drop, int, (snd_pcm_t *pcm), (pcm))
83PROXY_STUB(snd_pcm_resume, int, (snd_pcm_t *pcm), (pcm))
84PROXY_STUB(snd_pcm_hw_params_get_buffer_size, int,
85 (const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val),
86 (params, val))
87PROXY_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))
90PROXY_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))
93PROXY_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))
96PROXY_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),
98 (pcm, params, val))
99PROXY_STUB(snd_pcm_hw_params_get_buffer_size_min, int,
100 (const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val),
101 (params, val))
102PROXY_STUB(snd_pcm_hw_params_set_format, int,
103 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val),
104 (pcm, params, val))
105PROXY_STUB(snd_pcm_sw_params_current, int,
106 (snd_pcm_t *pcm, snd_pcm_sw_params_t *params),
107 (pcm, params))
108PROXY_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),
110 (pcm, params, val))
111
112typedef struct
113{
114 const char *name;
115 void (**fn)(void);
116} SHARED_FUNC;
117
118#define ELEMENT(function) { #function , (void (**)(void)) & pfn_ ## function }
119static SHARED_FUNC SharedFuncs[] =
120{
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),
151};
152#undef ELEMENT
153
154/**
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
157 * ALSA functions.
158 *
159 * @returns iprt status code
160 */
161int audioLoadAlsaLib(void)
162{
163 int rc = VINF_SUCCESS;
164 unsigned i;
165 static enum { NO = 0, YES, FAIL } isLibLoaded = NO;
166 RTLDRMOD hLib;
167
168 LogFlowFunc(("\n"));
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)
172 {
173 AssertMsgFailed(("isLibLoaded == %s\n", YES == isLibLoaded ? "YES" : "NO"));
174 return YES == isLibLoaded ? VINF_SUCCESS : VERR_NOT_SUPPORTED;
175 }
176 isLibLoaded = FAIL;
177 rc = RTLdrLoad(VBOX_ALSA_LIB, &hLib);
178 if (RT_FAILURE(rc))
179 {
180 LogRelFunc(("Failed to load library %s\n", VBOX_ALSA_LIB));
181 return rc;
182 }
183 for (i=0; i<RT_ELEMENTS(SharedFuncs); i++)
184 {
185 rc = RTLdrGetSymbol(hLib, SharedFuncs[i].name, (void**)SharedFuncs[i].fn);
186 if (RT_FAILURE(rc))
187 return rc;
188 }
189 isLibLoaded = YES;
190 return rc;
191}
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