alsa.audio: move handling of XRUN when writting to the slave task
[AROS.git] / workbench / devs / AHI / Drivers / Alsa / alsa-bridge / alsa_hostlib.c
blob40518bb039b913248f51b18b3de47f77b2a30c04
1 /*
2 Copyright © 2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <proto/hostlib.h>
8 #include "alsa_hostlib.h"
10 #include <aros/debug.h>
12 static const char *alsa_func_names[] =
14 "snd_pcm_open",
15 "snd_pcm_close",
16 "snd_pcm_hw_params_malloc",
17 "snd_pcm_hw_params_free",
18 "snd_pcm_hw_params_any",
19 "snd_pcm_hw_params_set_access",
20 "snd_pcm_hw_params_set_format",
21 "snd_pcm_hw_params_set_rate_near",
22 "snd_pcm_hw_params_set_channels",
23 "snd_pcm_hw_params",
24 "snd_pcm_prepare",
25 "snd_pcm_writei",
26 "snd_pcm_avail_update",
27 "snd_pcm_hw_params_get_buffer_size",
28 "snd_pcm_hw_params_set_buffer_size"
31 #define ALSA_NUM_FUNCS (sizeof(alsa_func_names) / sizeof(alsa_func_names[0]))
33 APTR HostLibBase;
34 struct alsa_func alsa_func;
35 static void * libasoundhandle;
37 static void *hostlib_load_so(const char *sofile, const char **names, int nfuncs,
38 void **funcptr)
40 void *handle;
41 char *err;
42 int i;
44 if ((handle = HostLib_Open(sofile, &err)) == NULL) {
45 D(bug("[ALSA] failed to open '%s': %s\n", sofile, err));
46 return NULL;
49 for (i = 0; i < nfuncs; i++) {
50 funcptr[i] = HostLib_GetPointer(handle, names[i], &err);
51 if (err != NULL) {
52 bug("[ALSA] failed to get symbol '%s' (%s)\n", names[i], err);
53 HostLib_Close(handle, NULL);
54 return NULL;
58 return handle;
61 BOOL ALSA_HostLib_Init()
63 HostLibBase = OpenResource("hostlib.resource");
65 if (!HostLibBase)
66 return FALSE;
68 libasoundhandle = hostlib_load_so("libasound.so", alsa_func_names,
69 ALSA_NUM_FUNCS, (void **)&alsa_func);
71 if (!libasoundhandle)
72 return FALSE;
74 return TRUE;
77 VOID ALSA_HostLib_Cleanup()
79 HostLib_Close(libasoundhandle, NULL);