Changeset 89425 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- Jun 1, 2021 10:22:23 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 144778
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostAudioAlsaStubs.cpp
r88966 r89425 18 18 #define LOG_GROUP LOG_GROUP_DRV_HOST_AUDIO 19 19 #include <iprt/assert.h> 20 #include <iprt/err.h> 20 21 #include <iprt/ldr.h> 21 22 #include <VBox/log.h> 22 #include <iprt/ err.h>23 #include <iprt/once.h> 23 24 24 25 #include <alsa/asoundlib.h> … … 239 240 #undef ELEMENT 240 241 241 /** 242 * Try to dynamically load the ALSA libraries. This function is not 243 * thread-safe, and should be called before attempting to use any of the 244 * ALSA functions. 245 * 246 * @returns iprt status code 247 */ 248 int audioLoadAlsaLib(void) 249 { 250 static enum { NO = 0, YES, FAIL } isLibLoaded = NO; 251 RTLDRMOD hLib; 252 242 /** Init once. */ 243 static RTONCE g_AlsaLibInitOnce = RTONCE_INITIALIZER; 244 245 246 /** @callback_method_impl{FNRTONCE} */ 247 static DECLCALLBACK(int32_t) drvHostAudioAlsaLibInitOnce(void *pvUser) 248 { 249 RT_NOREF(pvUser); 253 250 LogFlowFunc(("\n")); 254 /* If this is not NO then the function has obviously been called twice, 255 which is likely to be a bug. */ 256 if (NO != isLibLoaded) 251 252 RTLDRMOD hMod = NIL_RTLDRMOD; 253 int rc = RTLdrLoadSystemEx(VBOX_ALSA_LIB, RTLDRLOAD_FLAGS_NO_UNLOAD, &hMod); 254 if (RT_SUCCESS(rc)) 257 255 { 258 AssertMsgFailed(("isLibLoaded == %s\n", YES == isLibLoaded ? "YES" : "NO")); 259 return YES == isLibLoaded ? VINF_SUCCESS : VERR_NOT_SUPPORTED; 260 } 261 isLibLoaded = FAIL; 262 int rc = RTLdrLoad(VBOX_ALSA_LIB, &hLib); 263 if (RT_FAILURE(rc)) 264 { 265 LogRelFunc(("Failed to load library %s (%Rrc)\n", VBOX_ALSA_LIB, rc)); 266 return rc; 267 } 268 for (uintptr_t i = 0; i < RT_ELEMENTS(SharedFuncs); i++) 269 { 270 rc = RTLdrGetSymbol(hLib, SharedFuncs[i].name, (void **)SharedFuncs[i].pfn); 271 if (RT_SUCCESS(rc)) 272 { /* likely */ } 273 else if (SharedFuncs[i].pfnFallback && rc == VERR_SYMBOL_NOT_FOUND) 274 *SharedFuncs[i].pfn = SharedFuncs[i].pfnFallback; 275 else 256 for (uintptr_t i = 0; i < RT_ELEMENTS(SharedFuncs); i++) 276 257 { 277 LogRelFunc(("Failed to load library %s: Getting symbol %s failed: %Rrc\n", VBOX_ALSA_LIB, SharedFuncs[i].name, rc)); 278 return rc; 258 rc = RTLdrGetSymbol(hMod, SharedFuncs[i].name, (void **)SharedFuncs[i].pfn); 259 if (RT_SUCCESS(rc)) 260 { /* likely */ } 261 else if (SharedFuncs[i].pfnFallback && rc == VERR_SYMBOL_NOT_FOUND) 262 *SharedFuncs[i].pfn = SharedFuncs[i].pfnFallback; 263 else 264 { 265 LogRelFunc(("Failed to load library %s: Getting symbol %s failed: %Rrc\n", VBOX_ALSA_LIB, SharedFuncs[i].name, rc)); 266 return rc; 267 } 279 268 } 280 269 } 281 isLibLoaded = YES; 270 else 271 LogRelFunc(("Failed to load library %s (%Rrc)\n", VBOX_ALSA_LIB, rc)); 282 272 return rc; 283 273 } 284 274 275 276 /** 277 * Try to dynamically load the ALSA libraries. 278 * 279 * @returns VBox status code. 280 */ 281 int audioLoadAlsaLib(void) 282 { 283 LogFlowFunc(("\n")); 284 return RTOnce(&g_AlsaLibInitOnce, drvHostAudioAlsaLibInitOnce, NULL); 285 } 286
Note:
See TracChangeset
for help on using the changeset viewer.