From 35314c83976b4ebcfcaab370ab01842a901aac31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Sun, 14 Feb 2016 12:32:35 +0100 Subject: [PATCH] linux/audio: set ALSA device in the configuration Instead of only hardcoding "hw" read 'alsa_device' attribute from the config node to determine the proper playback device. The default value is still "hw" in case the attribute is not present. Fixes #1884. --- repos/os/src/drivers/audio/spec/linux/alsa.c | 4 ++-- repos/os/src/drivers/audio/spec/linux/alsa.h | 2 +- repos/os/src/drivers/audio/spec/linux/main.cc | 12 ++++++++++-- repos/os/src/drivers/audio/spec/linux/target.mk | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/repos/os/src/drivers/audio/spec/linux/alsa.c b/repos/os/src/drivers/audio/spec/linux/alsa.c index 993b24d89c..a07aa5b6b6 100644 --- a/repos/os/src/drivers/audio/spec/linux/alsa.c +++ b/repos/os/src/drivers/audio/spec/linux/alsa.c @@ -18,13 +18,13 @@ static snd_pcm_t *playback_handle; -int audio_drv_init(void) +int audio_drv_init(char const * const device) { unsigned int rate = 44100; int err; snd_pcm_hw_params_t *hw_params; - if ((err = snd_pcm_open(&playback_handle, "hw", SND_PCM_STREAM_PLAYBACK, 0)) < 0) + if ((err = snd_pcm_open(&playback_handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) return -1; if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) diff --git a/repos/os/src/drivers/audio/spec/linux/alsa.h b/repos/os/src/drivers/audio/spec/linux/alsa.h index 1390735168..11c2fd1d50 100644 --- a/repos/os/src/drivers/audio/spec/linux/alsa.h +++ b/repos/os/src/drivers/audio/spec/linux/alsa.h @@ -19,7 +19,7 @@ extern "C" { #endif -int audio_drv_init(void); +int audio_drv_init(char const * const); void audio_drv_adopt_myself(); int audio_drv_play(void *data, int frame_cnt); void audio_drv_stop(void); diff --git a/repos/os/src/drivers/audio/spec/linux/main.cc b/repos/os/src/drivers/audio/spec/linux/main.cc index 4f0e4c3f01..1089d4bb29 100644 --- a/repos/os/src/drivers/audio/spec/linux/main.cc +++ b/repos/os/src/drivers/audio/spec/linux/main.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include "alsa.h" @@ -269,10 +270,17 @@ int main(int argc, char **argv) static Signal_context data_context; static Signal_context_capability data_cap(data_recv.manage(&data_context)); + char dev[32] = { 'h', 'w', 0 }; + try { + Genode::Xml_node config = Genode::config()->xml_node(); + config.attribute("alsa_device").value(dev, sizeof(dev)); + } catch (...) { } + /* init ALSA */ - int err = audio_drv_init(); + int err = audio_drv_init(dev); if (err) { - PERR("audio driver init returned %d", err); + if (err == -1) PERR("Could not open ALSA device '%s'.", dev); + else PERR("audio driver init returned %d", err); return 0; } audio_drv_start(); diff --git a/repos/os/src/drivers/audio/spec/linux/target.mk b/repos/os/src/drivers/audio/spec/linux/target.mk index 20434725c6..f2e31531dd 100644 --- a/repos/os/src/drivers/audio/spec/linux/target.mk +++ b/repos/os/src/drivers/audio/spec/linux/target.mk @@ -1,6 +1,6 @@ REQUIRES = linux TARGET = audio_drv -LIBS = lx_hybrid +LIBS = lx_hybrid config SRC_CC = main.cc SRC_C = alsa.c LX_LIBS = alsa