mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 13:47:56 +00:00
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:
parent
6b1923bbe6
commit
35314c8397
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <cap_session/connection.h>
|
||||
#include <audio_out_session/rpc_object.h>
|
||||
#include <util/misc_math.h>
|
||||
#include <os/config.h>
|
||||
|
||||
#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();
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user