aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cubeb_sndio.c
diff options
context:
space:
mode:
authorDuncan Overbruck <[email protected]>2019-12-09 23:13:24 +0100
committerMatthew Gregan <[email protected]>2019-12-10 16:26:39 +1300
commitbb2735fa2ff680fdc615edbb363b19ff4a759503 (patch)
tree5c22230eb51b97f159e59dca84d5835e0969f53c /src/cubeb_sndio.c
parent3025cbec70f3ed097ec9a2f33a4823316a29efc4 (diff)
downloadcubeb-bb2735fa2ff680fdc615edbb363b19ff4a759503.tar.gz
cubeb-bb2735fa2ff680fdc615edbb363b19ff4a759503.zip
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.
Diffstat (limited to 'src/cubeb_sndio.c')
-rw-r--r--src/cubeb_sndio.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/cubeb_sndio.c b/src/cubeb_sndio.c
index bdb2e97..34b3513 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;