aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-10-30 04:19:11 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-10-30 04:19:11 +0000
commit1d34894f71742a75a71310f4ba0cdb4a0cb98838 (patch)
tree79540f178641e8a2062af551d527684391ea9e6c /src
parent657bec26b171437b103f67d980e6743b07920e00 (diff)
downloadmpd-1d34894f71742a75a71310f4ba0cdb4a0cb98838.tar.gz
mpd-1d34894f71742a75a71310f4ba0cdb4a0cb98838.tar.xz
mpd-1d34894f71742a75a71310f4ba0cdb4a0cb98838.zip
finish integrating in np's oss stuff
git-svn-id: https://svn.musicpd.org/mpd/trunk@2413 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/audioOutput_oss.c118
-rw-r--r--src/volume.c18
3 files changed, 65 insertions, 72 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 286166237..2fced704c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -58,6 +58,7 @@ mpd_SOURCES = \
audio.c \
audioOutput.c \
audioOutput_ao.c \
+ audioOutput_oss.c \
audioOutput_shout.c \
buffer2array.c \
charConv.c \
diff --git a/src/audioOutput_oss.c b/src/audioOutput_oss.c
index d02a7cbba..f73e1a38a 100644
--- a/src/audioOutput_oss.c
+++ b/src/audioOutput_oss.c
@@ -18,8 +18,10 @@
* 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
@@ -30,7 +32,6 @@
#include <string.h>
#include <assert.h>
#include <signal.h>
-#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -45,7 +46,7 @@
# include <sys/soundcard.h>
#endif /* !(defined(__OpenBSD__) || defined(__NetBSD__) */
-static typedef struct _OssData {
+typedef struct _OssData {
int fd;
char * device;
} OssData;
@@ -65,20 +66,19 @@ static void freeOssData(OssData * od) {
free(od);
}
-static void oss_initDriver(AudioOutput * audioOutput, ConfigParam * param) {
- char * test;
+static int oss_initDriver(AudioOutput * audioOutput, ConfigParam * param) {
BlockParam * bp = getBlockParam(param, "device");
- OssData * od = newOssData():
+ OssData * od = newOssData();
audioOutput->data = od;
if(!bp) {
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");
}
- 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");
}
else {
@@ -92,12 +92,12 @@ static void oss_initDriver(AudioOutput * audioOutput, ConfigParam * param) {
close(od->fd);
od->fd = -1;
- return;
+ return 0;
}
od->device = strdup(bp->value);
- return;
+ return 0;
}
static void oss_finishDriver(AudioOutput * audioOutput) {
@@ -106,79 +106,71 @@ static void oss_finishDriver(AudioOutput * audioOutput) {
freeOssData(od);
}
-static int oss_openDevice(AudioOutput * audioOutput,
- AudioFormat * audioFormat)
+static int oss_openDevice(AudioOutput * audioOutput, AudioFormat * audioFormat)
{
- int i = AFMT_S16_LE, err = 0;
- if (audio_device && !isCurrentAudioFormat(audioFormat))
- closeAudioDevice();
- if (audio_device!=0)
- return 0;
-
- if (audioFormat)
- copyAudioFormat(&audio_format,audioFormat);
-
- blockSignals();
- 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();
+ OssData * od = audioOutput->data;
+#ifdef WORDS_BIGENDIAN
+ int i = AFMT_S16_BE;
+#else
+ int i = AFMT_S16_LE;
+#endif
- if (err)
- ERROR("Error opening /dev/dsp: 0x%x\n");
- if (!audio_device)
- return -1;
+ if((od->fd = open(od->device, O_WRONLY)) < 0)
+ 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; */
+
+ audioOutput->open = 1;
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,
int size)
{
- int send;
+ OssData * od = audioOutput->data;
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) {
- ret = write(audio_device,playChunk,send);
+ ret = write(od->fd, playChunk, size);
if(ret<0) {
- audioError();
ERROR("closing audio device due to write error\n");
- closeAudioDevice();
+ oss_closeDevice(audioOutput);
return -1;
}
- playChunk+=ret;
- size-=ret;
+ playChunk += ret;
+ size -= ret;
}
return 0;
}
-static void oss_closeDevice(AudioOutput * audioOutput) {
- if(audio_device) {
- blockSignals();
- close(audio_device);
- audio_device = 0;
- unblockSignals();
- }
-}
-
-AudioOutput ossPlugin =
+AudioOutputPlugin ossPlugin =
{
"oss",
oss_initDriver,
@@ -191,7 +183,7 @@ AudioOutput ossPlugin =
#else /* HAVE OSS */
-AudioOutput ossPlugin =
+AudioOutputPlugin ossPlugin =
{
NULL,
NULL,
diff --git a/src/volume.c b/src/volume.c
index cd48f76f4..14733ae0b 100644
--- a/src/volume.c
+++ b/src/volume.c
@@ -29,7 +29,7 @@
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
-#ifndef NO_OSS_MIXER
+#ifdef HAVE_OSS
#include <sys/soundcard.h>
#endif
#ifdef HAVE_ALSA
@@ -45,7 +45,7 @@
#define VOLUME_MIXER_ALSA_DEFAULT "default"
#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_DEVICE_DEFAULT VOLUME_MIXER_OSS_DEFAULT
#else
@@ -63,7 +63,7 @@ char * volume_mixerDevice = VOLUME_MIXER_DEVICE_DEFAULT;
int volume_softwareSet = 100;
-#ifndef NO_OSS_MIXER
+#ifdef HAVE_OSS
int volume_ossFd;
int volume_ossControl = SOUND_MIXER_VOLUME;
#endif
@@ -76,7 +76,7 @@ long volume_alsaMax;
int volume_alsaSet = -1;
#endif
-#ifndef NO_OSS_MIXER
+#ifdef HAVE_OSS
int prepOssMixer(char * device) {
int devmask = 0;
ConfigParam * param;
@@ -335,7 +335,7 @@ int prepMixer(char * device) {
case VOLUME_MIXER_TYPE_ALSA:
return prepAlsaMixer(device);
#endif
-#ifndef NO_OSS_MIXER
+#ifdef HAVE_OSS
case VOLUME_MIXER_TYPE_OSS:
return prepOssMixer(device);
#endif
@@ -351,7 +351,7 @@ void finishVolume() {
closeAlsaMixer();
break;
#endif
-#ifndef NO_OSS_MIXER
+#ifndef HAVE_OSS
case VOLUME_MIXER_TYPE_OSS:
closeOssMixer();
break;
@@ -370,7 +370,7 @@ void initVolume() {
volume_mixerDevice = VOLUME_MIXER_ALSA_DEFAULT;
}
#endif
-#ifndef NO_OSS_MIXER
+#ifndef HAVE_OSS
else if(strcmp(param->value, VOLUME_MIXER_OSS)==0) {
volume_mixerType = VOLUME_MIXER_TYPE_OSS;
volume_mixerDevice = VOLUME_MIXER_OSS_DEFAULT;
@@ -411,7 +411,7 @@ int getVolumeLevel() {
case VOLUME_MIXER_TYPE_ALSA:
return getAlsaVolumeLevel();
#endif
-#ifndef NO_OSS_MIXER
+#ifndef HAVE_OSS
case VOLUME_MIXER_TYPE_OSS:
return getOssVolumeLevel();
#endif
@@ -448,7 +448,7 @@ int changeVolumeLevel(FILE * fp, int change, int rel) {
case VOLUME_MIXER_TYPE_ALSA:
return changeAlsaVolumeLevel(fp,change,rel);
#endif
-#ifndef NO_OSS_MIXER
+#ifndef HAVE_OSS
case VOLUME_MIXER_TYPE_OSS:
return changeOssVolumeLevel(fp,change,rel);
#endif