From c447ef4e746fe4952f547b5f21e21cb3f052caa5 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Tue, 29 Dec 2009 16:37:27 +0200 Subject: ao_alsa: Reinitialize parameters properly when reopening ao_alsa used static variables to define the parameter values for snd_pcm_hw_params_set_buffer_time_near() and snd_pcm_hw_params_set_periods_near(). The variables were non-const and the desired value was only set in the initializer. The ALSA functions in question take a pointer argument to an in/out parameter which is modified to reflect the value actually used. As a result, when playing multiple files or otherwise reinitializing the AO the later instances could use values that had been modified by earlier calls. Change the code to always always use the same default values. --- libao2/ao_alsa.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libao2/ao_alsa.c') diff --git a/libao2/ao_alsa.c b/libao2/ao_alsa.c index 1e0967ce4d..4c92597765 100644 --- a/libao2/ao_alsa.c +++ b/libao2/ao_alsa.c @@ -72,8 +72,8 @@ static snd_pcm_format_t alsa_format; static snd_pcm_hw_params_t *alsa_hwparams; static snd_pcm_sw_params_t *alsa_swparams; -static unsigned int alsa_buffer_time = 500000; /* 0.5 s */ -static unsigned int alsa_fragcount = 16; +#define BUFFER_TIME 500000 // 0.5 s +#define FRAGCOUNT 16 static size_t bytes_per_sample; @@ -589,7 +589,7 @@ static int init(int rate_hz, int channels, int format, int flags) ao_data.bps = ao_data.samplerate * bytes_per_sample; if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams, - &alsa_buffer_time, NULL)) < 0) + &(unsigned int){BUFFER_TIME}, NULL)) < 0) { mp_tmsg(MSGT_AO,MSGL_ERR,"[AO_ALSA] Unable to set buffer time near: %s\n", snd_strerror(err)); @@ -597,7 +597,7 @@ static int init(int rate_hz, int channels, int format, int flags) } if ((err = snd_pcm_hw_params_set_periods_near(alsa_handler, alsa_hwparams, - &alsa_fragcount, NULL)) < 0) { + &(unsigned int){FRAGCOUNT}, NULL)) < 0) { mp_tmsg(MSGT_AO,MSGL_ERR,"[AO_ALSA] Unable to set periods: %s\n", snd_strerror(err)); return 0; -- cgit v1.2.3