From bf1c9270875b722665d742f03b1859a038289b4b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 5 Dec 2018 11:23:30 +0100 Subject: [PATCH] alsa: reset queued and free buffers on start When we are out of buffers, drop the available samples. --- spa/plugins/alsa/alsa-utils.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/spa/plugins/alsa/alsa-utils.c b/spa/plugins/alsa/alsa-utils.c index dfa347cf8..9dc6112d8 100644 --- a/spa/plugins/alsa/alsa-utils.c +++ b/spa/plugins/alsa/alsa-utils.c @@ -769,7 +769,8 @@ push_frames(struct state *state, snd_pcm_uframes_t total_frames = 0; if (spa_list_is_empty(&state->free)) { - spa_log_trace(state->log, "no more buffers"); + spa_log_warn(state->log, "no more buffers"); + total_frames = state->threshold; } else { uint8_t *src; size_t n_bytes; @@ -940,6 +941,24 @@ next: set_timeout(state, state->next_time); } +static void reset_buffers(struct state *this) +{ + int i; + + spa_list_init(&this->free); + spa_list_init(&this->ready); + + for (i = 0; i < this->n_buffers; i++) { + struct buffer *b = &this->buffers[i]; + if (this->stream == SND_PCM_STREAM_PLAYBACK) { + SPA_FLAG_SET(b->flags, BUFFER_FLAG_OUT); + } else { + spa_list_append(&this->free, &b->link); + SPA_FLAG_UNSET(b->flags, BUFFER_FLAG_OUT); + } + } +} + int spa_alsa_start(struct state *state) { int err; @@ -984,6 +1003,8 @@ int spa_alsa_start(struct state *state) spa_loop_add_source(state->data_loop, &state->source); } + reset_buffers(state); + if (state->stream == SND_PCM_STREAM_PLAYBACK) { state->alsa_started = false; spa_alsa_write(state, state->threshold * 2, true);