Skip to content

Commit

Permalink
sndio: test if sndio works in sndio_init
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Duncaen authored and kinetiknz committed Dec 10, 2019
1 parent 3025cbe commit bb2735f
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/cubeb_sndio.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bb2735f

Please sign in to comment.