VirtualBox

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

Last change on this file since 31263 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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