When set latency is less than period time, we will assgin working buffer less than a period size, which will cause unnecessary xrun and wrong message indicating alsa driver bug. Signed-off-by: Feng Wei <feng.wei at linaro.org> --- src/modules/alsa/alsa-sink.c | 6 +++--- src/modules/alsa/alsa-source.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c index 5a4b606..a53fb6f 100644 --- a/src/modules/alsa/alsa-sink.c +++ b/src/modules/alsa/alsa-sink.c @@ -953,10 +953,10 @@ static int update_sw_params(struct userdata *u) { b = pa_usec_to_bytes(latency, &u->sink->sample_spec); - /* We need at least one sample in our buffer */ + /* We need at least one period and one sample in our buffer to avoid underflow */ - if (PA_UNLIKELY(b < u->frame_size)) - b = u->frame_size; + if (PA_UNLIKELY(b < u->frame_size + u->fragment_size)) + b = u->frame_size + u->fragment_size; u->hwbuf_unused = PA_LIKELY(b < u->hwbuf_size) ? (u->hwbuf_size - b) : 0; } diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c index 27fd3b9..8c41ca6 100644 --- a/src/modules/alsa/alsa-source.c +++ b/src/modules/alsa/alsa-source.c @@ -876,10 +876,10 @@ static int update_sw_params(struct userdata *u) { b = pa_usec_to_bytes(latency, &u->source->sample_spec); - /* We need at least one sample in our buffer */ + /* We need at least one period and one sample in our buffer to avoid overflow */ - if (PA_UNLIKELY(b < u->frame_size)) - b = u->frame_size; + if (PA_UNLIKELY(b < u->frame_size + u->fragment_size)) + b = u->frame_size + u->fragment_size; u->hwbuf_unused = PA_LIKELY(b < u->hwbuf_size) ? (u->hwbuf_size - b) : 0; } -- 1.7.4.1