audio: make audio_configFormat a static variable
Save one allocation, since the whole audio_format struct is nearly the same size as the pointer to it. Check audio_format_defined(af) instead of af!=NULL.
This commit is contained in:
13
src/audio.c
13
src/audio.c
@@ -30,7 +30,7 @@
|
|||||||
#define AUDIO_DEVICE_STATE_LEN (sizeof(AUDIO_DEVICE_STATE)-1)
|
#define AUDIO_DEVICE_STATE_LEN (sizeof(AUDIO_DEVICE_STATE)-1)
|
||||||
#define AUDIO_BUFFER_SIZE 2*MPD_PATH_MAX
|
#define AUDIO_BUFFER_SIZE 2*MPD_PATH_MAX
|
||||||
|
|
||||||
static struct audio_format *audio_configFormat;
|
static struct audio_format audio_configFormat;
|
||||||
|
|
||||||
static struct audio_output *audioOutputArray;
|
static struct audio_output *audioOutputArray;
|
||||||
static unsigned int audioOutputArraySize;
|
static unsigned int audioOutputArraySize;
|
||||||
@@ -115,8 +115,8 @@ void initAudioDriver(void)
|
|||||||
void getOutputAudioFormat(const struct audio_format *inAudioFormat,
|
void getOutputAudioFormat(const struct audio_format *inAudioFormat,
|
||||||
struct audio_format *outAudioFormat)
|
struct audio_format *outAudioFormat)
|
||||||
{
|
{
|
||||||
*outAudioFormat = audio_configFormat != NULL
|
*outAudioFormat = audio_format_defined(&audio_configFormat)
|
||||||
? *audio_configFormat
|
? audio_configFormat
|
||||||
: *inAudioFormat;
|
: *inAudioFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,9 +127,7 @@ void initAudioConfig(void)
|
|||||||
if (NULL == param || NULL == param->value)
|
if (NULL == param || NULL == param->value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
audio_configFormat = xmalloc(sizeof(*audio_configFormat));
|
if (0 != parseAudioConfig(&audio_configFormat, param->value)) {
|
||||||
|
|
||||||
if (0 != parseAudioConfig(audio_configFormat, param->value)) {
|
|
||||||
FATAL("error parsing \"%s\" at line %i\n",
|
FATAL("error parsing \"%s\" at line %i\n",
|
||||||
CONF_AUDIO_OUTPUT_FORMAT, param->line);
|
CONF_AUDIO_OUTPUT_FORMAT, param->line);
|
||||||
}
|
}
|
||||||
@@ -204,8 +202,7 @@ int parseAudioConfig(struct audio_format *audioFormat, char *conf)
|
|||||||
|
|
||||||
void finishAudioConfig(void)
|
void finishAudioConfig(void)
|
||||||
{
|
{
|
||||||
if (audio_configFormat)
|
audio_format_clear(&audio_configFormat);
|
||||||
free(audio_configFormat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void finishAudioDriver(void)
|
void finishAudioDriver(void)
|
||||||
|
Reference in New Issue
Block a user