VirtualBox

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

最後變更 在這個檔案從5092是 5092,由 vboxsync 提交於 18 年 前

Hrmpf.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette