audioOutput_alsa.c: avoid changing our internal period and buffer time values

Passing a ref to snd_pcm_hw_params_set_{buffer,period}_time_near
can modify our internal {period,buffer}_time members inside the
AlsaData structure, making re-initializing the device across
sample/bit rate and channel changes non-idempotent.

git-svn-id: https://svn.musicpd.org/mpd/trunk@4616 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Eric Wong 2006-08-12 18:20:55 +00:00
parent b5361f7789
commit 0511e14db0

View File

@ -140,8 +140,9 @@ static int alsa_openDevice(AudioOutput * audioOutput)
snd_pcm_uframes_t alsa_period_size;
int err;
const char *cmd = NULL;
unsigned int period_time;
int retry = MPD_ALSA_RETRY_NR;
unsigned int period_time, period_time_ro;
unsigned int buffer_time;
switch (audioFormat->bits) {
case 8:
@ -175,6 +176,7 @@ static int alsa_openDevice(AudioOutput * audioOutput)
if (err < 0)
goto error;
period_time_ro = period_time = ad->period_time;
configure_hw:
/* configure HW params */
snd_pcm_hw_params_alloca(&hwparams);
@ -231,28 +233,29 @@ configure_hw:
}
audioFormat->sampleRate = sampleRate;
buffer_time = ad->buffer_time;
cmd = "snd_pcm_hw_params_set_buffer_time_near";
err = snd_pcm_hw_params_set_buffer_time_near(ad->pcmHandle, hwparams,
&ad->buffer_time, NULL);
&buffer_time, NULL);
if (err < 0)
goto error;
period_time = ad->period_time;
period_time = period_time_ro;
cmd = "snd_pcm_hw_params_set_period_time_near";
err = snd_pcm_hw_params_set_period_time_near(ad->pcmHandle, hwparams,
&ad->period_time, NULL);
&period_time, NULL);
if (err < 0)
goto error;
cmd = "snd_pcm_hw_params";
err = snd_pcm_hw_params(ad->pcmHandle, hwparams);
if (err == -EPIPE && --retry > 0) {
ad->period_time = period_time >> 1;
period_time_ro = period_time_ro >> 1;
goto configure_hw;
} else if (err < 0)
goto error;
if (retry != MPD_ALSA_RETRY_NR)
DEBUG("ALSA period_time set to %d\n", ad->period_time);
DEBUG("ALSA period_time set to %d\n", period_time);
cmd = "snd_pcm_hw_params_get_buffer_size";
err = snd_pcm_hw_params_get_buffer_size(hwparams, &alsa_buffer_size);