Commit 01bf8228 authored by Max Kellermann's avatar Max Kellermann Committed by Eric Wong

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
parent a2380928
...@@ -181,8 +181,8 @@ int openAudioOutput(AudioOutput * audioOutput, AudioFormat * audioFormat) ...@@ -181,8 +181,8 @@ int openAudioOutput(AudioOutput * audioOutput, AudioFormat * audioFormat)
return ret; return ret;
} }
static void convertAudioFormat(AudioOutput * audioOutput, char **chunkArgPtr, static void convertAudioFormat(AudioOutput * audioOutput,
int *sizeArgPtr) const char **chunkArgPtr, size_t *sizeArgPtr)
{ {
size_t size = pcm_sizeOfConvBuffer(&(audioOutput->inAudioFormat), size_t size = pcm_sizeOfConvBuffer(&(audioOutput->inAudioFormat),
*sizeArgPtr, *sizeArgPtr,
...@@ -203,7 +203,8 @@ static void convertAudioFormat(AudioOutput * audioOutput, char **chunkArgPtr, ...@@ -203,7 +203,8 @@ static void convertAudioFormat(AudioOutput * audioOutput, char **chunkArgPtr,
*chunkArgPtr = audioOutput->convBuffer; *chunkArgPtr = audioOutput->convBuffer;
} }
int playAudioOutput(AudioOutput * audioOutput, char *playChunk, int size) int playAudioOutput(AudioOutput * audioOutput,
const char *playChunk, size_t size)
{ {
int ret; int ret;
......
...@@ -43,7 +43,7 @@ typedef void (*AudioOutputFinishDriverFunc) (AudioOutput * audioOutput); ...@@ -43,7 +43,7 @@ typedef void (*AudioOutputFinishDriverFunc) (AudioOutput * audioOutput);
typedef int (*AudioOutputOpenDeviceFunc) (AudioOutput * audioOutput); typedef int (*AudioOutputOpenDeviceFunc) (AudioOutput * audioOutput);
typedef int (*AudioOutputPlayFunc) (AudioOutput * audioOutput, typedef int (*AudioOutputPlayFunc) (AudioOutput * audioOutput,
char *playChunk, int size); const char *playChunk, size_t size);
typedef void (*AudioOutputDropBufferedAudioFunc) (AudioOutput * audioOutput); typedef void (*AudioOutputDropBufferedAudioFunc) (AudioOutput * audioOutput);
...@@ -97,7 +97,8 @@ void unloadAudioOutputPlugin(AudioOutputPlugin * audioOutputPlugin); ...@@ -97,7 +97,8 @@ void unloadAudioOutputPlugin(AudioOutputPlugin * audioOutputPlugin);
int initAudioOutput(AudioOutput *, ConfigParam * param); int initAudioOutput(AudioOutput *, ConfigParam * param);
int openAudioOutput(AudioOutput * audioOutput, AudioFormat * audioFormat); int openAudioOutput(AudioOutput * audioOutput, AudioFormat * audioFormat);
int playAudioOutput(AudioOutput * audioOutput, char *playChunk, int size); int playAudioOutput(AudioOutput * audioOutput,
const char *playChunk, size_t size);
void dropBufferedAudioOutput(AudioOutput * audioOutput); void dropBufferedAudioOutput(AudioOutput * audioOutput);
void closeAudioOutput(AudioOutput * audioOutput); void closeAudioOutput(AudioOutput * audioOutput);
void finishAudioOutput(AudioOutput * audioOutput); void finishAudioOutput(AudioOutput * audioOutput);
......
...@@ -381,7 +381,8 @@ static void alsa_closeDevice(AudioOutput * audioOutput) ...@@ -381,7 +381,8 @@ static void alsa_closeDevice(AudioOutput * audioOutput)
audioOutput->open = 0; 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; AlsaData *ad = audioOutput->data;
int ret; int ret;
......
...@@ -199,19 +199,37 @@ static int audioOutputAo_openDevice(AudioOutput * audioOutput) ...@@ -199,19 +199,37 @@ static int audioOutputAo_openDevice(AudioOutput * audioOutput)
return 0; 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; AoData *ad = (AoData *) audioOutput->data;
if (ad->device == NULL) if (ad->device == NULL)
return -1; return -1;
while (size > 0) { 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(); audioOutputAo_error();
ERROR("closing audio device due to write error\n"); ERROR("closing audio device due to write error\n");
audioOutputAo_closeDevice(audioOutput); audioOutputAo_closeDevice(audioOutput);
......
...@@ -234,11 +234,12 @@ static void fifo_dropBufferedAudio(AudioOutput *audioOutput) ...@@ -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; FifoData *fd = (FifoData *)audioOutput->data;
int offset = 0; size_t offset = 0;
int bytes; ssize_t bytes;
if (!fd->timer->started) if (!fd->timer->started)
timer_start(fd->timer); timer_start(fd->timer);
......
...@@ -368,12 +368,13 @@ static void jack_dropBufferedAudio (AudioOutput * audioOutput) ...@@ -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; JackData *jd = audioOutput->data;
size_t space; size_t space;
unsigned int i; size_t i;
short *buffer = (short *) buff; const short *buffer = (const short *) buff;
jack_default_audio_sample_t sample; jack_default_audio_sample_t sample;
size_t samples = size/4; size_t samples = size/4;
......
...@@ -231,10 +231,11 @@ static void mvp_dropBufferedAudio(AudioOutput * audioOutput) ...@@ -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; MvpData *md = audioOutput->data;
int ret; ssize_t ret;
/* reopen the device since it was closed by dropBufferedAudio */ /* reopen the device since it was closed by dropBufferedAudio */
if (md->fd < 0) if (md->fd < 0)
......
...@@ -42,7 +42,8 @@ static void null_closeDevice(AudioOutput *audioOutput) ...@@ -42,7 +42,8 @@ static void null_closeDevice(AudioOutput *audioOutput)
audioOutput->open = 0; 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; Timer *timer = audioOutput->data;
......
...@@ -521,10 +521,11 @@ static void oss_dropBufferedAudio(AudioOutput * audioOutput) ...@@ -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; OssData *od = audioOutput->data;
int ret; ssize_t ret;
/* reopen the device since it was closed by dropBufferedAudio */ /* reopen the device since it was closed by dropBufferedAudio */
if (od->fd < 0 && oss_open(audioOutput) < 0) if (od->fd < 0 && oss_open(audioOutput) < 0)
......
...@@ -29,9 +29,9 @@ typedef struct _OsxData { ...@@ -29,9 +29,9 @@ typedef struct _OsxData {
pthread_mutex_t mutex; pthread_mutex_t mutex;
pthread_cond_t condition; pthread_cond_t condition;
char *buffer; char *buffer;
int bufferSize; size_t bufferSize;
int pos; size_t pos;
int len; size_t len;
int started; int started;
} OsxData; } OsxData;
...@@ -141,8 +141,8 @@ static OSStatus osx_render(void *vdata, ...@@ -141,8 +141,8 @@ static OSStatus osx_render(void *vdata,
{ {
OsxData *od = (OsxData *) vdata; OsxData *od = (OsxData *) vdata;
AudioBuffer *buffer = &bufferList->mBuffers[0]; AudioBuffer *buffer = &bufferList->mBuffers[0];
int bufferSize = buffer->mDataByteSize; size_t bufferSize = buffer->mDataByteSize;
int bytesToCopy; size_t bytesToCopy;
int curpos = 0; int curpos = 0;
/*DEBUG("osx_render: enter : %i\n", (int)bufferList->mNumberBuffers); /*DEBUG("osx_render: enter : %i\n", (int)bufferList->mNumberBuffers);
...@@ -186,7 +186,7 @@ static OSStatus osx_render(void *vdata, ...@@ -186,7 +186,7 @@ static OSStatus osx_render(void *vdata,
od->len -= bytesToCopy; od->len -= bytesToCopy;
if (od->pos + bytesToCopy > od->bufferSize) { 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); memcpy(buffer->mData + curpos, od->buffer + od->pos, bytes);
od->pos = 0; od->pos = 0;
curpos += bytes; curpos += bytes;
...@@ -294,11 +294,12 @@ static int osx_openDevice(AudioOutput * audioOutput) ...@@ -294,11 +294,12 @@ static int osx_openDevice(AudioOutput * audioOutput)
return 0; 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; OsxData *od = (OsxData *) audioOutput->data;
int bytesToCopy; size_t bytesToCopy;
int curpos; size_t curpos;
/* DEBUG("osx_play: enter\n"); */ /* DEBUG("osx_play: enter\n"); */
...@@ -333,7 +334,7 @@ static int osx_play(AudioOutput * audioOutput, char *playChunk, int size) ...@@ -333,7 +334,7 @@ static int osx_play(AudioOutput * audioOutput, char *playChunk, int size)
od->len += bytesToCopy; od->len += bytesToCopy;
if (curpos + bytesToCopy > od->bufferSize) { if (curpos + bytesToCopy > od->bufferSize) {
int bytes = od->bufferSize - curpos; size_t bytes = od->bufferSize - curpos;
memcpy(od->buffer + curpos, playChunk, bytes); memcpy(od->buffer + curpos, playChunk, bytes);
curpos = 0; curpos = 0;
playChunk += bytes; playChunk += bytes;
......
...@@ -182,7 +182,8 @@ static void pulse_closeDevice(AudioOutput * audioOutput) ...@@ -182,7 +182,8 @@ static void pulse_closeDevice(AudioOutput * audioOutput)
audioOutput->open = 0; 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; PulseData *pd;
int error; int error;
......
...@@ -597,12 +597,14 @@ static void myShout_sendMetadata(ShoutData * sd) ...@@ -597,12 +597,14 @@ static void myShout_sendMetadata(ShoutData * sd)
sd->tagToSend = 0; 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; ShoutData *sd = (ShoutData *) audioOutput->data;
float **vorbbuf; float **vorbbuf;
int samples; unsigned int samples;
int bytes = sd->audioFormat->bits / 8; int bytes = sd->audioFormat->bits / 8;
int status; int status;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment