From 29595ca7bfd48e988c4350f9965f926749a8eb8e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 19 Feb 2024 15:09:41 +0100 Subject: [PATCH] audioadapter: clear buffers when format is reconfigured Always clear the Buffers when the format is reconfigured because they depend on the Format. --- spa/plugins/audioconvert/audioadapter.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/spa/plugins/audioconvert/audioadapter.c b/spa/plugins/audioconvert/audioadapter.c index 9c93a56b9..73bc8364d 100644 --- a/spa/plugins/audioconvert/audioadapter.c +++ b/spa/plugins/audioconvert/audioadapter.c @@ -472,6 +472,13 @@ static int negotiate_buffers(struct impl *this) return 0; } +static void clear_buffers(struct impl *this) +{ + free(this->buffers); + this->buffers = NULL; + this->n_buffers = 0; +} + static int configure_format(struct impl *this, uint32_t flags, const struct spa_pod *format) { uint8_t buffer[4096]; @@ -515,11 +522,11 @@ static int configure_format(struct impl *this, uint32_t flags, const struct spa_ } this->have_format = format != NULL; - if (format == NULL) { - this->n_buffers = 0; - } else if (this->target != this->follower) { + clear_buffers(this); + + if (format != NULL && this->target != this->follower) res = negotiate_buffers(this); - } + return res; } @@ -1725,10 +1732,7 @@ static int impl_clear(struct spa_handle *handle) spa_handle_clear(this->hnd_convert); - if (this->buffers) - free(this->buffers); - this->buffers = NULL; - + clear_buffers(this); return 0; }