aboutsummaryrefslogtreecommitdiffstats
path: root/src/audioOutputs
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-04-12 04:15:52 +0000
committerEric Wong <normalperson@yhbt.net>2008-04-12 04:15:52 +0000
commit01bf82289659b334a837062aef0c4814e26ed4fb (patch)
tree7f1bbd246e1925af986079fbe380822ccb452da1 /src/audioOutputs
parenta2380928dbc4d46c7bc3104df2dee47219db4b93 (diff)
downloadmpd-01bf82289659b334a837062aef0c4814e26ed4fb.tar.gz
mpd-01bf82289659b334a837062aef0c4814e26ed4fb.tar.xz
mpd-01bf82289659b334a837062aef0c4814e26ed4fb.zip
use size_t and constant pointer in ao plugins
The audio output plugins should get a constant pointer, because they must not modify the buffer. Since the size is a non-negative buffer size in bytes, we should change its type to size_t. git-svn-id: https://svn.musicpd.org/mpd/trunk@7293 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/audioOutputs/audioOutput_alsa.c3
-rw-r--r--src/audioOutputs/audioOutput_ao.c28
-rw-r--r--src/audioOutputs/audioOutput_fifo.c7
-rw-r--r--src/audioOutputs/audioOutput_jack.c7
-rw-r--r--src/audioOutputs/audioOutput_mvp.c5
-rw-r--r--src/audioOutputs/audioOutput_null.c3
-rw-r--r--src/audioOutputs/audioOutput_oss.c5
-rw-r--r--src/audioOutputs/audioOutput_osx.c21
-rw-r--r--src/audioOutputs/audioOutput_pulse.c3
-rw-r--r--src/audioOutputs/audioOutput_shout.c8
10 files changed, 59 insertions, 31 deletions
diff --git a/src/audioOutputs/audioOutput_alsa.c b/src/audioOutputs/audioOutput_alsa.c
index 167874b07..f0aa32713 100644
--- a/src/audioOutputs/audioOutput_alsa.c
+++ b/src/audioOutputs/audioOutput_alsa.c
@@ -381,7 +381,8 @@ static void alsa_closeDevice(AudioOutput * audioOutput)
audioOutput->open = 0;
}
-static int alsa_playAudio(AudioOutput * audioOutput, char *playChunk, int size)
+static int alsa_playAudio(AudioOutput * audioOutput,
+ const char *playChunk, size_t size)
{
AlsaData *ad = audioOutput->data;
int ret;
diff --git a/src/audioOutputs/audioOutput_ao.c b/src/audioOutputs/audioOutput_ao.c
index e7f3dcd6b..c28415410 100644
--- a/src/audioOutputs/audioOutput_ao.c
+++ b/src/audioOutputs/audioOutput_ao.c
@@ -199,19 +199,37 @@ static int audioOutputAo_openDevice(AudioOutput * audioOutput)
return 0;
}
-static int audioOutputAo_play(AudioOutput * audioOutput, char *playChunk,
- int size)
+/**
+ * For whatever reason, libao wants a non-const pointer. Let's hope
+ * it does not write to the buffer, and use the union deconst hack to
+ * work around this API misdesign.
+ */
+static int ao_play_deconst(ao_device *device, const void *output_samples,
+ uint_32 num_bytes)
+{
+ union {
+ const void *in;
+ void *out;
+ } u;
+
+ u.in = output_samples;
+ return ao_play(device, u.out, num_bytes);
+}
+
+static int audioOutputAo_play(AudioOutput * audioOutput,
+ const char *playChunk, size_t size)
{
- int send;
+ size_t send;
AoData *ad = (AoData *) audioOutput->data;
if (ad->device == NULL)
return -1;
while (size > 0) {
- send = ad->writeSize > size ? size : ad->writeSize;
+ send = (size_t)ad->writeSize > size
+ ? size : (size_t)ad->writeSize;
- if (ao_play(ad->device, playChunk, send) == 0) {
+ if (ao_play_deconst(ad->device, playChunk, send) == 0) {
audioOutputAo_error();
ERROR("closing audio device due to write error\n");
audioOutputAo_closeDevice(audioOutput);
diff --git a/src/audioOutputs/audioOutput_fifo.c b/src/audioOutputs/audioOutput_fifo.c
index d7b83fd7d..0c279667d 100644
--- a/src/audioOutputs/audioOutput_fifo.c
+++ b/src/audioOutputs/audioOutput_fifo.c
@@ -234,11 +234,12 @@ static void fifo_dropBufferedAudio(AudioOutput *audioOutput)
}
}
-static int fifo_playAudio(AudioOutput *audioOutput, char *playChunk, int size)
+static int fifo_playAudio(AudioOutput *audioOutput,
+ const char *playChunk, size_t size)
{
FifoData *fd = (FifoData *)audioOutput->data;
- int offset = 0;
- int bytes;
+ size_t offset = 0;
+ ssize_t bytes;
if (!fd->timer->started)
timer_start(fd->timer);
diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c
index 31f41b712..629702f20 100644
--- a/src/audioOutputs/audioOutput_jack.c
+++ b/src/audioOutputs/audioOutput_jack.c
@@ -368,12 +368,13 @@ static void jack_dropBufferedAudio (AudioOutput * audioOutput)
{
}
-static int jack_playAudio(AudioOutput * audioOutput, char *buff, int size)
+static int jack_playAudio(AudioOutput * audioOutput,
+ const char *buff, size_t size)
{
JackData *jd = audioOutput->data;
size_t space;
- unsigned int i;
- short *buffer = (short *) buff;
+ size_t i;
+ const short *buffer = (const short *) buff;
jack_default_audio_sample_t sample;
size_t samples = size/4;
diff --git a/src/audioOutputs/audioOutput_mvp.c b/src/audioOutputs/audioOutput_mvp.c
index c633bb96b..2b8ba6a00 100644
--- a/src/audioOutputs/audioOutput_mvp.c
+++ b/src/audioOutputs/audioOutput_mvp.c
@@ -231,10 +231,11 @@ static void mvp_dropBufferedAudio(AudioOutput * audioOutput)
}
}
-static int mvp_playAudio(AudioOutput * audioOutput, char *playChunk, int size)
+static int mvp_playAudio(AudioOutput * audioOutput,
+ const char *playChunk, size_t size)
{
MvpData *md = audioOutput->data;
- int ret;
+ ssize_t ret;
/* reopen the device since it was closed by dropBufferedAudio */
if (md->fd < 0)
diff --git a/src/audioOutputs/audioOutput_null.c b/src/audioOutputs/audioOutput_null.c
index 7dc3f1756..37ff7194a 100644
--- a/src/audioOutputs/audioOutput_null.c
+++ b/src/audioOutputs/audioOutput_null.c
@@ -42,7 +42,8 @@ static void null_closeDevice(AudioOutput *audioOutput)
audioOutput->open = 0;
}
-static int null_playAudio(AudioOutput *audioOutput, char *playChunk, int size)
+static int null_playAudio(AudioOutput *audioOutput,
+ const char *playChunk, size_t size)
{
Timer *timer = audioOutput->data;
diff --git a/src/audioOutputs/audioOutput_oss.c b/src/audioOutputs/audioOutput_oss.c
index 093b1a2ca..2a6a4876b 100644
--- a/src/audioOutputs/audioOutput_oss.c
+++ b/src/audioOutputs/audioOutput_oss.c
@@ -521,10 +521,11 @@ static void oss_dropBufferedAudio(AudioOutput * audioOutput)
}
}
-static int oss_playAudio(AudioOutput * audioOutput, char *playChunk, int size)
+static int oss_playAudio(AudioOutput * audioOutput,
+ const char *playChunk, size_t size)
{
OssData *od = audioOutput->data;
- int ret;
+ ssize_t ret;
/* reopen the device since it was closed by dropBufferedAudio */
if (od->fd < 0 && oss_open(audioOutput) < 0)
diff --git a/src/audioOutputs/audioOutput_osx.c b/src/audioOutputs/audioOutput_osx.c
index 4a6e8ccf1..4da921b4c 100644
--- a/src/audioOutputs/audioOutput_osx.c
+++ b/src/audioOutputs/audioOutput_osx.c
@@ -29,9 +29,9 @@ typedef struct _OsxData {
pthread_mutex_t mutex;
pthread_cond_t condition;
char *buffer;
- int bufferSize;
- int pos;
- int len;
+ size_t bufferSize;
+ size_t pos;
+ size_t len;
int started;
} OsxData;
@@ -141,8 +141,8 @@ static OSStatus osx_render(void *vdata,
{
OsxData *od = (OsxData *) vdata;
AudioBuffer *buffer = &bufferList->mBuffers[0];
- int bufferSize = buffer->mDataByteSize;
- int bytesToCopy;
+ size_t bufferSize = buffer->mDataByteSize;
+ size_t bytesToCopy;
int curpos = 0;
/*DEBUG("osx_render: enter : %i\n", (int)bufferList->mNumberBuffers);
@@ -186,7 +186,7 @@ static OSStatus osx_render(void *vdata,
od->len -= bytesToCopy;
if (od->pos + bytesToCopy > od->bufferSize) {
- int bytes = od->bufferSize - od->pos;
+ size_t bytes = od->bufferSize - od->pos;
memcpy(buffer->mData + curpos, od->buffer + od->pos, bytes);
od->pos = 0;
curpos += bytes;
@@ -294,11 +294,12 @@ static int osx_openDevice(AudioOutput * audioOutput)
return 0;
}
-static int osx_play(AudioOutput * audioOutput, char *playChunk, int size)
+static int osx_play(AudioOutput * audioOutput,
+ const char *playChunk, size_t size)
{
OsxData *od = (OsxData *) audioOutput->data;
- int bytesToCopy;
- int curpos;
+ size_t bytesToCopy;
+ size_t curpos;
/* DEBUG("osx_play: enter\n"); */
@@ -333,7 +334,7 @@ static int osx_play(AudioOutput * audioOutput, char *playChunk, int size)
od->len += bytesToCopy;
if (curpos + bytesToCopy > od->bufferSize) {
- int bytes = od->bufferSize - curpos;
+ size_t bytes = od->bufferSize - curpos;
memcpy(od->buffer + curpos, playChunk, bytes);
curpos = 0;
playChunk += bytes;
diff --git a/src/audioOutputs/audioOutput_pulse.c b/src/audioOutputs/audioOutput_pulse.c
index 69566444b..a67c2bae6 100644
--- a/src/audioOutputs/audioOutput_pulse.c
+++ b/src/audioOutputs/audioOutput_pulse.c
@@ -182,7 +182,8 @@ static void pulse_closeDevice(AudioOutput * audioOutput)
audioOutput->open = 0;
}
-static int pulse_playAudio(AudioOutput * audioOutput, char *playChunk, int size)
+static int pulse_playAudio(AudioOutput * audioOutput,
+ const char *playChunk, size_t size)
{
PulseData *pd;
int error;
diff --git a/src/audioOutputs/audioOutput_shout.c b/src/audioOutputs/audioOutput_shout.c
index d2725ffac..9ed5b4e7e 100644
--- a/src/audioOutputs/audioOutput_shout.c
+++ b/src/audioOutputs/audioOutput_shout.c
@@ -597,12 +597,14 @@ static void myShout_sendMetadata(ShoutData * sd)
sd->tagToSend = 0;
}
-static int myShout_play(AudioOutput * audioOutput, char *playChunk, int size)
+static int myShout_play(AudioOutput * audioOutput,
+ const char *playChunk, size_t size)
{
- int i, j;
+ unsigned int i;
+ int j;
ShoutData *sd = (ShoutData *) audioOutput->data;
float **vorbbuf;
- int samples;
+ unsigned int samples;
int bytes = sd->audioFormat->bits / 8;
int status;