revert between 56095 -> 55830 in arch
[AROS.git] / workbench / devs / AHI / Drivers / Alsa / alsa-bridge / alsa_hostlib.c
blobfff2aab8c43089beea9ba2d0d62ba080b3b04e6e
1 /*
2 Copyright © 2015-2018, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "alsa_hostlib.h"
7 #include <proto/hostlib.h>
9 #include <aros/debug.h>
11 #define LIBASOUND_SOFILE "libasound.so.2"
13 static const char *alsa_func_names[] =
15 "snd_pcm_open",
16 "snd_pcm_close",
17 "snd_pcm_hw_params_malloc",
18 "snd_pcm_hw_params_free",
19 "snd_pcm_hw_params_any",
20 "snd_pcm_hw_params_set_access",
21 "snd_pcm_hw_params_set_format",
22 "snd_pcm_hw_params_set_rate_near",
23 "snd_pcm_hw_params_set_channels",
24 "snd_pcm_hw_params",
25 "snd_pcm_prepare",
26 "snd_pcm_writei",
27 "snd_pcm_avail_update",
28 "snd_pcm_hw_params_get_buffer_size",
29 "snd_pcm_hw_params_set_buffer_size",
30 "snd_pcm_drop",
32 "snd_mixer_open",
33 "snd_mixer_close",
34 "snd_mixer_load",
35 "snd_mixer_attach",
36 "snd_mixer_find_selem",
37 "snd_mixer_selem_register",
38 "snd_mixer_selem_id_malloc",
39 "snd_mixer_selem_id_free",
40 "snd_mixer_selem_id_set_index",
41 "snd_mixer_selem_id_set_name",
42 "snd_mixer_selem_get_playback_volume_range",
43 "snd_mixer_selem_get_playback_volume",
44 "snd_mixer_selem_set_playback_volume_all",
47 #define ALSA_NUM_FUNCS (sizeof(alsa_func_names) / sizeof(alsa_func_names[0]))
49 APTR HostLibBase;
50 struct alsa_func alsa_func;
51 static void *libasoundhandle;
53 static void *hostlib_load_so(const char *sofile, const char **names, int nfuncs,
54 void **funcptr)
56 void *handle;
57 char *err;
58 int i;
60 if ((handle = HostLib_Open(sofile, &err)) == NULL) {
61 D(bug("[ALSA] failed to open '%s': %s\n", sofile, err));
62 return NULL;
65 for (i = 0; i < nfuncs; i++) {
66 funcptr[i] = HostLib_GetPointer(handle, names[i], &err);
67 if (err != NULL) {
68 bug("[ALSA] failed to get symbol '%s' (%s)\n", names[i], err);
69 HostLib_Close(handle, NULL);
70 return NULL;
74 return handle;
77 BOOL ALSA_HostLib_Init()
79 HostLibBase = OpenResource("hostlib.resource");
81 if (!HostLibBase)
83 D(bug("[ALSA] failed to open hostlib.resource\n"));
84 return FALSE;
87 libasoundhandle = hostlib_load_so(LIBASOUND_SOFILE, alsa_func_names,
88 ALSA_NUM_FUNCS, (void **)&alsa_func);
90 if (!libasoundhandle)
92 bug("[ALSA] failed to open "LIBASOUND_SOFILE"\n");
93 return FALSE;
96 return TRUE;
99 VOID ALSA_HostLib_Cleanup()
101 if (libasoundhandle != NULL)
102 HostLib_Close(libasoundhandle, NULL);