Changeset 6077 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- Dec 14, 2007 9:33:20 PM (17 years ago)
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/alsa_stubs.c
r5147 r6077 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 1 18 #include <iprt/assert.h> 2 19 #include <iprt/ldr.h> … … 11 28 #define VBOX_ALSA_LIB "libasound.so.2" 12 29 13 static enum { NO = 0, YES, FAIL } isLibLoaded = NO; 14 static RTLDRMOD hLibAsound = NULL; 30 #define PROXY_STUB(function, rettype, signature, shortsig) \ 31 void (*function ## _fn)(void); \ 32 rettype function signature \ 33 { return ( (rettype (*) signature) function ## _fn ) shortsig; } 34 35 PROXY_STUB(snd_pcm_hw_params_any, int, 36 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params), 37 (pcm, params)) 38 PROXY_STUB(snd_pcm_close, int, (snd_pcm_t *pcm), (pcm)) 39 PROXY_STUB(snd_pcm_avail_update, snd_pcm_sframes_t, (snd_pcm_t *pcm), 40 (pcm)) 41 PROXY_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)) 44 PROXY_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)) 47 PROXY_STUB(snd_pcm_prepare, int, (snd_pcm_t *pcm), (pcm)) 48 PROXY_STUB(snd_pcm_sw_params_sizeof, size_t, (void), ()) 49 PROXY_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)) 52 PROXY_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)) 55 PROXY_STUB(snd_pcm_hw_params, int, 56 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params), 57 (pcm, params)) 58 PROXY_STUB(snd_pcm_hw_params_sizeof, size_t, (void), ()) 59 PROXY_STUB(snd_pcm_state, snd_pcm_state_t, (snd_pcm_t *pcm), (pcm)) 60 PROXY_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)) 63 PROXY_STUB(snd_lib_error_set_handler, int, (snd_lib_error_handler_t handler), 64 (handler)) 65 PROXY_STUB(snd_pcm_sw_params, int, 66 (snd_pcm_t *pcm, snd_pcm_sw_params_t *params), 67 (pcm, params)) 68 PROXY_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)) 71 PROXY_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)) 74 PROXY_STUB(snd_pcm_readi, snd_pcm_sframes_t, 75 (snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size), 76 (pcm, buffer, size)) 77 PROXY_STUB(snd_strerror, const char *, (int errnum), (errnum)) 78 PROXY_STUB(snd_pcm_drop, int, (snd_pcm_t *pcm), (pcm)) 79 PROXY_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)) 82 PROXY_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)) 85 PROXY_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)) 88 PROXY_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)) 91 PROXY_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)) 94 PROXY_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)) 97 PROXY_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)) 100 PROXY_STUB(snd_pcm_sw_params_current, int, 101 (snd_pcm_t *pcm, snd_pcm_sw_params_t *params), 102 (pcm, params)) 103 PROXY_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 107 typedef struct 108 { 109 const char *name; 110 void (**fn)(void); 111 } SHARED_FUNC; 112 113 #define ELEMENT(s) { #s , & s ## _fn } 114 static 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 15 147 16 148 /** 17 149 * 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 theALSA functions.150 * thread-safe, and should be called before attempting to use any of the 151 * ALSA functions. 20 152 * 21 153 * @returns iprt status code … … 24 156 { 25 157 int rc = VINF_SUCCESS; 158 int i; 159 static enum { NO = 0, YES, FAIL } isLibLoaded = NO; 160 RTLDRMOD hLib; 26 161 27 162 LogFlowFunc(("\n")); … … 34 169 } 35 170 isLibLoaded = FAIL; 36 rc = RTLdrLoad(VBOX_ALSA_LIB, &hLib Asound);171 rc = RTLdrLoad(VBOX_ALSA_LIB, &hLib); 37 172 if (RT_FAILURE(rc)) 38 173 { 39 174 LogRelFunc(("Failed to load library %s\n", VBOX_ALSA_LIB)); 175 return rc; 40 176 } 41 if (RT_SUCCESS(rc))177 for (i=0; i<ELEMENTS(SharedFuncs); i++) 42 178 { 43 isLibLoaded = YES; 179 rc = RTLdrGetSymbol(hLib, SharedFuncs[i].name, (void**)SharedFuncs[i].fn); 180 if (RT_FAILURE(rc)) 181 return rc; 44 182 } 45 LogFlowFunc(("returning %Rrc\n", rc));183 isLibLoaded = YES; 46 184 return rc; 47 185 } 48 49 #define PROXY_STUB(function, rettype, signature, shortsig, retval) \50 extern rettype function signature; \51 rettype 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 78 PROXY_STUB(snd_pcm_hw_params_any, int,79 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params),80 (pcm, params), -1)81 PROXY_STUB(snd_pcm_close, int, (snd_pcm_t *pcm), (pcm), -1)82 PROXY_STUB(snd_pcm_avail_update, snd_pcm_sframes_t, (snd_pcm_t *pcm),83 (pcm), -1)84 PROXY_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)87 PROXY_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)90 PROXY_STUB(snd_pcm_prepare, int, (snd_pcm_t *pcm), (pcm), -1)91 PROXY_STUB(snd_pcm_sw_params_sizeof, size_t, (void), (), ~0)92 PROXY_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)95 PROXY_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)98 PROXY_STUB(snd_pcm_hw_params, int,99 (snd_pcm_t *pcm, snd_pcm_hw_params_t *params),100 (pcm, params), -1)101 PROXY_STUB(snd_pcm_hw_params_sizeof, size_t, (void), (), ~0)102 PROXY_STUB(snd_pcm_state, snd_pcm_state_t, (snd_pcm_t *pcm), (pcm), ~0)103 PROXY_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)106 PROXY_STUB(snd_lib_error_set_handler, int, (snd_lib_error_handler_t handler),107 (handler), -1)108 PROXY_STUB(snd_pcm_sw_params, int,109 (snd_pcm_t *pcm, snd_pcm_sw_params_t *params),110 (pcm, params), -1)111 PROXY_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)114 PROXY_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)117 PROXY_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)120 PROXY_STUB(snd_strerror, const char *, (int errnum), (errnum), NULL)121 PROXY_STUB(snd_pcm_drop, int, (snd_pcm_t *pcm), (pcm), -1)122 PROXY_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)125 PROXY_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)128 PROXY_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)131 PROXY_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)134 PROXY_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)137 PROXY_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)140 PROXY_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)143 PROXY_STUB(snd_pcm_sw_params_current, int,144 (snd_pcm_t *pcm, snd_pcm_sw_params_t *params),145 (pcm, params), -1)146 PROXY_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) -
trunk/src/VBox/Devices/Audio/alsa_stubs.h
r5092 r6077 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 1 18 #ifndef AUDIO_ALSA_STUBS_H 2 19 # define AUDIO_ALSA_STUBS_H -
trunk/src/VBox/Devices/Audio/alsaaudio.c
r6056 r6077 1068 1068 rc = audioLoadAlsaLib(); 1069 1069 if (RT_FAILURE(rc)) { 1070 LogRel Func(("Failed to load the ALSA shared library! Error %Rrc\n", rc));1070 LogRel(("ALSA: Failed to load the ALSA shared library! Error %Rrc\n", rc)); 1071 1071 return NULL; 1072 1072 }
Note:
See TracChangeset
for help on using the changeset viewer.