From bb2735fa2ff680fdc615edbb363b19ff4a759503 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Mon, 9 Dec 2019 23:13:24 +0100 Subject: [PATCH] sndio: test if sndio works in sndio_init This avoids issues when uses have libsndio installed but are not using it, also prefer sndio devices i.e. snd/0 by default on platforms other than OpenBSD. This way cubebs alsa backend can be used insted of using libsndio code which will use alsa directly, but with no benefit over cubebs implementation. --- src/cubeb_sndio.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/cubeb_sndio.c b/src/cubeb_sndio.c index bdb2e97a1..34b3513d5 100644 --- a/src/cubeb_sndio.c +++ b/src/cubeb_sndio.c @@ -125,6 +125,23 @@ s16_to_float(void *ptr, long nsamp) *(--dst) = (1. / 32768) * *(--src); } +static const char * +sndio_get_device() +{ +#ifndef __OpenBSD__ + /* + * On other platforms default to sndio devices, + * so cubebs other backends can be used instead. + */ + const char *dev = getenv("AUDIODEVICE"); + if (dev == NULL || *dev == '\0') + return "snd/0"; + return dev; +#else + return SIO_DEVANY; +#endif +} + static void sndio_onmove(void *arg, int delta) { @@ -288,6 +305,7 @@ sndio_mainloop(void *arg) sndio_init(cubeb **context, char const *context_name) { void * libsndio = NULL; + struct sio_hdl *hdl; assert(context); @@ -314,6 +332,13 @@ sndio_init(cubeb **context, char const *context_name) #undef LOAD #endif + /* test if sndio works */ + hdl = WRAP(sio_open)(sndio_get_device(), SIO_PLAY, 1); + if (hdl == NULL) { + return CUBEB_ERROR; + } + WRAP(sio_close)(hdl); + DPR("sndio_init(%s)\n", context_name); *context = malloc(sizeof(**context)); if (*context == NULL) @@ -388,7 +413,7 @@ sndio_stream_init(cubeb * context, goto err; } s->context = context; - s->hdl = WRAP(sio_open)(NULL, s->mode, 1); + s->hdl = WRAP(sio_open)(sndio_get_device(), s->mode, 1); if (s->hdl == NULL) { DPR("sndio_stream_init(), sio_open() failed\n"); goto err;