From cacc8451a6d89bf9ae000d3765030baa257f539c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Fri, 29 Apr 2016 02:28:57 +0700 Subject: [PATCH] Copy alsa device list implementation to alsathread --- audio/drivers/alsathread.c | 64 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/audio/drivers/alsathread.c b/audio/drivers/alsathread.c index b9428754b2..83175b3c56 100644 --- a/audio/drivers/alsathread.c +++ b/audio/drivers/alsathread.c @@ -16,6 +16,8 @@ #include +#include + #include #include @@ -342,6 +344,64 @@ static size_t alsa_thread_buffer_size(void *data) return alsa->buffer_size; } +static void *alsa_device_list_new(void *data) +{ + void **hints, **n; + union string_list_elem_attr attr; + struct string_list *s = string_list_new(); + + if (!s) + return NULL; + + attr.i = 0; + + if (snd_device_name_hint(-1, "pcm", &hints) != 0) + goto error; + + n = hints; + + while (*n != NULL) + { + char *name = snd_device_name_get_hint(*n, "NAME"); + char *io = snd_device_name_get_hint(*n, "IOID"); + char *desc = snd_device_name_get_hint(*n, "DESC"); + + /* description of device IOID - input / output identifcation + * ("Input" or "Output"), NULL means both) */ + + if (io == NULL) + string_list_append(s, name, attr); + + if (name) + free(name); + if (io) + free(io); + if (desc) + free(desc); + + n++; + } + + /* free hint buffer too */ + snd_device_name_free_hint(hints); + + return s; + +error: + string_list_free(s); + return NULL; +} + +static void alsa_device_list_free(void *data, void *array_list_data) +{ + struct string_list *s = (struct string_list*)array_list_data; + + if (!s) + return; + + string_list_free(s); +} + audio_driver_t audio_alsathread = { alsa_thread_init, alsa_thread_write, @@ -352,8 +412,8 @@ audio_driver_t audio_alsathread = { alsa_thread_free, alsa_thread_use_float, "alsathread", - NULL, - NULL, + alsa_device_list_new, + alsa_device_list_free, alsa_thread_write_avail, alsa_thread_buffer_size, };