From afc0e6e69dd286d2b9ffc34c5f9771347f8a12de Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 31 Jul 2024 16:20:15 +0200 Subject: [PATCH] module-ffado: keep the configured rate in sync with params When we reconfigure rate, make sure we update the EnumFormat and Format params with the new value. --- src/modules/module-ffado-driver.c | 42 +++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/modules/module-ffado-driver.c b/src/modules/module-ffado-driver.c index edcb7e047..47e62f9b0 100644 --- a/src/modules/module-ffado-driver.c +++ b/src/modules/module-ffado-driver.c @@ -895,6 +895,31 @@ static const struct pw_filter_events source_events = { .process = source_process, }; +static int update_stream_format(struct stream *s, uint32_t samplerate) +{ + uint8_t buffer[1024]; + struct spa_pod_builder b; + uint32_t n_params; + const struct spa_pod *params[2]; + + if (s->info.rate == samplerate) + return 0; + + s->info.rate = samplerate; + + if (s->filter == NULL) + return 0; + + n_params = 0; + spa_pod_builder_init(&b, buffer, sizeof(buffer)); + params[n_params++] = spa_format_audio_raw_build(&b, + SPA_PARAM_EnumFormat, &s->info); + params[n_params++] = spa_format_audio_raw_build(&b, + SPA_PARAM_Format, &s->info); + + return pw_filter_update_params(s->filter, NULL, params, n_params); +} + static int make_stream(struct stream *s, const char *name) { struct impl *impl = s->impl; @@ -902,11 +927,6 @@ static int make_stream(struct stream *s, const char *name) const struct spa_pod *params[4]; uint8_t buffer[1024]; struct spa_pod_builder b; - struct spa_latency_info latency; - - spa_zero(latency); - n_params = 0; - spa_pod_builder_init(&b, buffer, sizeof(buffer)); s->filter = pw_filter_new(impl->core, name, pw_properties_copy(s->props)); if (s->filter == NULL) @@ -923,6 +943,8 @@ static int make_stream(struct stream *s, const char *name) reset_volume(&s->volume, s->info.channels); + spa_pod_builder_init(&b, buffer, sizeof(buffer)); + n_params = 0; params[n_params++] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, &s->info); @@ -1075,6 +1097,10 @@ static int open_ffado_device(struct impl *impl) if (target_period == 0) target_period = c->target_duration; } + if (target_rate == 0) + target_rate = DEFAULT_SAMPLE_RATE; + if (target_period == 0) + target_period = DEFAULT_PERIOD_SIZE; spa_zero(impl->device_info); impl->device_info.device_spec_strings = impl->devices; @@ -1105,9 +1131,6 @@ static int open_ffado_device(struct impl *impl) ffado_streaming_set_audio_datatype(impl->dev, ffado_audio_datatype_float); - impl->source.info.rate = impl->device_options.sample_rate; - impl->sink.info.rate = impl->device_options.sample_rate; - impl->source.n_ports = ffado_streaming_get_nb_capture_streams(impl->dev); impl->sink.n_ports = ffado_streaming_get_nb_playback_streams(impl->dev); @@ -1116,6 +1139,9 @@ static int open_ffado_device(struct impl *impl) return -EIO; } + update_stream_format(&impl->source, impl->device_options.sample_rate); + update_stream_format(&impl->sink, impl->device_options.sample_rate); + pw_log_info("opened FFADO device %s source:%d sink:%d rate:%d period:%d %p", impl->devices[0], impl->source.n_ports, impl->sink.n_ports, impl->device_options.sample_rate,