From 4ffa7860bcd65637af50eb85a3953ea161bb2a98 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 14 Sep 2023 17:15:06 +0200 Subject: [PATCH] alsa: update the clock name when we can Update the clock name as soon as we get a io_clock. This way we can use it to compare the clock name against the driver right away. --- spa/plugins/alsa/alsa-pcm-sink.c | 4 ++++ spa/plugins/alsa/alsa-pcm-source.c | 2 ++ spa/plugins/alsa/alsa-pcm.c | 24 +++++++++++------------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/spa/plugins/alsa/alsa-pcm-sink.c b/spa/plugins/alsa/alsa-pcm-sink.c index f6602d6f9..39fca69fe 100644 --- a/spa/plugins/alsa/alsa-pcm-sink.c +++ b/spa/plugins/alsa/alsa-pcm-sink.c @@ -252,9 +252,13 @@ static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) switch (id) { case SPA_IO_Clock: + if (size > 0 && size < sizeof(struct spa_io_clock)) + return -EINVAL; this->clock = data; break; case SPA_IO_Position: + if (size > 0 && size < sizeof(struct spa_io_position)) + return -EINVAL; this->position = data; break; default: diff --git a/spa/plugins/alsa/alsa-pcm-source.c b/spa/plugins/alsa/alsa-pcm-source.c index cccbd12ab..356c9336a 100644 --- a/spa/plugins/alsa/alsa-pcm-source.c +++ b/spa/plugins/alsa/alsa-pcm-source.c @@ -235,6 +235,8 @@ static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) this->clock = data; break; case SPA_IO_Position: + if (size > 0 && size < sizeof(struct spa_io_position)) + return -EINVAL; this->position = data; break; default: diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index 687f50b4b..530e9ef2e 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -654,10 +654,6 @@ int spa_alsa_open(struct state *state, const char *params) /* ALSA pollfds may only be ready after setting swparams, so * these are initialised in spa_alsa_start() */ } - - if (state->clock) - spa_scnprintf(state->clock->name, sizeof(state->clock->name), - "%s", state->clock_name); state->opened = true; state->sample_count = 0; state->sample_time = 0; @@ -2965,16 +2961,17 @@ int spa_alsa_reassign_follower(struct state *state) { bool following, freewheel; - if (!state->started) - return 0; + if (state->clock != NULL) + spa_scnprintf(state->clock->name, sizeof(state->clock->name), "%s", state->clock_name); following = is_following(state); if (following != state->following) { spa_log_debug(state->log, "%p: reassign follower %d->%d", state, state->following, following); state->following = following; - spa_loop_invoke(state->data_loop, do_setup_sources, 0, NULL, 0, true, state); + setup_matching(state); + if (state->started) + spa_loop_invoke(state->data_loop, do_setup_sources, 0, NULL, 0, true, state); } - setup_matching(state); freewheel = state->position && SPA_FLAG_IS_SET(state->position->clock.flags, SPA_IO_CLOCK_FLAG_FREEWHEEL); @@ -2982,12 +2979,13 @@ int spa_alsa_reassign_follower(struct state *state) if (state->freewheel != freewheel) { spa_log_debug(state->log, "%p: freewheel %d->%d", state, state->freewheel, freewheel); state->freewheel = freewheel; - if (freewheel) - snd_pcm_pause(state->hndl, 1); - else - snd_pcm_pause(state->hndl, 0); + if (state->started) { + if (freewheel) + snd_pcm_pause(state->hndl, 1); + else + snd_pcm_pause(state->hndl, 0); + } } - state->alsa_sync_warning = false; return 0; }