Skip to content

Commit ccad2ba

Browse files
committed
audio: asrc: fix runtime params validation
IPC4 params do not provide a PCM sampling rate that is dynamically selected based on the mode (PULL/PUSH). Instead, the received params contain only a copy of the source rate already stored in ipc4_asrc_module_cfg. As a result, mode-dependent validation can trigger a bogus error. Fix this by splitting params validation into IPC protocol-specific functions. Signed-off-by: Wojciech Jablonski <wojciech.jablonski@intel.com>
1 parent 4f2c965 commit ccad2ba

4 files changed

Lines changed: 47 additions & 43 deletions

File tree

src/audio/asrc/asrc.c

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -336,47 +336,6 @@ static int asrc_set_config(struct processing_module *mod, uint32_t config_id,
336336
return -EINVAL;
337337
}
338338

339-
static int asrc_verify_params(struct processing_module *mod,
340-
struct sof_ipc_stream_params *params)
341-
{
342-
struct comp_data *cd = module_get_private_data(mod);
343-
struct comp_dev *dev = mod->dev;
344-
int ret;
345-
346-
comp_dbg(dev, "entry");
347-
348-
/* check whether params->rate (received from driver) are equal
349-
* to asrc->source_rate (PLAYBACK) or asrc->sink_rate (CAPTURE) set
350-
* during creating src component in asrc_new().
351-
* src->source/sink_rate = 0 means that source/sink rate can vary.
352-
*/
353-
if (dev->direction == SOF_IPC_STREAM_PLAYBACK) {
354-
if (asrc_get_source_rate(&cd->ipc_config) &&
355-
params->rate != asrc_get_source_rate(&cd->ipc_config)) {
356-
comp_err(dev, "runtime stream pcm rate %u does not match rate %u fetched from ipc.",
357-
params->rate, asrc_get_source_rate(&cd->ipc_config));
358-
return -EINVAL;
359-
}
360-
} else {
361-
if (asrc_get_sink_rate(&cd->ipc_config) &&
362-
params->rate != asrc_get_sink_rate(&cd->ipc_config)) {
363-
comp_err(dev, "runtime stream pcm rate %u does not match rate %u fetched from ipc.",
364-
params->rate, asrc_get_sink_rate(&cd->ipc_config));
365-
return -EINVAL;
366-
}
367-
}
368-
369-
/* update downstream (playback) or upstream (capture) buffer parameters
370-
*/
371-
ret = comp_verify_params(dev, BUFF_PARAMS_RATE, params);
372-
if (ret < 0) {
373-
comp_err(dev, "comp_verify_params() failed.");
374-
return ret;
375-
}
376-
377-
return 0;
378-
}
379-
380339
/* set component audio stream parameters */
381340
static int asrc_params(struct processing_module *mod)
382341
{
@@ -390,9 +349,13 @@ static int asrc_params(struct processing_module *mod)
390349

391350
asrc_set_stream_params(cd, pcm_params);
392351

393-
err = asrc_verify_params(mod, pcm_params);
352+
err = asrc_verify_stream_params(mod, pcm_params);
353+
if (err < 0)
354+
return -EINVAL;
355+
356+
err = comp_verify_params(dev, BUFF_PARAMS_RATE, pcm_params);
394357
if (err < 0) {
395-
comp_err(dev, "pcm params verification failed.");
358+
comp_err(dev, "comp_verify_params() failed.");
396359
return -EINVAL;
397360
}
398361

src/audio/asrc/asrc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ int asrc_dai_start_timestamp(struct comp_data *cd);
124124
int asrc_dai_stop_timestamp(struct comp_data *cd);
125125
void asrc_update_buffer_format(struct comp_buffer *buf_c, struct comp_data *cd);
126126
void asrc_set_stream_params(struct comp_data *cd, struct sof_ipc_stream_params *params);
127+
int asrc_verify_stream_params(struct processing_module *mod, struct sof_ipc_stream_params *params);
127128
extern struct tr_ctx asrc_tr;
128129

129130
/* Different UUID names for different build configurations... */

src/audio/asrc/asrc_ipc3.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,31 @@ void asrc_set_stream_params(struct comp_data *cd, struct sof_ipc_stream_params *
6363
{
6464
/* IPC3 don't need to update audio stream format here. */
6565
}
66+
67+
int asrc_verify_stream_params(struct processing_module *mod, struct sof_ipc_stream_params *params)
68+
{
69+
struct comp_data *cd = module_get_private_data(mod);
70+
struct comp_dev *dev = mod->dev;
71+
72+
/* PCM sampling rate received in params is dynamically selected based on the mode
73+
* (PULL/PUSH). Need to validate it against the initial fixed ASRC configuration
74+
* src->source/sink_rate = 0 means that source/sink rate can vary.
75+
*/
76+
if (dev->direction == SOF_IPC_STREAM_PLAYBACK) {
77+
if (asrc_get_source_rate(&cd->ipc_config) &&
78+
params->rate != asrc_get_source_rate(&cd->ipc_config)) {
79+
comp_err(dev, "runtime stream pcm rate %u does not match rate %u fetched from ipc.",
80+
params->rate, asrc_get_source_rate(&cd->ipc_config));
81+
return -EINVAL;
82+
}
83+
} else {
84+
if (asrc_get_sink_rate(&cd->ipc_config) &&
85+
params->rate != asrc_get_sink_rate(&cd->ipc_config)) {
86+
comp_err(dev, "runtime stream pcm rate %u does not match rate %u fetched from ipc.",
87+
params->rate, asrc_get_sink_rate(&cd->ipc_config));
88+
return -EINVAL;
89+
}
90+
}
91+
92+
return 0;
93+
}

src/audio/asrc/asrc_ipc4.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,15 @@ void asrc_set_stream_params(struct comp_data *cd, struct sof_ipc_stream_params *
7575
{
7676
ipc4_base_module_cfg_to_stream_params(&cd->ipc_config.base, params);
7777
}
78+
79+
int asrc_verify_stream_params(struct processing_module *mod, struct sof_ipc_stream_params *params)
80+
{
81+
/* IPC4 params contain the same fixed sampling rate that is already stored in
82+
* ipc4_asrc_module_cfg, rather than a PCM sampling rate that is dynamically selected
83+
* based on the mode (PULL/PUSH) as in IPC3. For now leave the function empty.
84+
*/
85+
ARG_UNUSED(mod);
86+
ARG_UNUSED(params);
87+
88+
return 0;
89+
}

0 commit comments

Comments
 (0)