Skip to content

Commit 17cb03b

Browse files
wjablon1kv2019i
authored andcommitted
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 4241c75 commit 17cb03b

4 files changed

Lines changed: 48 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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
SOF_DEFINE_REG_UUID(asrc);
1818

1919
DECLARE_TR_CTX(asrc_tr, SOF_UUID(asrc_uuid), LOG_LEVEL_INFO);
20+
LOG_MODULE_DECLARE(asrc, CONFIG_SOF_LOG_LEVEL);
2021

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

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+
(void)mod;
86+
(void)params;
87+
88+
return 0;
89+
}

0 commit comments

Comments
 (0)