aboutsummaryrefslogtreecommitdiffstats
path: root/src/audio.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-08-01 10:07:16 +0000
committerEric Wong <normalperson@yhbt.net>2006-08-01 10:07:16 +0000
commiteb537f84f1ebcd508fded4f1a319a0da146a7fc4 (patch)
treebfa2ca32d530d175dc5ffe3a8acdba10a10d6550 /src/audio.c
parentb0965c317babb7d25b3d42241788661b94c59fa2 (diff)
downloadmpd-eb537f84f1ebcd508fded4f1a319a0da146a7fc4.tar.gz
mpd-eb537f84f1ebcd508fded4f1a319a0da146a7fc4.tar.xz
mpd-eb537f84f1ebcd508fded4f1a319a0da146a7fc4.zip
audio: malloc reductions
Just malloc all of the audioOutput array in one shot to avoid fragmentation and to improve cache locality when iterating through the array. We also know name and type members of the AudioOutput struct won't change in the config, so there's no need to strdup them. newAudioOutput => initAudioOutput git-svn-id: https://svn.musicpd.org/mpd/trunk@4515 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/audio.c')
-rw-r--r--src/audio.c53
1 files changed, 25 insertions, 28 deletions
diff --git a/src/audio.c b/src/audio.c
index eedbfb1ff..63aecb7f4 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -44,7 +44,7 @@ static AudioFormat audio_format;
static AudioFormat *audio_configFormat = NULL;
-static AudioOutput **audioOutputArray = NULL;
+static AudioOutput *audioOutputArray = NULL;
static mpd_uint8 audioOutputArraySize = 0;
#define DEVICE_OFF 0x00
@@ -120,33 +120,30 @@ void initAudioDriver(void)
audioOutputArraySize = audio_device_count();
audioDeviceStates = (getPlayerData())->audioDeviceStates;
- audioOutputArray = malloc(sizeof(AudioOutput *) * audioOutputArraySize);
-
+ audioOutputArray = malloc(sizeof(AudioOutput) * audioOutputArraySize);
i = 0;
param = getNextConfigParam(CONF_AUDIO_OUTPUT, param);
do {
- AudioOutput *output;
+ AudioOutput *output = &audioOutputArray[i];
int j;
- output = newAudioOutput(param);
- if (!output && param) {
+ if (!initAudioOutput(output, param) && param) {
ERROR("problems configuring output device defined at "
"line %i\n", param->line);
exit(EXIT_FAILURE);
}
/* require output names to be unique: */
- for (j = i - 1; j >= 0; --j) {
- if (!strcmp(output->name, audioOutputArray[j]->name)) {
+ for (j = i; --j >= 0; ) {
+ if (!strcmp(output->name, audioOutputArray[j].name)) {
ERROR("output devices with identical "
"names: %s\n", output->name);
exit(EXIT_FAILURE);
}
}
- audioDeviceStates[i] = DEVICE_ENABLE;
- audioOutputArray[i++] = output;
+ audioDeviceStates[i++] = DEVICE_ENABLE;
} while ((param = getNextConfigParam(CONF_AUDIO_OUTPUT, param)));
}
@@ -253,7 +250,7 @@ void finishAudioDriver(void)
int i;
for (i = 0; i < audioOutputArraySize; i++) {
- finishAudioOutput(audioOutputArray[i]);
+ finishAudioOutput(&audioOutputArray[i]);
}
free(audioOutputArray);
@@ -283,11 +280,11 @@ static int flushAudioBuffer(void)
for (i = audioOutputArraySize; --i >= 0; ) {
switch (audioDeviceStates[i]) {
case DEVICE_ENABLE:
- openAudioOutput(audioOutputArray[i], &audio_format);
+ openAudioOutput(&audioOutputArray[i], &audio_format);
audioDeviceStates[i] = DEVICE_ON;
/* fall-through */
case DEVICE_ON:
- err = playAudioOutput(audioOutputArray[i], audioBuffer,
+ err = playAudioOutput(&audioOutputArray[i], audioBuffer,
audioBufferPos);
if (!err)
ret = 0;
@@ -297,8 +294,8 @@ static int flushAudioBuffer(void)
audioDeviceStates[i] = DEVICE_OFF;
break;
case DEVICE_DISABLE:
- dropBufferedAudioOutput(audioOutputArray[i]);
- closeAudioOutput(audioOutputArray[i]);
+ dropBufferedAudioOutput(&audioOutputArray[i]);
+ closeAudioOutput(&audioOutputArray[i]);
audioDeviceStates[i] = DEVICE_OFF;
break;
}
@@ -330,15 +327,15 @@ int openAudioDevice(AudioFormat * audioFormat)
for (i = audioOutputArraySize; --i >= 0; ) {
switch (audioDeviceStates[i]) {
case DEVICE_ENABLE:
- openAudioOutput(audioOutputArray[i], &audio_format);
+ openAudioOutput(&audioOutputArray[i], &audio_format);
audioDeviceStates[i] = DEVICE_ON;
/* fall-through */
case DEVICE_ON:
ret = 0;
break;
case DEVICE_DISABLE:
- dropBufferedAudioOutput(audioOutputArray[i]);
- closeAudioOutput(audioOutputArray[i]);
+ dropBufferedAudioOutput(&audioOutputArray[i]);
+ closeAudioOutput(&audioOutputArray[i]);
audioDeviceStates[i] = DEVICE_OFF;
break;
}
@@ -349,7 +346,7 @@ int openAudioDevice(AudioFormat * audioFormat)
else {
/* close all devices if there was an error */
for (i = audioOutputArraySize; --i >= 0; ) {
- closeAudioOutput(audioOutputArray[i]);
+ closeAudioOutput(&audioOutputArray[i]);
}
audioOpened = 0;
@@ -393,17 +390,17 @@ void dropBufferedAudio(void)
for (i = audioOutputArraySize; --i >= 0; ) {
switch (audioDeviceStates[i]) {
case DEVICE_ON:
- dropBufferedAudioOutput(audioOutputArray[i]);
+ dropBufferedAudioOutput(&audioOutputArray[i]);
break;
case DEVICE_ENABLE:
- openAudioOutput(audioOutputArray[i], &audio_format);
+ openAudioOutput(&audioOutputArray[i], &audio_format);
audioDeviceStates[i] = DEVICE_ON;
/* there's no point in dropping audio for something
* we just enabled */
break;
case DEVICE_DISABLE:
- dropBufferedAudioOutput(audioOutputArray[i]);
- closeAudioOutput(audioOutputArray[i]);
+ dropBufferedAudioOutput(&audioOutputArray[i]);
+ closeAudioOutput(&audioOutputArray[i]);
audioDeviceStates[i] = DEVICE_OFF;
break;
}
@@ -421,7 +418,7 @@ void closeAudioDevice(void)
audioBufferSize = 0;
for (i = audioOutputArraySize; --i >= 0; ) {
- closeAudioOutput(audioOutputArray[i]);
+ closeAudioOutput(&audioOutputArray[i]);
}
audioOpened = 0;
@@ -432,7 +429,7 @@ void sendMetadataToAudioDevice(MpdTag * tag)
int i;
for (i = audioOutputArraySize; --i >= 0; ) {
- sendMetadataToAudioOutput(audioOutputArray[i], tag);
+ sendMetadataToAudioOutput(&audioOutputArray[i], tag);
}
}
@@ -471,7 +468,7 @@ void printAudioDevices(int fd)
fdprintf(fd,
"outputid: %i\noutputname: %s\noutputenabled: %i\n",
i,
- audioOutputArray[i]->name,
+ audioOutputArray[i].name,
audioDeviceStates[i] & 0x01);
}
}
@@ -484,7 +481,7 @@ void saveAudioDevicesState(FILE *fp)
for (i = 0; i < audioOutputArraySize; i++) {
fprintf(fp, AUDIO_DEVICE_STATE "%d:%s\n",
audioDeviceStates[i] & 0x01,
- audioOutputArray[i]->name);
+ audioOutputArray[i].name);
}
}
@@ -510,7 +507,7 @@ void readAudioDevicesState(FILE *fp)
goto errline;
for (i = audioOutputArraySize; --i >= 0; ) {
- if (!strcmp(name, audioOutputArray[i]->name)) {
+ if (!strcmp(name, audioOutputArray[i].name)) {
/* devices default to on */
if (!atoi(c))
audioDeviceStates[i] = DEVICE_DISABLE;