solaris: new audio output plugin for Solaris /dev/audio

This commit is contained in:
Max Kellermann 2009-03-16 09:55:10 +01:00
parent 18cb4fa277
commit bba127a392
6 changed files with 237 additions and 0 deletions

View File

@ -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

1
NEWS
View File

@ -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

View File

@ -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 &&

View File

@ -424,6 +424,38 @@ cd mpd-0.14.2</programlisting>
or IceCast server. It forwards tags to this server.
</para>
</section>
<section>
<title><varname>solaris</varname></title>
<para>
The "Solaris" plugin runs only on SUN Solaris, and plays via
<filename>/dev/audio</filename>.
</para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>Setting</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>
<varname>device</varname>
<parameter>PATH</parameter>
</entry>
<entry>
Sets the path of the audio device, defaults to
<filename>/dev/audio</filename>.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</section>
</section>
</chapter>
</book>

View File

@ -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 <glib.h>
#include <sys/audio.h>
#include <sys/stropts.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#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,
};

View File

@ -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