From a23d1549523b8c2600719133aeb5d4563c1c4ffc Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 3 Aug 2022 11:32:10 +0200 Subject: [PATCH] audioconvert: always use DSP rate on DSP ports Always use the DSP rate on DSP ports for format conversion, not the previous used rate. This avoids some resampler reconfiguration as it negotiates a non-passthrough rate conversion and then switches to passthrough when the rate correction is done to match the graph rate. See #2614 --- spa/plugins/audioconvert/audioconvert.c | 17 ++++++++++------- src/pipewire/context.c | 3 +++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/spa/plugins/audioconvert/audioconvert.c b/spa/plugins/audioconvert/audioconvert.c index 7fe3a2d01..070d84056 100644 --- a/spa/plugins/audioconvert/audioconvert.c +++ b/spa/plugins/audioconvert/audioconvert.c @@ -1471,26 +1471,29 @@ static int setup_convert(struct impl *this) rate = this->io_position ? this->io_position->clock.rate.denom : DEFAULT_RATE; - if (in->format.info.raw.rate == 0 && in->mode == SPA_PARAM_PORT_CONFIG_MODE_dsp) + /* in DSP mode we always convert to the DSP rate */ + if (in->mode == SPA_PARAM_PORT_CONFIG_MODE_dsp) in->format.info.raw.rate = rate; - if (out->format.info.raw.rate == 0 && out->mode == SPA_PARAM_PORT_CONFIG_MODE_dsp) + if (out->mode == SPA_PARAM_PORT_CONFIG_MODE_dsp) out->format.info.raw.rate = rate; + /* try to passthrough the rates */ if (in->format.info.raw.rate == 0) in->format.info.raw.rate = out->format.info.raw.rate; else if (out->format.info.raw.rate == 0) out->format.info.raw.rate = in->format.info.raw.rate; - if (in->format.info.raw.rate == 0 && out->format.info.raw.rate == 0) - return -EINVAL; - if (in->format.info.raw.channels == 0 && out->format.info.raw.channels == 0) - return -EINVAL; - + /* try to passthrough the channels */ if (in->format.info.raw.channels == 0) in->format.info.raw.channels = out->format.info.raw.channels; else if (out->format.info.raw.channels == 0) out->format.info.raw.channels = in->format.info.raw.channels; + if (in->format.info.raw.rate == 0 || out->format.info.raw.rate == 0) + return -EINVAL; + if (in->format.info.raw.channels == 0 || out->format.info.raw.channels == 0) + return -EINVAL; + if ((res = setup_in_convert(this)) < 0) return res; if ((res = setup_channelmix(this)) < 0) diff --git a/src/pipewire/context.c b/src/pipewire/context.c index bcfa10485..24e754e1b 100644 --- a/src/pipewire/context.c +++ b/src/pipewire/context.c @@ -1382,6 +1382,9 @@ again: * panding change. Apply the change to the position now so * that we have the right values when we change the node * states of the driver and followers to RUNNING below */ + pw_log_debug("%p: apply duration:%"PRIu64" rate:%u/%u", context, + n->current_quantum, n->current_rate.num, + n->current_rate.denom); n->rt.position->clock.duration = n->current_quantum; n->rt.position->clock.rate = n->current_rate; n->current_pending = false;