From 25bfc9c63dba024aa4182434e4e04d26ccddbd05 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 23 Nov 2021 12:20:27 +0100 Subject: [PATCH] alsa: refactor a bit Make spa_alsa_close() do spa_alsa_pause() first and also clear the format. --- spa/plugins/alsa/alsa-pcm-sink.c | 7 +------ spa/plugins/alsa/alsa-pcm-source.c | 6 +----- spa/plugins/alsa/alsa-pcm.c | 7 +++++++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm-sink.c b/spa/plugins/alsa/alsa-pcm-sink.c index 88e407240..e3295a70b 100644 --- a/spa/plugins/alsa/alsa-pcm-sink.c +++ b/spa/plugins/alsa/alsa-pcm-sink.c @@ -644,11 +644,8 @@ static int port_set_format(void *object, return 0; spa_log_debug(this->log, "clear format"); - this->card->format_ref--; - spa_alsa_pause(this); - clear_buffers(this); spa_alsa_close(this); - this->have_format = false; + clear_buffers(this); } else { struct spa_audio_info info = { 0 }; @@ -679,7 +676,6 @@ static int port_set_format(void *object, return err; this->current_format = info; - this->have_format = true; } this->info.change_mask |= SPA_NODE_CHANGE_MASK_PROPS; @@ -1025,7 +1021,6 @@ impl_init(const struct spa_handle_factory *factory, this->multi_rate = spa_atob(s); } } - return spa_alsa_init(this); } diff --git a/spa/plugins/alsa/alsa-pcm-source.c b/spa/plugins/alsa/alsa-pcm-source.c index db12467b0..6bf820f5b 100644 --- a/spa/plugins/alsa/alsa-pcm-source.c +++ b/spa/plugins/alsa/alsa-pcm-source.c @@ -587,11 +587,8 @@ static int port_set_format(void *object, return 0; spa_log_debug(this->log, "clear format"); - this->card->format_ref--; - spa_alsa_pause(this); - clear_buffers(this); spa_alsa_close(this); - this->have_format = false; + clear_buffers(this); } else { struct spa_audio_info info = { 0 }; @@ -609,7 +606,6 @@ static int port_set_format(void *object, return err; this->current_format = info; - this->have_format = true; } this->info.change_mask |= SPA_NODE_CHANGE_MASK_PROPS; diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index e39cadce3..11229132c 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -176,6 +176,8 @@ int spa_alsa_close(struct state *state) if (!state->opened) return 0; + spa_alsa_pause(state); + spa_log_info(state->log, "%p: Device '%s' closing", state, state->props.device); if ((err = snd_pcm_close(state->hndl)) < 0) spa_log_warn(state->log, "%s: close failed: %s", state->props.device, @@ -186,6 +188,10 @@ int spa_alsa_close(struct state *state) spa_system_close(state->data_system, state->timerfd); + if (state->have_format) + state->card->format_ref--; + + state->have_format = false; state->opened = false; return err; @@ -1022,6 +1028,7 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_ else state->frame_size *= rchannels; + state->have_format = true; if (state->card->format_ref++ == 0) state->card->rate = rrate;