From 629e202f1b4f73a1374690ea3649a012a75eab30 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 5 Sep 2013 03:24:23 +0200 Subject: [PATCH] add support for openbsd sndio sound daemon --- Makefile | 4 +++ audio.c | 6 ++++ audio_sndio.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ configure | 6 ++++ 4 files changed, 100 insertions(+) create mode 100644 audio_sndio.c diff --git a/Makefile b/Makefile index 47fd69e7..7a5c3051 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,10 @@ PREFIX ?= /usr/local SRCS := shairport.c daemon.c rtsp.c mdns.c common.c rtp.c player.c alac.c audio.c audio_dummy.c audio_pipe.c +ifdef CONFIG_SNDIO +SRCS += audio_sndio.c +endif + ifdef CONFIG_AO SRCS += audio_ao.c endif diff --git a/audio.c b/audio.c index 1a72cb96..a39c74dd 100644 --- a/audio.c +++ b/audio.c @@ -29,6 +29,9 @@ #include "audio.h" #include "config.h" +#ifdef CONFIG_SNDIO +extern audio_output audio_sndio; +#endif #ifdef CONFIG_AO extern audio_output audio_ao; #endif @@ -41,6 +44,9 @@ extern audio_output audio_alsa; extern audio_output audio_dummy, audio_pipe; static audio_output *outputs[] = { +#ifdef CONFIG_SNDIO + &audio_sndio, +#endif #ifdef CONFIG_ALSA &audio_alsa, #endif diff --git a/audio_sndio.c b/audio_sndio.c new file mode 100644 index 00000000..2120e873 --- /dev/null +++ b/audio_sndio.c @@ -0,0 +1,84 @@ +/* + * sndio output driver. This file is part of Shairport. + * Copyright (c) 2013 Dimitri Sokolyuk + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include "audio.h" + +static struct sio_hdl *sio; +static struct sio_par par; + +static int init(int argc, char **argv) { + sio = sio_open(SIO_DEVANY, SIO_PLAY, 0); + if (!sio) + die("sndio: cannoct connect to sound server"); + + sio_initpar(&par); + + par.bits = 16; + par.rate = 44100; + par.pchan = 2; + par.le = SIO_LE_NATIVE; + par.sig = 1; + + if (!sio_setpar(sio, &par)) + die("sndio: failed to set audio parameters"); + if (!sio_getpar(sio, &par)) + die("sndio: failed to get audio parameters"); + + return 0; +} + +static void deinit(void) { + sio_close(sio); +} + +static void start(int sample_rate) { + if (sample_rate != par.rate) + die("unexpected sample rate!"); + sio_start(sio); +} + +static void play(short buf[], int samples) { + sio_write(sio, (char *)buf, samples * par.bps * par.pchan); +} + +static void stop(void) { + sio_stop(sio); +} + +static void help(void) { + printf(" There are no options for sndio audio.\n"); + printf(" Use AUDIODEVICE environment variable.\n"); +} + +static void volume(double vol) { + unsigned int v = vol * SIO_MAXVOL; + sio_setvol(sio, v); +} + +audio_output audio_sndio = { + .name = "sndio", + .help = &help, + .init = &init, + .deinit = &deinit, + .start = &start, + .stop = &stop, + .play = &play, + .volume = &volume +}; diff --git a/configure b/configure index e1dfc67c..bbefbeb8 100755 --- a/configure +++ b/configure @@ -43,6 +43,12 @@ do_pkg_config PulseAudio libpulse-simple CONFIG_PULSE do_pkg_config ALSA alsa CONFIG_ALSA do_pkg_config Avahi\ client avahi-client CONFIG_AVAHI +if [ `uname` == 'OpenBSD' ]; then + echo "OpenBSD machine, use sndio" + echo "#define CONFIG_SNDIO" >> config.h + echo "CONFIG_SNDIO=yes" >> config.mk + LDFLAGS="${LDFLAGS} -lsndio" +fi echo "CFLAGS+=${CFLAGS}" >> config.mk echo "LDFLAGS+=${LDFLAGS}" >> config.mk