2004-10-29 05:30:23 +02:00
|
|
|
/* the Music Player Daemon (MPD)
|
2006-07-14 21:37:45 +02:00
|
|
|
* (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
|
2004-10-29 05:30:23 +02:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
2006-07-12 04:34:23 +02:00
|
|
|
* OSS audio output (c) 2004, 2005, 2006 by Eric Wong <eric@petta-tech.com>
|
|
|
|
* 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"
|
|
|
|
#include "../sig_handlers.h"
|
2004-10-29 05:30:23 +02:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <signal.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>
|
|
|
|
#else /* !(defined(__OpenBSD__) || defined(__NetBSD__) */
|
|
|
|
# include <sys/soundcard.h>
|
|
|
|
#endif /* !(defined(__OpenBSD__) || defined(__NetBSD__) */
|
|
|
|
|
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
|
|
|
|
#endif /* WORDS_BIGENDIAN */
|
|
|
|
|
2004-10-30 06:19:11 +02:00
|
|
|
typedef struct _OssData {
|
2004-10-29 06:11:10 +02:00
|
|
|
int fd;
|
|
|
|
char * device;
|
2005-03-05 15:01:13 +01:00
|
|
|
int channels;
|
|
|
|
int sampleRate;
|
|
|
|
int bitFormat;
|
|
|
|
int bits;
|
2005-03-10 03:47:18 +01:00
|
|
|
int * supported[3];
|
|
|
|
int numSupported[3];
|
|
|
|
int * unsupported[3];
|
|
|
|
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
|
|
|
|
|
|
|
|
static int getIndexForParam(int param) {
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
switch(param) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int findSupportedParam(OssData * od, int param, int val) {
|
|
|
|
int i;
|
|
|
|
int index = getIndexForParam(param);
|
|
|
|
|
|
|
|
for(i = 0; i < od->numSupported[index]; i++) {
|
|
|
|
if(od->supported[index][i] == val) return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int canConvert(int index, int val) {
|
|
|
|
switch(index) {
|
|
|
|
case OSS_BITS:
|
|
|
|
if(val!=16) return 0;
|
|
|
|
break;
|
|
|
|
case OSS_CHANNELS:
|
|
|
|
if(val!=2) return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int getSupportedParam(OssData * od, int param, int val) {
|
|
|
|
int i;
|
|
|
|
int index = getIndexForParam(param);
|
|
|
|
int ret = -1;
|
|
|
|
int least = val;
|
|
|
|
int diff;
|
|
|
|
|
|
|
|
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])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
least = diff;
|
|
|
|
ret = od->supported[index][i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int findUnsupportedParam(OssData * od, int param, int val) {
|
|
|
|
int i;
|
|
|
|
int index = getIndexForParam(param);
|
|
|
|
|
|
|
|
for(i = 0; i < od->numUnsupported[index]; i++) {
|
|
|
|
if(od->unsupported[index][i] == val) return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addSupportedParam(OssData * od, int param, int val) {
|
|
|
|
int index = getIndexForParam(param);
|
|
|
|
|
|
|
|
od->numSupported[index]++;
|
|
|
|
od->supported[index] = realloc(od->supported[index],
|
|
|
|
od->numSupported[index]*sizeof(int));
|
|
|
|
od->supported[index][od->numSupported[index]-1] = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void addUnsupportedParam(OssData * od, int param, int val) {
|
|
|
|
int index = getIndexForParam(param);
|
|
|
|
|
|
|
|
od->numUnsupported[index]++;
|
|
|
|
od->unsupported[index] = realloc(od->unsupported[index],
|
|
|
|
od->numUnsupported[index]*sizeof(int));
|
|
|
|
od->unsupported[index][od->numUnsupported[index]-1] = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void removeSupportedParam(OssData * od, int param, int val) {
|
|
|
|
int i = 0;
|
|
|
|
int j = 0;
|
|
|
|
int index = getIndexForParam(param);
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
od->numSupported[index]--;
|
|
|
|
od->supported[index] = realloc(od->supported[index],
|
|
|
|
od->numSupported[index]*sizeof(int));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void removeUnsupportedParam(OssData * od, int param, int val) {
|
|
|
|
int i = 0;
|
|
|
|
int j = 0;
|
|
|
|
int index = getIndexForParam(param);
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
od->numUnsupported[index]--;
|
|
|
|
od->unsupported[index] = realloc(od->unsupported[index],
|
|
|
|
od->numUnsupported[index]*sizeof(int));
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
return OSS_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void supportParam(OssData * od, int param, int val) {
|
|
|
|
int supported = isSupportedParam(od, param, val);
|
|
|
|
|
|
|
|
if(supported == OSS_SUPPORTED) return;
|
|
|
|
|
|
|
|
if(supported == OSS_UNSUPPORTED) {
|
|
|
|
removeUnsupportedParam(od, param, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
addSupportedParam(od, param, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unsupportParam(OssData * od, int param, int val) {
|
|
|
|
int supported = isSupportedParam(od, param, val);
|
|
|
|
|
|
|
|
if(supported == OSS_UNSUPPORTED) return;
|
|
|
|
|
|
|
|
if(supported == OSS_SUPPORTED) {
|
|
|
|
removeSupportedParam(od, param, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
addUnsupportedParam(od, param, val);
|
|
|
|
}
|
|
|
|
|
2004-10-29 05:30:23 +02:00
|
|
|
static OssData * newOssData() {
|
|
|
|
OssData * ret = malloc(sizeof(OssData));
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
supportParam(ret, SNDCTL_DSP_SPEED, 48000);
|
|
|
|
supportParam(ret, SNDCTL_DSP_SPEED, 44100);
|
|
|
|
supportParam(ret, SNDCTL_DSP_CHANNELS, 2);
|
|
|
|
supportParam(ret, SNDCTL_DSP_SAMPLESIZE, 16);
|
|
|
|
|
2004-10-29 05:30:23 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void freeOssData(OssData * od) {
|
2004-10-29 06:11:10 +02:00
|
|
|
if(od->device) free(od->device);
|
|
|
|
|
2005-03-10 03:47:18 +01:00
|
|
|
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]);
|
|
|
|
|
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
|
|
|
|
|
|
|
|
static int oss_statDevice(char * device, int * stErrno) {
|
|
|
|
struct stat st;
|
|
|
|
|
2005-03-05 15:28:37 +01:00
|
|
|
if(0 == stat(device, &st)) {
|
2005-03-05 04:36:24 +01:00
|
|
|
if(!S_ISCHR(st.st_mode)) {
|
|
|
|
return OSS_STAT_NOT_CHAR_DEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*stErrno = errno;
|
|
|
|
|
|
|
|
switch(errno) {
|
|
|
|
case ENOENT:
|
|
|
|
case ENOTDIR:
|
|
|
|
return OSS_STAT_DOESN_T_EXIST;
|
|
|
|
case EACCES:
|
|
|
|
return OSS_STAT_NO_PERMS;
|
|
|
|
default:
|
|
|
|
return OSS_STAT_OTHER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-03-12 04:10:09 +01:00
|
|
|
static int oss_testDefault() {
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open("/dev/sound/dsp", O_WRONLY);
|
|
|
|
|
2006-07-12 04:34:23 +02:00
|
|
|
if(fd >= 0) {
|
2005-03-12 04:10:09 +01:00
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARNING("Error opening OSS device \"/dev/sound/dsp\": %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
|
|
|
|
fd = open("/dev/dsp", O_WRONLY);
|
|
|
|
|
2006-07-12 04:34:23 +02:00
|
|
|
if(fd >= 0) {
|
2005-03-12 04:10:09 +01:00
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARNING("Error opening OSS device \"/dev/dsp\": %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-10-30 06:19:11 +02:00
|
|
|
static int oss_initDriver(AudioOutput * audioOutput, ConfigParam * param) {
|
2005-03-12 04:10:09 +01:00
|
|
|
BlockParam * bp = NULL;
|
2005-11-19 11:29:20 +01:00
|
|
|
OssData * od;
|
2005-03-12 04:10:09 +01:00
|
|
|
|
|
|
|
if(param) bp = getBlockParam(param, "device");
|
|
|
|
|
2005-11-19 11:29:20 +01:00
|
|
|
od = newOssData();
|
2004-10-29 06:11:10 +02:00
|
|
|
audioOutput->data = od;
|
|
|
|
|
|
|
|
if(!bp) {
|
2005-03-05 04:36:24 +01:00
|
|
|
int err[2];
|
|
|
|
int ret[2];
|
|
|
|
|
|
|
|
ret[0] = oss_statDevice("/dev/sound/dsp", err);
|
|
|
|
ret[1] = oss_statDevice("/dev/dsp", err+1);
|
|
|
|
|
|
|
|
if(ret[0] == 0) od->device = strdup("/dev/sound/dsp");
|
|
|
|
else if(ret[1] == 0) od->device = strdup("/dev/dsp");
|
2004-10-29 06:11:10 +02:00
|
|
|
else {
|
2005-03-12 04:10:09 +01:00
|
|
|
if(param) {
|
|
|
|
ERROR("Error trying to open default OSS device "
|
|
|
|
"specified at line %i\n", param->line);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ERROR("Error trying to open default OSS "
|
|
|
|
"device\n");
|
|
|
|
}
|
2005-03-05 04:36:24 +01:00
|
|
|
|
2005-08-07 12:17:28 +02:00
|
|
|
if((ret[0] == OSS_STAT_DOESN_T_EXIST) &&
|
|
|
|
(ret[1] == OSS_STAT_DOESN_T_EXIST)) {
|
2005-03-05 04:36:24 +01:00
|
|
|
ERROR("Neither /dev/dsp nor /dev/sound/dsp "
|
|
|
|
"were found\n");
|
|
|
|
}
|
|
|
|
else if(ret[0] == OSS_STAT_NOT_CHAR_DEV) {
|
|
|
|
ERROR("/dev/sound/dsp is not a char device");
|
|
|
|
}
|
|
|
|
else if(ret[1] == OSS_STAT_NOT_CHAR_DEV) {
|
|
|
|
ERROR("/dev/dsp is not a char device");
|
|
|
|
}
|
|
|
|
else if(ret[0] == OSS_STAT_NO_PERMS) {
|
|
|
|
ERROR("no permission to access /dev/sound/dsp");
|
|
|
|
}
|
|
|
|
else if(ret[1] == OSS_STAT_NO_PERMS) {
|
|
|
|
ERROR("no permission to access /dev/dsp");
|
|
|
|
}
|
|
|
|
else if(ret[0] == OSS_STAT_OTHER) {
|
|
|
|
ERROR("Error accessing /dev/sound/dsp: %s",
|
|
|
|
strerror(err[0]));
|
|
|
|
}
|
|
|
|
else if(ret[1] == OSS_STAT_OTHER) {
|
|
|
|
ERROR("Error accessing /dev/dsp: %s",
|
|
|
|
strerror(err[1]));
|
|
|
|
}
|
|
|
|
|
2004-10-29 06:11:10 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2004-10-29 05:30:23 +02:00
|
|
|
}
|
2005-03-05 04:36:24 +01:00
|
|
|
else od->device = strdup(bp->value);
|
2004-10-29 06:11:10 +02:00
|
|
|
|
2004-10-30 06:19:11 +02:00
|
|
|
return 0;
|
2004-10-29 05:30:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void oss_finishDriver(AudioOutput * audioOutput) {
|
|
|
|
OssData * od = audioOutput->data;
|
|
|
|
|
|
|
|
freeOssData(od);
|
|
|
|
}
|
|
|
|
|
2005-03-10 03:47:18 +01:00
|
|
|
static int setParam(OssData * od, int param, int * value) {
|
|
|
|
int val = *value;
|
|
|
|
int copy;
|
|
|
|
int supported = isSupportedParam(od, param, val);
|
|
|
|
|
|
|
|
do {
|
|
|
|
if(supported == OSS_UNSUPPORTED) {
|
|
|
|
val = getSupportedParam(od, param, val);
|
|
|
|
if(copy < 0) return -1;
|
|
|
|
}
|
|
|
|
copy = val;
|
|
|
|
if(ioctl(od->fd, param, ©)) {
|
|
|
|
unsupportParam(od, param, val);
|
|
|
|
supported = OSS_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(supported == OSS_UNKNOWN) {
|
|
|
|
supportParam(od, param, val);
|
|
|
|
supported = OSS_SUPPORTED;
|
|
|
|
}
|
|
|
|
val = copy;
|
|
|
|
}
|
|
|
|
} while( supported == OSS_UNSUPPORTED );
|
|
|
|
|
|
|
|
*value = val;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-03-05 15:01:13 +01:00
|
|
|
static int oss_open(AudioOutput * audioOutput) {
|
2006-03-25 06:33:14 +01:00
|
|
|
int tmp;
|
2004-10-30 06:19:11 +02:00
|
|
|
OssData * od = audioOutput->data;
|
2005-03-05 04:36:24 +01:00
|
|
|
|
2005-03-05 15:01:13 +01:00
|
|
|
if((od->fd = open(od->device, O_WRONLY)) < 0) {
|
|
|
|
ERROR("Error opening OSS device \"%s\": %s\n", od->device,
|
|
|
|
strerror(errno));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2005-03-10 03:47:18 +01:00
|
|
|
if(setParam(od, SNDCTL_DSP_CHANNELS, &od->channels)) {
|
2005-03-05 15:01:13 +01:00
|
|
|
ERROR("OSS device \"%s\" does not support %i channels: %s\n",
|
|
|
|
od->device,
|
|
|
|
od->channels,
|
|
|
|
strerror(errno));
|
|
|
|
goto fail;
|
|
|
|
}
|
2005-03-05 04:36:24 +01:00
|
|
|
|
2005-03-10 03:47:18 +01:00
|
|
|
if(setParam(od, SNDCTL_DSP_SPEED, &od->sampleRate)) {
|
2005-03-05 15:01:13 +01:00
|
|
|
ERROR("OSS device \"%s\" does not support %i Hz audio: %s\n",
|
|
|
|
od->device,
|
|
|
|
od->sampleRate,
|
|
|
|
strerror(errno));
|
|
|
|
goto fail;
|
|
|
|
}
|
2005-03-05 04:36:24 +01:00
|
|
|
|
2006-03-25 06:33:14 +01:00
|
|
|
switch(od->bits) {
|
|
|
|
case 8:
|
|
|
|
tmp = AFMT_S8;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
tmp = AFMT_S16_MPD;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(setParam(od, SNDCTL_DSP_SAMPLESIZE, &tmp)) {
|
2005-03-05 15:01:13 +01:00
|
|
|
ERROR("OSS device \"%s\" does not support %i bit audio: %s\n",
|
|
|
|
od->device,
|
2006-03-25 06:33:14 +01:00
|
|
|
tmp,
|
2005-03-05 15:01:13 +01:00
|
|
|
strerror(errno));
|
|
|
|
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
|
|
|
|
|
|
|
fail:
|
|
|
|
if(od->fd >= 0) close(od->fd);
|
|
|
|
audioOutput->open = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-03-05 15:01:13 +01:00
|
|
|
static int oss_openDevice(AudioOutput * audioOutput)
|
|
|
|
{
|
2005-03-10 03:47:18 +01:00
|
|
|
int ret = -1;
|
2005-03-05 15:01:13 +01: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;
|
|
|
|
|
2005-03-10 03:47:18 +01:00
|
|
|
ret = oss_open(audioOutput);
|
|
|
|
|
|
|
|
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 "
|
|
|
|
"%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
|
|
|
}
|
|
|
|
|
2005-04-07 00:52:42 +02:00
|
|
|
static void oss_close(OssData * od) {
|
|
|
|
if(od->fd >= 0) close(od->fd);
|
|
|
|
od->fd = -1;
|
|
|
|
}
|
|
|
|
|
2004-10-30 06:19:11 +02:00
|
|
|
static void oss_closeDevice(AudioOutput * audioOutput) {
|
|
|
|
OssData * od = audioOutput->data;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-03-05 15:01:13 +01:00
|
|
|
static void oss_dropBufferedAudio(AudioOutput * audioOutput) {
|
|
|
|
OssData * od = audioOutput->data;
|
|
|
|
|
|
|
|
if(od->fd >= 0) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*oss_open(audioOutput);*/
|
|
|
|
}
|
|
|
|
|
2004-10-29 05:30:23 +02:00
|
|
|
static int oss_playAudio(AudioOutput * audioOutput, char * playChunk,
|
|
|
|
int size)
|
|
|
|
{
|
2004-10-30 06:19:11 +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 */
|
|
|
|
if(od->fd < 0) oss_open(audioOutput);
|
|
|
|
|
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);
|
2004-10-29 05:30:23 +02:00
|
|
|
if(ret<0) {
|
2005-07-03 14:15:45 +02:00
|
|
|
if(errno == EINTR) continue;
|
2005-03-05 22:09:32 +01:00
|
|
|
ERROR("closing oss device \"%s\" due to write error: "
|
|
|
|
"%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;
|
|
|
|
}
|
|
|
|
|
2004-10-30 06:19:11 +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-14 19:39:14 +02:00
|
|
|
NULL, /* sendMetadataFunc */
|
2004-10-29 05:30:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#else /* HAVE OSS */
|
|
|
|
|
2006-07-14 19:39:14 +02:00
|
|
|
DISABLED_AUDIO_OUTPUT_PLUGIN(ossPlugin)
|
2004-10-29 05:30:23 +02:00
|
|
|
|
|
|
|
#endif /* HAVE_OSS */
|