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.
This commit is contained in:
Uoti Urpala 2009-12-29 16:37:27 +02:00
parent 57ce95b96a
commit c447ef4e74
1 changed files with 4 additions and 4 deletions

View File

@ -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;