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.
This commit is contained in:
Josef Söntgen 2016-02-14 12:32:35 +01:00
parent 6b1923bbe6
commit 35314c8397
4 changed files with 14 additions and 6 deletions

View File

@ -18,13 +18,13 @@
static snd_pcm_t *playback_handle; static snd_pcm_t *playback_handle;
int audio_drv_init(void) int audio_drv_init(char const * const device)
{ {
unsigned int rate = 44100; unsigned int rate = 44100;
int err; int err;
snd_pcm_hw_params_t *hw_params; 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; return -1;
if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0) if ((err = snd_pcm_hw_params_malloc(&hw_params)) < 0)

View File

@ -19,7 +19,7 @@
extern "C" { extern "C" {
#endif #endif
int audio_drv_init(void); int audio_drv_init(char const * const);
void audio_drv_adopt_myself(); void audio_drv_adopt_myself();
int audio_drv_play(void *data, int frame_cnt); int audio_drv_play(void *data, int frame_cnt);
void audio_drv_stop(void); void audio_drv_stop(void);

View File

@ -22,6 +22,7 @@
#include <cap_session/connection.h> #include <cap_session/connection.h>
#include <audio_out_session/rpc_object.h> #include <audio_out_session/rpc_object.h>
#include <util/misc_math.h> #include <util/misc_math.h>
#include <os/config.h>
#include "alsa.h" #include "alsa.h"
@ -269,10 +270,17 @@ int main(int argc, char **argv)
static Signal_context data_context; static Signal_context data_context;
static Signal_context_capability data_cap(data_recv.manage(&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 */ /* init ALSA */
int err = audio_drv_init(); int err = audio_drv_init(dev);
if (err) { 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; return 0;
} }
audio_drv_start(); audio_drv_start();

View File

@ -1,6 +1,6 @@
REQUIRES = linux REQUIRES = linux
TARGET = audio_drv TARGET = audio_drv
LIBS = lx_hybrid LIBS = lx_hybrid config
SRC_CC = main.cc SRC_CC = main.cc
SRC_C = alsa.c SRC_C = alsa.c
LX_LIBS = alsa LX_LIBS = alsa