VirtualBox

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

Last change on this file since 6056 was 5147, checked in by vboxsync, 17 years ago

prevent a bunch of ugly warnings

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1#include <iprt/assert.h>
2#include <iprt/ldr.h>
3#define LOG_GROUP LOG_GROUP_DEV_AUDIO
4#include <VBox/log.h>
5#include <VBox/err.h>
6
7#include <alsa/asoundlib.h>
8
9#include "alsa_stubs.h"
10
11#define VBOX_ALSA_LIB "libasound.so.2"
12
13static enum { NO = 0, YES, FAIL } isLibLoaded = NO;
14static RTLDRMOD hLibAsound = NULL;
15
16/**
17 * Try to dynamically load the ALSA libraries. This function is not
18 * thread-safe, and should be called before attempting to use any
19 * of the ALSA functions.
20 *
21 * @returns iprt status code
22 */
23int audioLoadAlsaLib(void)
24{
25 int rc = VINF_SUCCESS;
26
27 LogFlowFunc(("\n"));
28 /* If this is not NO then the function has obviously been called twice,
29 which is likely to be a bug. */
30 if (NO != isLibLoaded)
31 {
32 AssertMsgFailed(("isLibLoaded == %s\n", YES == isLibLoaded ? "YES" : "NO"));
33 return YES == isLibLoaded ? VINF_SUCCESS : VERR_NOT_SUPPORTED;
34 }
35 isLibLoaded = FAIL;
36 rc = RTLdrLoad(VBOX_ALSA_LIB, &hLibAsound);
37 if (RT_FAILURE(rc))
38 {
39 LogRelFunc(("Failed to load library %s\n", VBOX_ALSA_LIB));
40 }
41 if (RT_SUCCESS(rc))
42 {
43 isLibLoaded = YES;
44 }
45 LogFlowFunc(("returning %Rrc\n", rc));
46 return rc;
47}
48
49#define PROXY_STUB(function, rettype, signature, shortsig, retval) \
50extern rettype function signature; \
51rettype function signature \
52{ \
53 static rettype (*pfnFunc) signature = NULL; \
54 rettype (*pfnResolvedFunc) signature; \
55 int rc; \
56 rettype rcFunc = retval; \
57\
58 if (RT_LIKELY(NULL != pfnFunc)) \
59 { \
60 return pfnFunc shortsig; \
61 } \
62 AssertReturn(YES == isLibLoaded, retval); \
63 rc = RTLdrGetSymbol(hLibAsound, #function, (void**)&pfnResolvedFunc); \
64 if (RT_SUCCESS(rc)) \
65 { \
66 Log2(("%s: resolving symbol on first call.\n", __PRETTY_FUNCTION__)); \
67 pfnFunc = pfnResolvedFunc; \
68 rcFunc = pfnFunc shortsig; \
69 } \
70 else \
71 { \
72 LogRelFunc(("failed to resolve symbol on first call, rc=%Rrc\n", rc)); \
73 } \
74 return rcFunc; \
75} \
76
77
78PROXY_STUB(snd_pcm_hw_params_any, int,
79 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params),
80 (pcm, params), -1)
81PROXY_STUB(snd_pcm_close, int, (snd_pcm_t *pcm), (pcm), -1)
82PROXY_STUB(snd_pcm_avail_update, snd_pcm_sframes_t, (snd_pcm_t *pcm),
83 (pcm), -1)
84PROXY_STUB(snd_pcm_hw_params_set_channels_near, int,
85 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val),
86 (pcm, params, val), -1)
87PROXY_STUB(snd_pcm_hw_params_set_period_time_near, int,
88 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir),
89 (pcm, params, val, dir), -1)
90PROXY_STUB(snd_pcm_prepare, int, (snd_pcm_t *pcm), (pcm), -1)
91PROXY_STUB(snd_pcm_sw_params_sizeof, size_t, (void), (), ~0)
92PROXY_STUB(snd_pcm_hw_params_set_period_size_near, int,
93 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir),
94 (pcm, params, val, dir), -1)
95PROXY_STUB(snd_pcm_hw_params_get_period_size, int,
96 (const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir),
97 (params, frames, dir), -1)
98PROXY_STUB(snd_pcm_hw_params, int,
99 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params),
100 (pcm, params), -1)
101PROXY_STUB(snd_pcm_hw_params_sizeof, size_t, (void), (), ~0)
102PROXY_STUB(snd_pcm_state, snd_pcm_state_t, (snd_pcm_t *pcm), (pcm), ~0)
103PROXY_STUB(snd_pcm_open, int,
104 (snd_pcm_t **pcm, const char *name, snd_pcm_stream_t stream, int mode),
105 (pcm, name, stream, mode), -1)
106PROXY_STUB(snd_lib_error_set_handler, int, (snd_lib_error_handler_t handler),
107 (handler), -1)
108PROXY_STUB(snd_pcm_sw_params, int,
109 (snd_pcm_t *pcm, snd_pcm_sw_params_t *params),
110 (pcm, params), -1)
111PROXY_STUB(snd_pcm_hw_params_get_period_size_min, int,
112 (const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir),
113 (params, frames, dir), -1)
114PROXY_STUB(snd_pcm_writei, snd_pcm_sframes_t,
115 (snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size),
116 (pcm, buffer, size), -1)
117PROXY_STUB(snd_pcm_readi, snd_pcm_sframes_t,
118 (snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size),
119 (pcm, buffer, size), -1)
120PROXY_STUB(snd_strerror, const char *, (int errnum), (errnum), NULL)
121PROXY_STUB(snd_pcm_drop, int, (snd_pcm_t *pcm), (pcm), -1)
122PROXY_STUB(snd_pcm_hw_params_get_buffer_size, int,
123 (const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val),
124 (params, val), -1)
125PROXY_STUB(snd_pcm_hw_params_set_rate_near, int,
126 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir),
127 (pcm, params, val, dir), -1)
128PROXY_STUB(snd_pcm_hw_params_set_access, int,
129 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t _access),
130 (pcm, params, _access), -1)
131PROXY_STUB(snd_pcm_hw_params_set_buffer_time_near, int,
132 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir),
133 (pcm, params, val, dir), -1)
134PROXY_STUB(snd_pcm_hw_params_set_buffer_size_near, int,
135 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val),
136 (pcm, params, val), -1)
137PROXY_STUB(snd_pcm_hw_params_get_buffer_size_min, int,
138 (const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val),
139 (params, val), -1)
140PROXY_STUB(snd_pcm_hw_params_set_format, int,
141 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val),
142 (pcm, params, val), -1)
143PROXY_STUB(snd_pcm_sw_params_current, int,
144 (snd_pcm_t *pcm, snd_pcm_sw_params_t *params),
145 (pcm, params), -1)
146PROXY_STUB(snd_pcm_sw_params_set_start_threshold, int,
147 (snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val),
148 (pcm, params, val), -1)
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