finish integrating in np's oss stuff

git-svn-id: https://svn.musicpd.org/mpd/trunk@2413 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-10-30 04:19:11 +00:00
parent 657bec26b1
commit 1d34894f71
3 changed files with 64 additions and 71 deletions

View File

@ -58,6 +58,7 @@ mpd_SOURCES = \
audio.c \ audio.c \
audioOutput.c \ audioOutput.c \
audioOutput_ao.c \ audioOutput_ao.c \
audioOutput_oss.c \
audioOutput_shout.c \ audioOutput_shout.c \
buffer2array.c \ buffer2array.c \
charConv.c \ charConv.c \

View File

@ -18,8 +18,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "../config.h"
#include "audioOutput.h"
#include "audio.h" #include <stdlib.h>
#ifdef HAVE_OSS #ifdef HAVE_OSS
@ -30,7 +32,6 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <signal.h> #include <signal.h>
#include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -45,7 +46,7 @@
# include <sys/soundcard.h> # include <sys/soundcard.h>
#endif /* !(defined(__OpenBSD__) || defined(__NetBSD__) */ #endif /* !(defined(__OpenBSD__) || defined(__NetBSD__) */
static typedef struct _OssData { typedef struct _OssData {
int fd; int fd;
char * device; char * device;
} OssData; } OssData;
@ -65,20 +66,19 @@ static void freeOssData(OssData * od) {
free(od); free(od);
} }
static void oss_initDriver(AudioOutput * audioOutput, ConfigParam * param) { static int oss_initDriver(AudioOutput * audioOutput, ConfigParam * param) {
char * test;
BlockParam * bp = getBlockParam(param, "device"); BlockParam * bp = getBlockParam(param, "device");
OssData * od = newOssData(): OssData * od = newOssData();
audioOutput->data = od; audioOutput->data = od;
if(!bp) { if(!bp) {
int fd; int fd;
if(0 <= (fd = fopen("/dev/sound/dsp", O_WRONLY | O_NONBLOCK))) { if(0 <= (fd = open("/dev/sound/dsp", O_WRONLY | O_NONBLOCK))) {
od->device = strdup("/dev/sound/dsp"); od->device = strdup("/dev/sound/dsp");
} }
else if(0 <= (fd = fopen("/dev/dsp", O_WRONLY | O_NONBLOCK))) { else if(0 <= (fd = open("/dev/dsp", O_WRONLY | O_NONBLOCK))) {
od->device = strdup("/dev/dsp"); od->device = strdup("/dev/dsp");
} }
else { else {
@ -92,12 +92,12 @@ static void oss_initDriver(AudioOutput * audioOutput, ConfigParam * param) {
close(od->fd); close(od->fd);
od->fd = -1; od->fd = -1;
return; return 0;
} }
od->device = strdup(bp->value); od->device = strdup(bp->value);
return; return 0;
} }
static void oss_finishDriver(AudioOutput * audioOutput) { static void oss_finishDriver(AudioOutput * audioOutput) {
@ -106,79 +106,71 @@ static void oss_finishDriver(AudioOutput * audioOutput) {
freeOssData(od); freeOssData(od);
} }
static int oss_openDevice(AudioOutput * audioOutput, static int oss_openDevice(AudioOutput * audioOutput, AudioFormat * audioFormat)
AudioFormat * audioFormat)
{ {
int i = AFMT_S16_LE, err = 0; OssData * od = audioOutput->data;
if (audio_device && !isCurrentAudioFormat(audioFormat)) #ifdef WORDS_BIGENDIAN
closeAudioDevice(); int i = AFMT_S16_BE;
if (audio_device!=0) #else
return 0; int i = AFMT_S16_LE;
#endif
if (audioFormat) if((od->fd = open(od->device, O_WRONLY)) < 0)
copyAudioFormat(&audio_format,audioFormat); goto fail;
if(ioctl(od->fd, SNDCTL_DSP_SETFMT, &i))
goto fail;
if(ioctl(od->fd, SNDCTL_DSP_CHANNELS, &audioFormat->channels))
goto fail;
if(ioctl(od->fd, SNDCTL_DSP_SPEED, &audioFormat->sampleRate))
goto fail;
if(ioctl(od->fd, SNDCTL_DSP_SAMPLESIZE, &audioFormat->bits))
goto fail;
/*i = 1; if (ioctl(od->fd,SNDCTL_DSP_STEREO,&i)) err != 32; */
blockSignals(); audioOutput->open = 1;
audio_device = open("/dev/dsp", O_WRONLY);
if (audio_device < 0) err |= 1;
if (ioctl(audio_device,SNDCTL_DSP_SETFMT,&i))
err |= 2;
if (ioctl(audio_device,SNDCTL_DSP_CHANNELS, &audio_format.channels))
err |= 4;
if (ioctl(audio_device,SNDCTL_DSP_SPEED,&audio_format.sampleRate))
err |= 8;
if (ioctl(audio_device,SNDCTL_DSP_SAMPLESIZE,&audio_format.bits))
err |= 16;
/*i = 1; if (ioctl(audio_device,SNDCTL_DSP_STEREO,&i)) err != 32; */
unblockSignals();
if (err)
ERROR("Error opening /dev/dsp: 0x%x\n");
if (!audio_device)
return -1;
return 0; return 0;
fail:
if(od->fd >= 0) close(od->fd);
audioOutput->open = 0;
ERROR("Error opening OSS device \"%s\": %s\n", od->device,
strerror(errno));
return -1;
}
static void oss_closeDevice(AudioOutput * audioOutput) {
OssData * od = audioOutput->data;
if(od->fd >= 0) {
close(od->fd);
od->fd = -1;
}
audioOutput->open = 0;
} }
static int oss_playAudio(AudioOutput * audioOutput, char * playChunk, static int oss_playAudio(AudioOutput * audioOutput, char * playChunk,
int size) int size)
{ {
int send; OssData * od = audioOutput->data;
int ret; int ret;
if(audio_device==0) {
ERROR("trying to play w/o the audio device being open!\n");
return -1;
}
send = audio_write_size>size?size:audio_write_size;
while (size > 0) { while (size > 0) {
ret = write(audio_device,playChunk,send); ret = write(od->fd, playChunk, size);
if(ret<0) { if(ret<0) {
audioError();
ERROR("closing audio device due to write error\n"); ERROR("closing audio device due to write error\n");
closeAudioDevice(); oss_closeDevice(audioOutput);
return -1; return -1;
} }
playChunk+=ret; playChunk += ret;
size-=ret; size -= ret;
} }
return 0; return 0;
} }
static void oss_closeDevice(AudioOutput * audioOutput) { AudioOutputPlugin ossPlugin =
if(audio_device) {
blockSignals();
close(audio_device);
audio_device = 0;
unblockSignals();
}
}
AudioOutput ossPlugin =
{ {
"oss", "oss",
oss_initDriver, oss_initDriver,
@ -191,7 +183,7 @@ AudioOutput ossPlugin =
#else /* HAVE OSS */ #else /* HAVE OSS */
AudioOutput ossPlugin = AudioOutputPlugin ossPlugin =
{ {
NULL, NULL,
NULL, NULL,

View File

@ -29,7 +29,7 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#ifndef NO_OSS_MIXER #ifdef HAVE_OSS
#include <sys/soundcard.h> #include <sys/soundcard.h>
#endif #endif
#ifdef HAVE_ALSA #ifdef HAVE_ALSA
@ -45,7 +45,7 @@
#define VOLUME_MIXER_ALSA_DEFAULT "default" #define VOLUME_MIXER_ALSA_DEFAULT "default"
#define VOLUME_MIXER_ALSA_CONTROL_DEFAULT "Master" #define VOLUME_MIXER_ALSA_CONTROL_DEFAULT "Master"
#ifndef NO_OSS_MIXER #ifdef HAVE_OSS
#define VOLUME_MIXER_TYPE_DEFAULT VOLUME_MIXER_TYPE_OSS #define VOLUME_MIXER_TYPE_DEFAULT VOLUME_MIXER_TYPE_OSS
#define VOLUME_MIXER_DEVICE_DEFAULT VOLUME_MIXER_OSS_DEFAULT #define VOLUME_MIXER_DEVICE_DEFAULT VOLUME_MIXER_OSS_DEFAULT
#else #else
@ -63,7 +63,7 @@ char * volume_mixerDevice = VOLUME_MIXER_DEVICE_DEFAULT;
int volume_softwareSet = 100; int volume_softwareSet = 100;
#ifndef NO_OSS_MIXER #ifdef HAVE_OSS
int volume_ossFd; int volume_ossFd;
int volume_ossControl = SOUND_MIXER_VOLUME; int volume_ossControl = SOUND_MIXER_VOLUME;
#endif #endif
@ -76,7 +76,7 @@ long volume_alsaMax;
int volume_alsaSet = -1; int volume_alsaSet = -1;
#endif #endif
#ifndef NO_OSS_MIXER #ifdef HAVE_OSS
int prepOssMixer(char * device) { int prepOssMixer(char * device) {
int devmask = 0; int devmask = 0;
ConfigParam * param; ConfigParam * param;
@ -335,7 +335,7 @@ int prepMixer(char * device) {
case VOLUME_MIXER_TYPE_ALSA: case VOLUME_MIXER_TYPE_ALSA:
return prepAlsaMixer(device); return prepAlsaMixer(device);
#endif #endif
#ifndef NO_OSS_MIXER #ifdef HAVE_OSS
case VOLUME_MIXER_TYPE_OSS: case VOLUME_MIXER_TYPE_OSS:
return prepOssMixer(device); return prepOssMixer(device);
#endif #endif
@ -351,7 +351,7 @@ void finishVolume() {
closeAlsaMixer(); closeAlsaMixer();
break; break;
#endif #endif
#ifndef NO_OSS_MIXER #ifndef HAVE_OSS
case VOLUME_MIXER_TYPE_OSS: case VOLUME_MIXER_TYPE_OSS:
closeOssMixer(); closeOssMixer();
break; break;
@ -370,7 +370,7 @@ void initVolume() {
volume_mixerDevice = VOLUME_MIXER_ALSA_DEFAULT; volume_mixerDevice = VOLUME_MIXER_ALSA_DEFAULT;
} }
#endif #endif
#ifndef NO_OSS_MIXER #ifndef HAVE_OSS
else if(strcmp(param->value, VOLUME_MIXER_OSS)==0) { else if(strcmp(param->value, VOLUME_MIXER_OSS)==0) {
volume_mixerType = VOLUME_MIXER_TYPE_OSS; volume_mixerType = VOLUME_MIXER_TYPE_OSS;
volume_mixerDevice = VOLUME_MIXER_OSS_DEFAULT; volume_mixerDevice = VOLUME_MIXER_OSS_DEFAULT;
@ -411,7 +411,7 @@ int getVolumeLevel() {
case VOLUME_MIXER_TYPE_ALSA: case VOLUME_MIXER_TYPE_ALSA:
return getAlsaVolumeLevel(); return getAlsaVolumeLevel();
#endif #endif
#ifndef NO_OSS_MIXER #ifndef HAVE_OSS
case VOLUME_MIXER_TYPE_OSS: case VOLUME_MIXER_TYPE_OSS:
return getOssVolumeLevel(); return getOssVolumeLevel();
#endif #endif
@ -448,7 +448,7 @@ int changeVolumeLevel(FILE * fp, int change, int rel) {
case VOLUME_MIXER_TYPE_ALSA: case VOLUME_MIXER_TYPE_ALSA:
return changeAlsaVolumeLevel(fp,change,rel); return changeAlsaVolumeLevel(fp,change,rel);
#endif #endif
#ifndef NO_OSS_MIXER #ifndef HAVE_OSS
case VOLUME_MIXER_TYPE_OSS: case VOLUME_MIXER_TYPE_OSS:
return changeOssVolumeLevel(fp,change,rel); return changeOssVolumeLevel(fp,change,rel);
#endif #endif