2004-10-29 05:30:23 +02:00
|
|
|
/* the Music Player Daemon (MPD)
|
2007-04-05 05:22:33 +02:00
|
|
|
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
|
2004-10-29 05:30:23 +02:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
2007-04-05 05:22:33 +02:00
|
|
|
* OSS audio output (c) 2004, 2005, 2006, 2007 by Eric Wong <eric@petta-tech.com>
|
2006-07-12 04:34:23 +02:00
|
|
|
* and Warren Dukes <warren.dukes@gmail.com>
|
2004-10-29 05:30:23 +02:00
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2004-11-02 13:46:52 +01:00
|
|
|
#include "../audioOutput.h"
|
2004-10-29 05:30:23 +02:00
|
|
|
|
2004-10-30 06:19:11 +02:00
|
|
|
#include <stdlib.h>
|
2004-10-29 05:30:23 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_OSS
|
|
|
|
|
2004-11-02 13:46:52 +01:00
|
|
|
#include "../conf.h"
|
|
|
|
#include "../log.h"
|
2004-10-29 05:30:23 +02:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#if defined(__OpenBSD__) || defined(__NetBSD__)
|
|
|
|
# include <soundcard.h>
|
2006-07-20 20:53:56 +02:00
|
|
|
#else /* !(defined(__OpenBSD__) || defined(__NetBSD__) */
|
2004-10-29 05:30:23 +02:00
|
|
|
# include <sys/soundcard.h>
|
2006-07-20 20:53:56 +02:00
|
|
|
#endif /* !(defined(__OpenBSD__) || defined(__NetBSD__) */
|
2004-10-29 05:30:23 +02:00
|
|
|
|
2006-03-25 06:33:14 +01:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
# define AFMT_S16_MPD AFMT_S16_BE
|
|
|
|
#else
|
|
|
|
# define AFMT_S16_MPD AFMT_S16_LE
|
2006-07-20 20:53:56 +02:00
|
|
|
#endif /* WORDS_BIGENDIAN */
|
2006-03-25 06:33:14 +01:00
|
|
|
|
2004-10-30 06:19:11 +02:00
|
|
|
typedef struct _OssData {
|
2004-10-29 06:11:10 +02:00
|
|
|
int fd;
|
2006-08-01 14:39:10 +02:00
|
|
|
const char *device;
|
2005-03-05 15:01:13 +01:00
|
|
|
int channels;
|
|
|
|
int sampleRate;
|
|
|
|
int bitFormat;
|
|
|
|
int bits;
|
2006-07-20 18:02:40 +02:00
|
|
|
int *supported[3];
|
2005-03-10 03:47:18 +01:00
|
|
|
int numSupported[3];
|
2006-07-20 18:02:40 +02:00
|
|
|
int *unsupported[3];
|
2005-03-10 03:47:18 +01:00
|
|
|
int numUnsupported[3];
|
2004-10-29 05:30:23 +02:00
|
|
|
} OssData;
|
|
|
|
|
2005-03-10 03:47:18 +01:00
|
|
|
#define OSS_SUPPORTED 1
|
|
|
|
#define OSS_UNSUPPORTED 0
|
|
|
|
#define OSS_UNKNOWN -1
|
|
|
|
|
|
|
|
#define OSS_RATE 0
|
|
|
|
#define OSS_CHANNELS 1
|
|
|
|
#define OSS_BITS 2
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int getIndexForParam(int param)
|
|
|
|
{
|
2005-03-10 03:47:18 +01:00
|
|
|
int index = 0;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
switch (param) {
|
2005-03-10 03:47:18 +01:00
|
|
|
case SNDCTL_DSP_SPEED:
|
|
|
|
index = OSS_RATE;
|
|
|
|
break;
|
|
|
|
case SNDCTL_DSP_CHANNELS:
|
|
|
|
index = OSS_CHANNELS;
|
|
|
|
break;
|
|
|
|
case SNDCTL_DSP_SAMPLESIZE:
|
|
|
|
index = OSS_BITS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int findSupportedParam(OssData * od, int param, int val)
|
|
|
|
{
|
2005-03-10 03:47:18 +01:00
|
|
|
int i;
|
|
|
|
int index = getIndexForParam(param);
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
for (i = 0; i < od->numSupported[index]; i++) {
|
|
|
|
if (od->supported[index][i] == val)
|
|
|
|
return 1;
|
2005-03-10 03:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int canConvert(int index, int val)
|
|
|
|
{
|
|
|
|
switch (index) {
|
2005-03-10 03:47:18 +01:00
|
|
|
case OSS_BITS:
|
2006-07-20 18:02:40 +02:00
|
|
|
if (val != 16)
|
|
|
|
return 0;
|
2005-03-10 03:47:18 +01:00
|
|
|
break;
|
|
|
|
case OSS_CHANNELS:
|
2006-07-20 18:02:40 +02:00
|
|
|
if (val != 2)
|
|
|
|
return 0;
|
2005-03-10 03:47:18 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int getSupportedParam(OssData * od, int param, int val)
|
|
|
|
{
|
2005-03-10 03:47:18 +01:00
|
|
|
int i;
|
|
|
|
int index = getIndexForParam(param);
|
|
|
|
int ret = -1;
|
|
|
|
int least = val;
|
|
|
|
int diff;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
for (i = 0; i < od->numSupported[index]; i++) {
|
|
|
|
diff = od->supported[index][i] - val;
|
|
|
|
if (diff < 0)
|
|
|
|
diff = -diff;
|
|
|
|
if (diff < least) {
|
|
|
|
if (!canConvert(index, od->supported[index][i])) {
|
2005-03-10 03:47:18 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
least = diff;
|
|
|
|
ret = od->supported[index][i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int findUnsupportedParam(OssData * od, int param, int val)
|
|
|
|
{
|
2005-03-10 03:47:18 +01:00
|
|
|
int i;
|
|
|
|
int index = getIndexForParam(param);
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
for (i = 0; i < od->numUnsupported[index]; i++) {
|
|
|
|
if (od->unsupported[index][i] == val)
|
|
|
|
return 1;
|
2005-03-10 03:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void addSupportedParam(OssData * od, int param, int val)
|
|
|
|
{
|
2005-03-10 03:47:18 +01:00
|
|
|
int index = getIndexForParam(param);
|
|
|
|
|
|
|
|
od->numSupported[index]++;
|
2006-08-26 08:25:57 +02:00
|
|
|
od->supported[index] = xrealloc(od->supported[index],
|
2006-07-20 18:02:40 +02:00
|
|
|
od->numSupported[index] * sizeof(int));
|
|
|
|
od->supported[index][od->numSupported[index] - 1] = val;
|
2005-03-10 03:47:18 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void addUnsupportedParam(OssData * od, int param, int val)
|
|
|
|
{
|
2005-03-10 03:47:18 +01:00
|
|
|
int index = getIndexForParam(param);
|
|
|
|
|
|
|
|
od->numUnsupported[index]++;
|
2006-08-26 08:25:57 +02:00
|
|
|
od->unsupported[index] = xrealloc(od->unsupported[index],
|
2006-07-20 18:02:40 +02:00
|
|
|
od->numUnsupported[index] *
|
|
|
|
sizeof(int));
|
|
|
|
od->unsupported[index][od->numUnsupported[index] - 1] = val;
|
2005-03-10 03:47:18 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void removeSupportedParam(OssData * od, int param, int val)
|
|
|
|
{
|
2005-03-10 03:47:18 +01:00
|
|
|
int i = 0;
|
|
|
|
int j = 0;
|
|
|
|
int index = getIndexForParam(param);
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < od->numSupported[index] - 1; i++) {
|
|
|
|
if (od->supported[index][i] == val)
|
|
|
|
j = 1;
|
|
|
|
od->supported[index][i] = od->supported[index][i + j];
|
2005-03-10 03:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
od->numSupported[index]--;
|
2006-08-26 08:25:57 +02:00
|
|
|
od->supported[index] = xrealloc(od->supported[index],
|
2006-07-20 18:02:40 +02:00
|
|
|
od->numSupported[index] * sizeof(int));
|
2005-03-10 03:47:18 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void removeUnsupportedParam(OssData * od, int param, int val)
|
|
|
|
{
|
2005-03-10 03:47:18 +01:00
|
|
|
int i = 0;
|
|
|
|
int j = 0;
|
|
|
|
int index = getIndexForParam(param);
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < od->numUnsupported[index] - 1; i++) {
|
|
|
|
if (od->unsupported[index][i] == val)
|
|
|
|
j = 1;
|
|
|
|
od->unsupported[index][i] = od->unsupported[index][i + j];
|
2005-03-10 03:47:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
od->numUnsupported[index]--;
|
2006-08-26 08:25:57 +02:00
|
|
|
od->unsupported[index] = xrealloc(od->unsupported[index],
|
2006-07-20 18:02:40 +02:00
|
|
|
od->numUnsupported[index] *
|
|
|
|
sizeof(int));
|
2005-03-10 03:47:18 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int isSupportedParam(OssData * od, int param, int val)
|
|
|
|
{
|
|
|
|
if (findSupportedParam(od, param, val))
|
|
|
|
return OSS_SUPPORTED;
|
|
|
|
if (findUnsupportedParam(od, param, val))
|
|
|
|
return OSS_UNSUPPORTED;
|
2005-03-10 03:47:18 +01:00
|
|
|
return OSS_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void supportParam(OssData * od, int param, int val)
|
|
|
|
{
|
2005-03-10 03:47:18 +01:00
|
|
|
int supported = isSupportedParam(od, param, val);
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (supported == OSS_SUPPORTED)
|
|
|
|
return;
|
2005-03-10 03:47:18 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (supported == OSS_UNSUPPORTED) {
|
2005-03-10 03:47:18 +01:00
|
|
|
removeUnsupportedParam(od, param, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
addSupportedParam(od, param, val);
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void unsupportParam(OssData * od, int param, int val)
|
|
|
|
{
|
2005-03-10 03:47:18 +01:00
|
|
|
int supported = isSupportedParam(od, param, val);
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (supported == OSS_UNSUPPORTED)
|
|
|
|
return;
|
2005-03-10 03:47:18 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (supported == OSS_SUPPORTED) {
|
2005-03-10 03:47:18 +01:00
|
|
|
removeSupportedParam(od, param, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
addUnsupportedParam(od, param, val);
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static OssData *newOssData(void)
|
|
|
|
{
|
2006-08-26 08:25:57 +02:00
|
|
|
OssData *ret = xmalloc(sizeof(OssData));
|
2004-10-29 05:30:23 +02:00
|
|
|
|
2004-10-29 06:11:10 +02:00
|
|
|
ret->device = NULL;
|
|
|
|
ret->fd = -1;
|
2004-10-29 05:30:23 +02:00
|
|
|
|
2005-03-10 03:47:18 +01:00
|
|
|
ret->supported[OSS_RATE] = NULL;
|
|
|
|
ret->supported[OSS_CHANNELS] = NULL;
|
|
|
|
ret->supported[OSS_BITS] = NULL;
|
|
|
|
ret->unsupported[OSS_RATE] = NULL;
|
|
|
|
ret->unsupported[OSS_CHANNELS] = NULL;
|
|
|
|
ret->unsupported[OSS_BITS] = NULL;
|
|
|
|
|
|
|
|
ret->numSupported[OSS_RATE] = 0;
|
|
|
|
ret->numSupported[OSS_CHANNELS] = 0;
|
|
|
|
ret->numSupported[OSS_BITS] = 0;
|
|
|
|
ret->numUnsupported[OSS_RATE] = 0;
|
|
|
|
ret->numUnsupported[OSS_CHANNELS] = 0;
|
|
|
|
ret->numUnsupported[OSS_BITS] = 0;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
supportParam(ret, SNDCTL_DSP_SPEED, 48000);
|
|
|
|
supportParam(ret, SNDCTL_DSP_SPEED, 44100);
|
|
|
|
supportParam(ret, SNDCTL_DSP_CHANNELS, 2);
|
|
|
|
supportParam(ret, SNDCTL_DSP_SAMPLESIZE, 16);
|
2005-03-10 03:47:18 +01:00
|
|
|
|
2004-10-29 05:30:23 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void freeOssData(OssData * od)
|
|
|
|
{
|
|
|
|
if (od->supported[OSS_RATE])
|
|
|
|
free(od->supported[OSS_RATE]);
|
|
|
|
if (od->supported[OSS_CHANNELS])
|
|
|
|
free(od->supported[OSS_CHANNELS]);
|
|
|
|
if (od->supported[OSS_BITS])
|
|
|
|
free(od->supported[OSS_BITS]);
|
|
|
|
if (od->unsupported[OSS_RATE])
|
|
|
|
free(od->unsupported[OSS_RATE]);
|
|
|
|
if (od->unsupported[OSS_CHANNELS])
|
|
|
|
free(od->unsupported[OSS_CHANNELS]);
|
|
|
|
if (od->unsupported[OSS_BITS])
|
|
|
|
free(od->unsupported[OSS_BITS]);
|
2005-03-10 03:47:18 +01:00
|
|
|
|
2004-10-29 05:30:23 +02:00
|
|
|
free(od);
|
|
|
|
}
|
|
|
|
|
2005-03-05 04:36:24 +01:00
|
|
|
#define OSS_STAT_NO_ERROR 0
|
|
|
|
#define OSS_STAT_NOT_CHAR_DEV -1
|
|
|
|
#define OSS_STAT_NO_PERMS -2
|
|
|
|
#define OSS_STAT_DOESN_T_EXIST -3
|
|
|
|
#define OSS_STAT_OTHER -4
|
|
|
|
|
2006-08-01 14:39:10 +02:00
|
|
|
static int oss_statDevice(const char *device, int *stErrno)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2005-03-05 04:36:24 +01:00
|
|
|
struct stat st;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
if (0 == stat(device, &st)) {
|
|
|
|
if (!S_ISCHR(st.st_mode)) {
|
2005-03-05 04:36:24 +01:00
|
|
|
return OSS_STAT_NOT_CHAR_DEV;
|
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
} else {
|
2005-03-05 04:36:24 +01:00
|
|
|
*stErrno = errno;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
switch (errno) {
|
2005-03-05 04:36:24 +01:00
|
|
|
case ENOENT:
|
|
|
|
case ENOTDIR:
|
|
|
|
return OSS_STAT_DOESN_T_EXIST;
|
|
|
|
case EACCES:
|
|
|
|
return OSS_STAT_NO_PERMS;
|
|
|
|
default:
|
|
|
|
return OSS_STAT_OTHER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-08-01 14:39:10 +02:00
|
|
|
static const char *default_devices[] = { "/dev/sound/dsp", "/dev/dsp" };
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int oss_testDefault(void)
|
|
|
|
{
|
2006-08-01 14:39:10 +02:00
|
|
|
int fd, i;
|
2005-03-12 04:10:09 +01:00
|
|
|
|
2006-08-01 14:39:10 +02:00
|
|
|
for (i = ARRAY_SIZE(default_devices); --i >= 0; ) {
|
|
|
|
if ((fd = open(default_devices[i], O_WRONLY)) >= 0) {
|
|
|
|
xclose(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
WARNING("Error opening OSS device \"%s\": %s\n",
|
|
|
|
default_devices[i], strerror(errno));
|
2005-03-12 04:10:09 +01:00
|
|
|
}
|
|
|
|
|
2006-08-01 14:39:10 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2005-03-12 04:10:09 +01:00
|
|
|
|
2006-08-01 14:39:10 +02:00
|
|
|
static int oss_open_default(AudioOutput *ao, ConfigParam *param, OssData *od)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int err[ARRAY_SIZE(default_devices)];
|
|
|
|
int ret[ARRAY_SIZE(default_devices)];
|
2005-03-12 04:10:09 +01:00
|
|
|
|
2006-08-01 14:39:10 +02:00
|
|
|
for (i = ARRAY_SIZE(default_devices); --i >= 0; ) {
|
|
|
|
ret[i] = oss_statDevice(default_devices[i], &err[i]);
|
|
|
|
if (ret[i] == 0) {
|
|
|
|
od->device = default_devices[i];
|
|
|
|
return 0;
|
|
|
|
}
|
2005-03-12 04:10:09 +01:00
|
|
|
}
|
|
|
|
|
2006-08-01 14:39:10 +02:00
|
|
|
if (param)
|
2007-05-26 20:15:54 +02:00
|
|
|
ERROR("error trying to open specified OSS device"
|
2006-08-01 14:39:10 +02:00
|
|
|
" at line %i\n", param->line);
|
|
|
|
else
|
|
|
|
ERROR("error trying to open default OSS device\n");
|
|
|
|
|
2006-08-26 08:25:52 +02:00
|
|
|
for (i = ARRAY_SIZE(default_devices); --i >= 0; ) {
|
2006-08-01 14:39:10 +02:00
|
|
|
const char *dev = default_devices[i];
|
|
|
|
switch(ret[i]) {
|
|
|
|
case OSS_STAT_DOESN_T_EXIST:
|
|
|
|
ERROR("%s not found\n", dev);
|
|
|
|
break;
|
|
|
|
case OSS_STAT_NOT_CHAR_DEV:
|
|
|
|
ERROR("%s is not a character device\n", dev);
|
|
|
|
break;
|
|
|
|
case OSS_STAT_NO_PERMS:
|
|
|
|
ERROR("%s: permission denied\n", dev);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERROR("Error accessing %s: %s", dev, strerror(err[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
return 0; /* some compilers can be dumb... */
|
2005-03-12 04:10:09 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int oss_initDriver(AudioOutput * audioOutput, ConfigParam * param)
|
|
|
|
{
|
2006-08-01 14:39:10 +02:00
|
|
|
OssData *od = newOssData();
|
2004-10-29 06:11:10 +02:00
|
|
|
audioOutput->data = od;
|
2006-08-01 14:39:10 +02:00
|
|
|
if (param) {
|
|
|
|
BlockParam *bp = getBlockParam(param, "device");
|
|
|
|
if (bp) {
|
|
|
|
od->device = bp->value;
|
|
|
|
return 0;
|
2004-10-29 06:11:10 +02:00
|
|
|
}
|
2006-08-01 14:39:10 +02:00
|
|
|
}
|
|
|
|
return oss_open_default(audioOutput, param, od);
|
2004-10-29 05:30:23 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void oss_finishDriver(AudioOutput * audioOutput)
|
|
|
|
{
|
|
|
|
OssData *od = audioOutput->data;
|
2004-10-29 05:30:23 +02:00
|
|
|
|
|
|
|
freeOssData(od);
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int setParam(OssData * od, int param, int *value)
|
|
|
|
{
|
2005-03-10 03:47:18 +01:00
|
|
|
int val = *value;
|
|
|
|
int copy;
|
|
|
|
int supported = isSupportedParam(od, param, val);
|
|
|
|
|
|
|
|
do {
|
2006-07-20 18:02:40 +02:00
|
|
|
if (supported == OSS_UNSUPPORTED) {
|
2005-03-10 03:47:18 +01:00
|
|
|
val = getSupportedParam(od, param, val);
|
2006-07-20 18:02:40 +02:00
|
|
|
if (copy < 0)
|
|
|
|
return -1;
|
2005-03-10 03:47:18 +01:00
|
|
|
}
|
|
|
|
copy = val;
|
2006-07-20 18:02:40 +02:00
|
|
|
if (ioctl(od->fd, param, ©)) {
|
2005-03-10 03:47:18 +01:00
|
|
|
unsupportParam(od, param, val);
|
|
|
|
supported = OSS_UNSUPPORTED;
|
2006-07-20 18:02:40 +02:00
|
|
|
} else {
|
|
|
|
if (supported == OSS_UNKNOWN) {
|
2005-03-10 03:47:18 +01:00
|
|
|
supportParam(od, param, val);
|
|
|
|
supported = OSS_SUPPORTED;
|
|
|
|
}
|
|
|
|
val = copy;
|
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
} while (supported == OSS_UNSUPPORTED);
|
2005-03-10 03:47:18 +01:00
|
|
|
|
|
|
|
*value = val;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-16 18:53:04 +02:00
|
|
|
static void oss_close(OssData * od)
|
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
if (od->fd >= 0)
|
|
|
|
while (close(od->fd) && errno == EINTR) ;
|
2006-07-16 18:53:04 +02:00
|
|
|
od->fd = -1;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int oss_open(AudioOutput * audioOutput)
|
|
|
|
{
|
2006-03-25 06:33:14 +01:00
|
|
|
int tmp;
|
2006-07-20 18:02:40 +02:00
|
|
|
OssData *od = audioOutput->data;
|
2005-03-05 04:36:24 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if ((od->fd = open(od->device, O_WRONLY)) < 0) {
|
|
|
|
ERROR("Error opening OSS device \"%s\": %s\n", od->device,
|
|
|
|
strerror(errno));
|
2005-03-05 15:01:13 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (setParam(od, SNDCTL_DSP_CHANNELS, &od->channels)) {
|
|
|
|
ERROR("OSS device \"%s\" does not support %i channels: %s\n",
|
|
|
|
od->device, od->channels, strerror(errno));
|
2005-03-05 15:01:13 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
2005-03-05 04:36:24 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (setParam(od, SNDCTL_DSP_SPEED, &od->sampleRate)) {
|
|
|
|
ERROR("OSS device \"%s\" does not support %i Hz audio: %s\n",
|
|
|
|
od->device, od->sampleRate, strerror(errno));
|
2005-03-05 15:01:13 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
2005-03-05 04:36:24 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
switch (od->bits) {
|
2006-03-25 06:33:14 +01:00
|
|
|
case 8:
|
|
|
|
tmp = AFMT_S8;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
tmp = AFMT_S16_MPD;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (setParam(od, SNDCTL_DSP_SAMPLESIZE, &tmp)) {
|
|
|
|
ERROR("OSS device \"%s\" does not support %i bit audio: %s\n",
|
|
|
|
od->device, tmp, strerror(errno));
|
2005-03-05 15:01:13 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
2004-10-30 06:19:11 +02:00
|
|
|
|
|
|
|
audioOutput->open = 1;
|
2004-10-29 05:30:23 +02:00
|
|
|
|
|
|
|
return 0;
|
2004-10-30 06:19:11 +02:00
|
|
|
|
2006-08-20 12:13:54 +02:00
|
|
|
fail:
|
2006-07-16 18:53:04 +02:00
|
|
|
oss_close(od);
|
2004-10-30 06:19:11 +02:00
|
|
|
audioOutput->open = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int oss_openDevice(AudioOutput * audioOutput)
|
2005-03-05 15:01:13 +01:00
|
|
|
{
|
2005-03-10 03:47:18 +01:00
|
|
|
int ret = -1;
|
2006-07-20 18:02:40 +02:00
|
|
|
OssData *od = audioOutput->data;
|
|
|
|
AudioFormat *audioFormat = &audioOutput->outAudioFormat;
|
2006-03-25 06:33:14 +01:00
|
|
|
|
|
|
|
od->channels = audioFormat->channels;
|
2005-03-05 15:01:13 +01:00
|
|
|
od->sampleRate = audioFormat->sampleRate;
|
|
|
|
od->bits = audioFormat->bits;
|
|
|
|
|
2006-07-16 18:53:04 +02:00
|
|
|
if ((ret = oss_open(audioOutput)) < 0)
|
|
|
|
return ret;
|
2005-03-10 03:47:18 +01:00
|
|
|
|
|
|
|
audioFormat->channels = od->channels;
|
|
|
|
audioFormat->sampleRate = od->sampleRate;
|
|
|
|
audioFormat->bits = od->bits;
|
|
|
|
|
2005-03-19 15:30:07 +01:00
|
|
|
DEBUG("oss device \"%s\" will be playing %i bit %i channel audio at "
|
2006-07-20 18:02:40 +02:00
|
|
|
"%i Hz\n", od->device, od->bits, od->channels, od->sampleRate);
|
2005-03-10 03:47:18 +01:00
|
|
|
|
|
|
|
return ret;
|
2005-03-05 15:01:13 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void oss_closeDevice(AudioOutput * audioOutput)
|
|
|
|
{
|
|
|
|
OssData *od = audioOutput->data;
|
2004-10-30 06:19:11 +02:00
|
|
|
|
2005-04-07 00:52:42 +02:00
|
|
|
oss_close(od);
|
2004-10-30 06:19:11 +02:00
|
|
|
|
|
|
|
audioOutput->open = 0;
|
2004-10-29 05:30:23 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void oss_dropBufferedAudio(AudioOutput * audioOutput)
|
|
|
|
{
|
|
|
|
OssData *od = audioOutput->data;
|
2005-03-05 15:01:13 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (od->fd >= 0) {
|
2005-03-05 15:01:13 +01:00
|
|
|
ioctl(od->fd, SNDCTL_DSP_RESET, 0);
|
2005-04-07 00:52:42 +02:00
|
|
|
oss_close(od);
|
2005-03-05 15:01:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int oss_playAudio(AudioOutput * audioOutput, char *playChunk, int size)
|
2004-10-29 05:30:23 +02:00
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
OssData *od = audioOutput->data;
|
2004-10-29 05:30:23 +02:00
|
|
|
int ret;
|
|
|
|
|
2005-04-07 00:52:42 +02:00
|
|
|
/* reopen the device since it was closed by dropBufferedAudio */
|
2006-07-20 18:02:40 +02:00
|
|
|
if (od->fd < 0 && oss_open(audioOutput) < 0)
|
2006-07-16 18:53:04 +02:00
|
|
|
return -1;
|
2005-04-07 00:52:42 +02:00
|
|
|
|
2004-10-29 05:30:23 +02:00
|
|
|
while (size > 0) {
|
2004-10-30 06:19:11 +02:00
|
|
|
ret = write(od->fd, playChunk, size);
|
2006-07-20 18:02:40 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
if (errno == EINTR)
|
|
|
|
continue;
|
2005-03-05 22:09:32 +01:00
|
|
|
ERROR("closing oss device \"%s\" due to write error: "
|
2006-07-20 18:02:40 +02:00
|
|
|
"%s\n", od->device, strerror(errno));
|
2004-10-30 06:19:11 +02:00
|
|
|
oss_closeDevice(audioOutput);
|
2004-10-29 05:30:23 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2004-10-30 06:19:11 +02:00
|
|
|
playChunk += ret;
|
|
|
|
size -= ret;
|
2004-10-29 05:30:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
AudioOutputPlugin ossPlugin = {
|
2004-10-29 05:30:23 +02:00
|
|
|
"oss",
|
2005-03-12 04:10:09 +01:00
|
|
|
oss_testDefault,
|
2004-10-29 05:30:23 +02:00
|
|
|
oss_initDriver,
|
|
|
|
oss_finishDriver,
|
|
|
|
oss_openDevice,
|
|
|
|
oss_playAudio,
|
2005-03-05 15:01:13 +01:00
|
|
|
oss_dropBufferedAudio,
|
2004-10-29 05:30:23 +02:00
|
|
|
oss_closeDevice,
|
2006-07-20 20:53:56 +02:00
|
|
|
NULL, /* sendMetadataFunc */
|
2004-10-29 05:30:23 +02:00
|
|
|
};
|
|
|
|
|
2006-07-20 20:53:56 +02:00
|
|
|
#else /* HAVE OSS */
|
2004-10-29 05:30:23 +02:00
|
|
|
|
2006-07-14 19:39:14 +02:00
|
|
|
DISABLED_AUDIO_OUTPUT_PLUGIN(ossPlugin)
|
2006-07-20 20:53:56 +02:00
|
|
|
#endif /* HAVE_OSS */
|