[alsa-devel] [PATCH 2/2] pcm_pulse: set prebuf parameter according to software parameters

Rémi Denis-Courmont remi at remlab.net
Wed Nov 14 19:07:57 CET 2012


The current default value for prebuf is very high, almost the full
virtual ALSA buffer. This breaks some application especially where
low latency is involved.

This patch makes pcm_pulse implement the sw_params callback and get
the prebuf value from the ALSA software parameters. Thus the
trigger latency is much more like what an ALSA application should
expect from an ALSA PCM device.
---
 pulse/pcm_pulse.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/pulse/pcm_pulse.c b/pulse/pcm_pulse.c
index 0165120..08b6cea 100644
--- a/pulse/pcm_pulse.c
+++ b/pulse/pcm_pulse.c
@@ -859,6 +859,30 @@ static int pulse_hw_params(snd_pcm_ioplug_t * io,
 	return err;
 }
 
+static int pulse_sw_params(snd_pcm_ioplug_t *io, snd_pcm_sw_params_t *params)
+{
+	snd_pcm_pulse_t *pcm = io->private_data;
+	snd_pcm_uframes_t start_threshold;
+
+	assert(pcm);
+
+	if (!pcm->p || !pcm->p->mainloop)
+		return -EBADFD;
+
+	pa_threaded_mainloop_lock(pcm->p->mainloop);
+
+	snd_pcm_sw_params_get_start_threshold(params, &start_threshold);
+
+	if (start_threshold < io->period_size)
+		start_threshold = io->period_size;
+
+	pcm->buffer_attr.prebuf = start_threshold * pcm->frame_size;
+
+	pa_threaded_mainloop_unlock(pcm->p->mainloop);
+
+	return 0;
+}
+
 static int pulse_close(snd_pcm_ioplug_t * io)
 {
 	snd_pcm_pulse_t *pcm = io->private_data;
@@ -925,6 +949,7 @@ static const snd_pcm_ioplug_callback_t pulse_playback_callback = {
 	.poll_revents = pulse_pcm_poll_revents,
 	.prepare = pulse_prepare,
 	.hw_params = pulse_hw_params,
+	.sw_params = pulse_sw_params,
 	.close = pulse_close,
 	.pause = pulse_pause
 };
-- 
1.7.10.4



More information about the Alsa-devel mailing list