aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-10-29 03:30:23 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-10-29 03:30:23 +0000
commit9906d3a7b2c509764afb14e9414789b36b266364 (patch)
treea7975e491c8dd6260b146c018971d40e9e3b7000
parent94ee53178d3c9e6950e9fccaeaf67555274a4107 (diff)
downloadmpd-9906d3a7b2c509764afb14e9414789b36b266364.tar.gz
mpd-9906d3a7b2c509764afb14e9414789b36b266364.tar.xz
mpd-9906d3a7b2c509764afb14e9414789b36b266364.zip
begin integrating np's oss code
git-svn-id: https://svn.musicpd.org/mpd/trunk@2394 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--TODO8
-rw-r--r--src/audioOutput.c2
-rw-r--r--src/audioOutput_oss.c178
-rw-r--r--src/audioOutput_shout.c2
4 files changed, 189 insertions, 1 deletions
diff --git a/TODO b/TODO
index e61cb17b9..0b7abfe79 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,13 @@
0.12
----
+*) AudioOutput
+ *) intigrate np's oss shit
+ *) have "format" as a default config option for all audioOutputs
+ *) don't automatically close audioOutput devices on openDevice(),
+ instead, let the plugins determine if they should be closed
+ or not, so that they can just leave the device open,
+ like if they are using a constant audioFormat
+
*) Fix id3v1 encoding
*) Cleanup Config File Code
diff --git a/src/audioOutput.c b/src/audioOutput.c
index 902edbccb..a1de85942 100644
--- a/src/audioOutput.c
+++ b/src/audioOutput.c
@@ -11,11 +11,13 @@
static List * audioOutputPluginList;
void loadAudioOutputPlugin(AudioOutputPlugin * audioOutputPlugin) {
+ if(!audioOutputPlugin->name) return;
insertInList(audioOutputPluginList, audioOutputPlugin->name,
audioOutputPlugin);
}
void unloadAudioOutputPlugin(AudioOutputPlugin * audioOutputPlugin) {
+ if(!audioOutputPlugin->name) return;
deleteFromList(audioOutputPluginList, audioOutputPlugin->name);
}
diff --git a/src/audioOutput_oss.c b/src/audioOutput_oss.c
new file mode 100644
index 000000000..a445761ec
--- /dev/null
+++ b/src/audioOutput_oss.c
@@ -0,0 +1,178 @@
+/* the Music Player Daemon (MPD)
+ * (c)2003-2004 by Warren Dukes (shank@mercury.chem.pitt.edu)
+ * This project's homepage is: http://www.musicpd.org
+ *
+ * OSS audio output (c) 2004 by Eric Wong <eric@petta-tech.com>
+ *
+ * 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
+ */
+
+
+#include "audio.h"
+
+#ifdef HAVE_OSS
+
+#include "conf.h"
+#include "log.h"
+#include "sig_handlers.h"
+
+#include <string.h>
+#include <assert.h>
+#include <signal.h>
+#include <stdlib.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__) */
+
+static typedef struct _OssData {
+ int device;
+} OssData;
+
+static OssData * newOssData() {
+ OssData * ret = malloc(sizeof(OssData));
+
+ ret->device = 0;
+
+ return ret;
+}
+
+static void freeOssData(OssData * od) {
+ free(od);
+}
+
+static void oss_initDriver(AudioOutput * audioOutput, ConfigParam * param) {
+ char * test;
+ audio_write_size = strtol((getConf())[CONF_AUDIO_WRITE_SIZE],&test,10);
+ if (*test!='\0') {
+ ERROR("\"%s\" is not a valid write size",
+ (getConf())[CONF_AUDIO_WRITE_SIZE]);
+ exit(EXIT_FAILURE);
+ }
+}
+
+static void oss_finishDriver(AudioOutput * audioOutput) {
+ OssData * od = audioOutput->data;
+
+ freeOssData(od);
+}
+
+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();
+
+ if (err)
+ ERROR("Error opening /dev/dsp: 0x%x\n");
+ if (!audio_device)
+ return -1;
+
+ return 0;
+}
+
+static int oss_playAudio(AudioOutput * audioOutput, char * playChunk,
+ int size)
+{
+ int send;
+ 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);
+ if(ret<0) {
+ audioError();
+ ERROR("closing audio device due to write error\n");
+ closeAudioDevice();
+ return -1;
+ }
+ 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 =
+{
+ "oss",
+ oss_initDriver,
+ oss_finishDriver,
+ oss_openDevice,
+ oss_playAudio,
+ oss_closeDevice,
+ NULL /* sendMetadataFunc */
+};
+
+#else /* HAVE OSS */
+
+AudioOutput ossPlugin =
+{
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL /* sendMetadataFunc */
+};
+
+#endif /* HAVE_OSS */
+
+
diff --git a/src/audioOutput_shout.c b/src/audioOutput_shout.c
index f41b57359..3fb07cc49 100644
--- a/src/audioOutput_shout.c
+++ b/src/audioOutput_shout.c
@@ -467,7 +467,7 @@ AudioOutputPlugin shoutPlugin =
AudioOutputPlugin shoutPlugin =
{
- "shout",
+ NULL,
NULL,
NULL,
NULL,