aboutsummaryrefslogtreecommitdiffstats
path: root/src/audioOutputs/audioOutput_alsa.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-09-08 20:42:39 +0200
committerMax Kellermann <max@duempel.org>2008-09-08 20:42:39 +0200
commit67c642c93501e206950f2e79a64fb334f1cb8ea3 (patch)
tree89afb1fbcde747f7d4088d2154cd6be861970d6b /src/audioOutputs/audioOutput_alsa.c
parentf1f1104b2cb49ea9cc7e8e156a30950ffaf04a56 (diff)
downloadmpd-67c642c93501e206950f2e79a64fb334f1cb8ea3.tar.gz
mpd-67c642c93501e206950f2e79a64fb334f1cb8ea3.tar.xz
mpd-67c642c93501e206950f2e79a64fb334f1cb8ea3.zip
alsa: avoid unnecessary heap usage if we don't set a device name
Diffstat (limited to '')
-rw-r--r--src/audioOutputs/audioOutput_alsa.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/audioOutputs/audioOutput_alsa.c b/src/audioOutputs/audioOutput_alsa.c
index 81db6923c..759ef5db4 100644
--- a/src/audioOutputs/audioOutput_alsa.c
+++ b/src/audioOutputs/audioOutput_alsa.c
@@ -23,6 +23,8 @@
#define ALSA_PCM_NEW_HW_PARAMS_API
#define ALSA_PCM_NEW_SW_PARAMS_API
+static const char default_device[] = "default";
+
#define MPD_ALSA_BUFFER_TIME_US 500000
/* the default period time of xmms is 50 ms, so let's use that as well.
* a user can tweak this parameter via the "period_time" config parameter.
@@ -39,7 +41,7 @@ typedef snd_pcm_sframes_t alsa_writei_t(snd_pcm_t * pcm, const void *buffer,
snd_pcm_uframes_t size);
typedef struct _AlsaData {
- char *device;
+ const char *device;
snd_pcm_t *pcmHandle;
alsa_writei_t *writei;
unsigned int buffer_time;
@@ -52,7 +54,7 @@ static AlsaData *newAlsaData(void)
{
AlsaData *ret = xmalloc(sizeof(AlsaData));
- ret->device = NULL;
+ ret->device = default_device;
ret->pcmHandle = NULL;
ret->writei = snd_pcm_writei;
ret->useMmap = 0;
@@ -64,9 +66,8 @@ static AlsaData *newAlsaData(void)
static void freeAlsaData(AlsaData * ad)
{
- if (ad->device)
- free(ad->device);
-
+ if (ad->device && ad->device != default_device)
+ xfree(ad->device);
free(ad);
}
@@ -76,9 +77,10 @@ static int alsa_initDriver(struct audio_output *audioOutput,
AlsaData *ad = newAlsaData();
if (param) {
- BlockParam *bp = getBlockParam(param, "device");
- ad->device = bp ? xstrdup(bp->value) : xstrdup("default");
+ BlockParam *bp;
+ if ((bp = getBlockParam(param, "device")))
+ ad->device = xstrdup(bp->value);
ad->useMmap = getBoolBlockParam(param, "use_mmap", 1);
if (ad->useMmap == CONF_BOOL_UNSET)
ad->useMmap = 0;
@@ -86,8 +88,7 @@ static int alsa_initDriver(struct audio_output *audioOutput,
ad->buffer_time = atoi(bp->value);
if ((bp = getBlockParam(param, "period_time")))
ad->period_time = atoi(bp->value);
- } else
- ad->device = xstrdup("default");
+ }
audioOutput->data = ad;
return 0;
@@ -104,8 +105,8 @@ static int alsa_testDefault(void)
{
snd_pcm_t *handle;
- int ret = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK,
- SND_PCM_NONBLOCK);
+ int ret = snd_pcm_open(&handle, default_device,
+ SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
snd_config_update_free_global();
if (ret) {