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
This commit is contained in:
parent
a2380928db
commit
01bf822896
@ -181,8 +181,8 @@ int openAudioOutput(AudioOutput * audioOutput, AudioFormat * audioFormat)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void convertAudioFormat(AudioOutput * audioOutput, char **chunkArgPtr,
|
||||
int *sizeArgPtr)
|
||||
static void convertAudioFormat(AudioOutput * audioOutput,
|
||||
const char **chunkArgPtr, size_t *sizeArgPtr)
|
||||
{
|
||||
size_t size = pcm_sizeOfConvBuffer(&(audioOutput->inAudioFormat),
|
||||
*sizeArgPtr,
|
||||
@ -203,7 +203,8 @@ static void convertAudioFormat(AudioOutput * audioOutput, char **chunkArgPtr,
|
||||
*chunkArgPtr = audioOutput->convBuffer;
|
||||
}
|
||||
|
||||
int playAudioOutput(AudioOutput * audioOutput, char *playChunk, int size)
|
||||
int playAudioOutput(AudioOutput * audioOutput,
|
||||
const char *playChunk, size_t size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -43,7 +43,7 @@ typedef void (*AudioOutputFinishDriverFunc) (AudioOutput * audioOutput);
|
||||
typedef int (*AudioOutputOpenDeviceFunc) (AudioOutput * audioOutput);
|
||||
|
||||
typedef int (*AudioOutputPlayFunc) (AudioOutput * audioOutput,
|
||||
char *playChunk, int size);
|
||||
const char *playChunk, size_t size);
|
||||
|
||||
typedef void (*AudioOutputDropBufferedAudioFunc) (AudioOutput * audioOutput);
|
||||
|
||||
@ -97,7 +97,8 @@ void unloadAudioOutputPlugin(AudioOutputPlugin * audioOutputPlugin);
|
||||
|
||||
int initAudioOutput(AudioOutput *, ConfigParam * param);
|
||||
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 closeAudioOutput(AudioOutput * audioOutput);
|
||||
void finishAudioOutput(AudioOutput * audioOutput);
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
int send;
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user