From bba127a392486be31961e82fe577de1a8caa8e5c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 16 Mar 2009 09:55:10 +0100 Subject: solaris: new audio output plugin for Solaris /dev/audio --- Makefile.am | 4 + NEWS | 1 + configure.ac | 21 +++++ doc/user.xml | 32 +++++++ src/output/solaris_output_plugin.c | 175 +++++++++++++++++++++++++++++++++++++ src/output_list.c | 4 + 6 files changed, 237 insertions(+) create mode 100644 src/output/solaris_output_plugin.c diff --git a/Makefile.am b/Makefile.am index 007c3f353..28d128249 100644 --- a/Makefile.am +++ b/Makefile.am @@ -519,6 +519,10 @@ OUTPUT_SRC += \ src/output/httpd_output_plugin.c endif +if ENABLE_SOLARIS_OUTPUT +OUTPUT_SRC += src/output/solaris_output_plugin.c +endif + # # Sparse code analysis diff --git a/NEWS b/NEWS index 4da735343..a5b8ccc52 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,7 @@ ver 0.15 - (200?/??/??) - mvp: fixed default device detection - pipe: new audio output plugin which runs a command - alsa: better period_time default value for high sample rates + - solaris: new audio output plugin for Solaris /dev/audio * commands: - "playlistinfo" supports a range now - added "sticker database", command "sticker", which allows clients diff --git a/configure.ac b/configure.ac index ed9703fed..cd14c42f6 100644 --- a/configure.ac +++ b/configure.ac @@ -594,6 +594,20 @@ if test x$enable_shout = xyes; then enable_shout=no) fi +case "$host_os" in + solaris*) + AC_DEFINE(ENABLE_SOLARIS_OUTPUT, 1, [Define to enable Solaris /dev/audio support]) + enable_solaris_output=yes + ;; + + *) + enable_solaris_output=no + ;; +esac +echo "HOST_OS=$host_os" + +AM_CONDITIONAL(ENABLE_SOLARIS_OUTPUT, test x$enable_solaris_output = xyes) + if test x$enable_oggvorbis_encoder = xyes; then if test x$enable_oggvorbis = xno; then AC_MSG_WARN([disabling ogg shout streaming support because vorbis is not enabled]) @@ -1144,6 +1158,12 @@ else echo " SHOUTcast support .............disabled" fi +if test x$enable_solaris_output = xyes; then + echo " Solaris /dev/audio support ....enabled" +else + echo " Solaris /dev/audio support ....disabled" +fi + echo "" if @@ -1151,6 +1171,7 @@ if test x$enable_oss = xno && test x$enable_shout = xno && test x$enable_httpd_output = xno && + test x$enable_solaris_output = xno && test x$enable_alsa = xno && test x$enable_osx = xno && test x$enable_pulse = xno && diff --git a/doc/user.xml b/doc/user.xml index 6837181a9..7276429cd 100644 --- a/doc/user.xml +++ b/doc/user.xml @@ -424,6 +424,38 @@ cd mpd-0.14.2 or IceCast server. It forwards tags to this server. + +
+ <varname>solaris</varname> + + + The "Solaris" plugin runs only on SUN Solaris, and plays via + /dev/audio. + + + + + + + Setting + Description + + + + + + device + PATH + + + Sets the path of the audio device, defaults to + /dev/audio. + + + + + +
diff --git a/src/output/solaris_output_plugin.c b/src/output/solaris_output_plugin.c new file mode 100644 index 000000000..5febf0afc --- /dev/null +++ b/src/output/solaris_output_plugin.c @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2003-2009 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "output_api.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + +#undef G_LOG_DOMAIN +#define G_LOG_DOMAIN "solaris_output" + +struct solaris_output { + /* configuration */ + const char *device; + + int fd; +}; + +/** + * The quark used for GError.domain. + */ +static inline GQuark +solaris_output_quark(void) +{ + return g_quark_from_static_string("solaris_output"); +} + +static bool +solaris_output_test_default_device(void) +{ + struct stat st; + + return stat("/dev/audio", &st) == 0 && S_ISCHR(st.st_mode) && + access("/dev/audio", W_OK) == 0; +} + +static void * +solaris_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, + const struct config_param *param, + G_GNUC_UNUSED GError **error) +{ + struct solaris_output *so = g_new(struct solaris_output, 1); + + so->device = config_get_block_string(param, "device", "/dev/audio"); + + return so; +} + +static void +solaris_output_finish(void *data) +{ + struct solaris_output *so = data; + + g_free(so); +} + +static bool +solaris_output_open(void *data, struct audio_format *audio_format, + GError **error) +{ + struct solaris_output *so = data; + struct audio_info info; + int ret, flags; + + /* support only 16 bit mono/stereo for now; nothing else has + been tested */ + audio_format->bits = 16; + + /* open the device in non-blocking mode */ + + so->fd = open(so->device, O_WRONLY|O_NONBLOCK); + if (so->fd < 0) { + g_set_error(error, solaris_output_quark(), errno, + "Failed to open %s: %s", + so->device, g_strerror(errno)); + return false; + } + + /* restore blocking mode */ + + flags = fcntl(so->fd, F_GETFL); + if (flags > 0 && (flags & O_NONBLOCK) != 0) + fcntl(so->fd, F_SETFL, flags & ~O_NONBLOCK); + + /* configure the audio device */ + + ret = ioctl(so->fd, AUDIO_GETINFO, &info); + if (ret < 0) { + g_set_error(error, solaris_output_quark(), errno, + "AUDIO_GETINFO failed: %s", g_strerror(errno)); + close(so->fd); + return false; + } + + info.play.sample_rate = audio_format->sample_rate; + info.play.channels = audio_format->channels; + info.play.precision = audio_format->bits; + info.play.encoding = AUDIO_ENCODING_LINEAR; + + ret = ioctl(so->fd, AUDIO_SETINFO, &info); + if (ret < 0) { + g_set_error(error, solaris_output_quark(), errno, + "AUDIO_SETINFO failed: %s", g_strerror(errno)); + close(so->fd); + return false; + } + + return true; +} + +static void +solaris_output_close(void *data) +{ + struct solaris_output *so = data; + + close(so->fd); +} + +static size_t +solaris_output_play(void *data, const void *chunk, size_t size, GError **error) +{ + struct solaris_output *so = data; + ssize_t nbytes; + + nbytes = write(so->fd, chunk, size); + if (nbytes <= 0) { + g_set_error(error, solaris_output_quark(), errno, + "Write failed: %s", g_strerror(errno)); + return 0; + } + + return nbytes; +} + +static void +solaris_output_cancel(void *data) +{ + struct solaris_output *so = data; + + ioctl(so->fd, I_FLUSH); +} + +const struct audio_output_plugin solaris_output_plugin = { + .name = "solaris", + .test_default_device = solaris_output_test_default_device, + .init = solaris_output_init, + .finish = solaris_output_finish, + .open = solaris_output_open, + .close = solaris_output_close, + .play = solaris_output_play, + .cancel = solaris_output_cancel, +}; diff --git a/src/output_list.c b/src/output_list.c index f2e107584..f1569abf9 100644 --- a/src/output_list.c +++ b/src/output_list.c @@ -29,6 +29,7 @@ extern const struct audio_output_plugin alsaPlugin; extern const struct audio_output_plugin ao_output_plugin; extern const struct audio_output_plugin oss_output_plugin; extern const struct audio_output_plugin osxPlugin; +extern const struct audio_output_plugin solaris_output_plugin; extern const struct audio_output_plugin pulse_plugin; extern const struct audio_output_plugin mvp_output_plugin; extern const struct audio_output_plugin jackPlugin; @@ -57,6 +58,9 @@ const struct audio_output_plugin *audio_output_plugins[] = { #ifdef HAVE_OSX &osxPlugin, #endif +#ifdef ENABLE_SOLARIS_OUTPUT + &solaris_output_plugin, +#endif #ifdef HAVE_PULSE &pulse_plugin, #endif -- cgit v1.2.3