summaryrefslogtreecommitdiffstats
path: root/libao2/ao_alsa.c
diff options
context:
space:
mode:
authorUoti Urpala <uau@glyph.nonexistent.invalid>2009-12-29 16:37:27 +0200
committerUoti Urpala <uau@glyph.nonexistent.invalid>2009-12-29 16:54:38 +0200
commitc447ef4e746fe4952f547b5f21e21cb3f052caa5 (patch)
tree17cd9b183cad894029fe0d8f27a14bb7afeaf8c5 /libao2/ao_alsa.c
parent57ce95b96a9d5ff75b5afa608bdda8366a999cf5 (diff)
downloadmpv-c447ef4e746fe4952f547b5f21e21cb3f052caa5.tar.bz2
mpv-c447ef4e746fe4952f547b5f21e21cb3f052caa5.tar.xz
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.
Diffstat (limited to 'libao2/ao_alsa.c')
-rw-r--r--libao2/ao_alsa.c8
1 files changed, 4 insertions, 4 deletions
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;