Skip to content

Commit a658cc1

Browse files
committed
src: audio: module_adapter: Do the params config right after init
The module_adapter_params() functions set the stream params based on the base config for each module which is available right after module init. So configure the params for IPC4 during module_new() and remove the call to ipc4_pipeline_params(). In order to update the buffer params, add a call to comp_verify_params() during module_adapter_prepare in order to update the intermediate buffers. This should help with reducing the time to trigger pipelines during start. Add the params handling for the KPB and detect_test modules explicitly because they don't use the module adapter. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
1 parent 60e7a0a commit a658cc1

File tree

4 files changed

+52
-50
lines changed

4 files changed

+52
-50
lines changed

src/audio/kpb.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ static void kpb_set_params(struct comp_dev *dev,
453453
{}
454454
#endif /* CONFIG_IPC_MAJOR_4 */
455455

456+
static int kpb_params(struct comp_dev *dev, struct sof_ipc_stream_params *params);
457+
456458
/*
457459
* \brief Create a key phrase buffer component.
458460
* \param[in] config - generic ipc component pointer.
@@ -534,6 +536,17 @@ static struct comp_dev *kpb_new(const struct comp_driver *drv,
534536
dev->state = COMP_STATE_READY;
535537
kpb_change_state(kpb, KPB_STATE_CREATED);
536538

539+
#if CONFIG_IPC_MAJOR_4
540+
struct sof_ipc_stream_params params;
541+
542+
/* set params based on base config for IPC4 */
543+
ret = kpb_params(dev, &params);
544+
if (ret < 0) {
545+
rfree(dev);
546+
return NULL;
547+
}
548+
#endif
549+
537550
return dev;
538551
}
539552

@@ -786,12 +799,21 @@ static int kpb_params(struct comp_dev *dev,
786799
static int kpb_prepare(struct comp_dev *dev)
787800
{
788801
struct comp_data *kpb = comp_get_drvdata(dev);
802+
struct sof_ipc_stream_params params;
789803
int ret = 0;
790804
int i;
791805
size_t hb_size_req = KPB_MAX_BUFFER_SIZE(kpb->config.sampling_width, kpb->config.channels);
792806

793807
comp_dbg(dev, "kpb_prepare()");
794808

809+
kpb_set_params(dev, &params);
810+
811+
ret = kbp_verify_params(dev, &params);
812+
if (ret < 0) {
813+
comp_err(dev, "kpb_prepare: pcm params verification failed");
814+
return -EINVAL;
815+
}
816+
795817
if (kpb->state == KPB_STATE_RESETTING ||
796818
kpb->state == KPB_STATE_RESET_FINISHING) {
797819
comp_cl_err(&comp_kpb, "can not prepare KPB due to ongoing reset, state log %x",

src/audio/module_adapter/module_adapter.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv,
123123

124124
dev->state = COMP_STATE_READY;
125125

126+
#if CONFIG_IPC_MAJOR_4
127+
struct sof_ipc_stream_params params = {{ 0 }};
128+
129+
/* set the stream params based on the module base cfg. It is OK to pass NULL params
130+
* here because it will be filled in based on the module base_cfg.
131+
*/
132+
ret = module_adapter_params(dev, &params);
133+
if (ret) {
134+
comp_err(dev, "module_adapter_new() %d: module params failed", ret);
135+
goto err;
136+
}
137+
#endif
138+
126139
comp_dbg(dev, "module_adapter_new() done");
127140
return dev;
128141
err:
@@ -180,6 +193,12 @@ int module_adapter_prepare(struct comp_dev *dev)
180193

181194
comp_dbg(dev, "module_adapter_prepare() start");
182195

196+
ret = comp_verify_params(dev, mod->verify_params_flags, mod->stream_params);
197+
if (ret < 0) {
198+
comp_err(dev, "module_adapter_prepare(): comp_verify_params() failed.");
199+
return ret;
200+
}
201+
183202
/* Prepare module */
184203
if (IS_PROCESSING_MODE_SINK_SOURCE(mod))
185204
ret = module_adapter_sink_src_prepare(dev);
@@ -1185,9 +1204,10 @@ int module_adapter_reset(struct comp_dev *dev)
11851204
buffer_zero(buffer);
11861205
}
11871206

1207+
#if CONFIG_IPC_MAJOR_3
11881208
rfree(mod->stream_params);
11891209
mod->stream_params = NULL;
1190-
1210+
#endif
11911211
comp_dbg(dev, "module_adapter_reset(): done");
11921212

11931213
return comp_set_state(dev, COMP_TRIGGER_RESET);
@@ -1219,6 +1239,7 @@ void module_adapter_free(struct comp_dev *dev)
12191239

12201240
#if CONFIG_IPC_MAJOR_4
12211241
rfree(mod->priv.cfg.input_pins);
1242+
rfree(mod->stream_params);
12221243
#endif
12231244

12241245
rfree(mod);

src/ipc/ipc4/handler.c

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -155,46 +155,6 @@ __cold static int ipc4_delete_pipeline(struct ipc4_message_request *ipc4)
155155
return ipc_pipeline_free(ipc, pipe->primary.r.instance_id);
156156
}
157157

158-
static int ipc4_comp_params(struct comp_dev *current,
159-
struct comp_buffer *calling_buf,
160-
struct pipeline_walk_context *ctx, int dir)
161-
{
162-
struct pipeline_data *ppl_data = ctx->comp_data;
163-
int err;
164-
165-
/* don't do any params if current is running */
166-
if (current->state == COMP_STATE_ACTIVE)
167-
return 0;
168-
169-
/* Stay on the current pipeline */
170-
if (current->pipeline != ((struct pipeline_data *)ctx->comp_data)->p)
171-
return 0;
172-
173-
err = comp_params(current, &ppl_data->params->params);
174-
if (err < 0 || err == PPL_STATUS_PATH_STOP)
175-
return err;
176-
177-
return pipeline_for_each_comp(current, ctx, dir);
178-
}
179-
180-
static int ipc4_pipeline_params(struct pipeline *p, struct comp_dev *host)
181-
{
182-
struct sof_ipc_pcm_params hw_params = {{ 0 }};
183-
struct pipeline_data data = {
184-
.start = host,
185-
.params = &hw_params,
186-
.p = p,
187-
};
188-
189-
struct pipeline_walk_context param_ctx = {
190-
.comp_func = ipc4_comp_params,
191-
.comp_data = &data,
192-
.skip_incomplete = true,
193-
};
194-
195-
return param_ctx.comp_func(host, NULL, &param_ctx, host->direction);
196-
}
197-
198158
static int ipc4_pcm_params(struct ipc_comp_dev *pcm_dev)
199159
{
200160
int err, reset_err;
@@ -205,15 +165,6 @@ static int ipc4_pcm_params(struct ipc_comp_dev *pcm_dev)
205165
return -EINVAL;
206166
}
207167

208-
/* configure pipeline audio params */
209-
err = ipc4_pipeline_params(pcm_dev->cd->pipeline, pcm_dev->cd);
210-
if (err < 0) {
211-
ipc_cmd_err(&ipc_tr, "ipc: pipe %d comp %d params failed %d",
212-
pcm_dev->cd->pipeline->pipeline_id,
213-
pcm_dev->cd->pipeline->comp_id, err);
214-
goto error;
215-
}
216-
217168
/* prepare pipeline audio params */
218169
err = pipeline_prepare(pcm_dev->cd->pipeline, pcm_dev->cd);
219170
if (err < 0) {

src/samples/audio/detect_test.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ static struct comp_dev *test_keyword_new(const struct comp_driver *drv,
749749
dev->direction = SOF_IPC_STREAM_CAPTURE;
750750
dev->direction_set = true;
751751
dev->state = COMP_STATE_READY;
752+
752753
return dev;
753754

754755
cd_fail:
@@ -926,6 +927,7 @@ static int test_keyword_reset(struct comp_dev *dev)
926927
static int test_keyword_prepare(struct comp_dev *dev)
927928
{
928929
struct comp_data *cd = comp_get_drvdata(dev);
930+
struct sof_ipc_stream_params params;
929931
uint16_t valid_bits = cd->sample_valid_bytes * 8;
930932
uint16_t sample_width;
931933
int ret;
@@ -938,6 +940,12 @@ static int test_keyword_prepare(struct comp_dev *dev)
938940

939941
comp_info(dev, "test_keyword_prepare()");
940942

943+
ret = test_keyword_params(dev, &params);
944+
if (ret < 0) {
945+
comp_err(dev, "test_keyword_prepare(): pcm params verification failed.");
946+
return ret;
947+
}
948+
941949
/*
942950
* FIXME: this condition is always "false" for IPC4 as audio format cannot be changed
943951
* without component re-creation. Does this "if" makes sense for IPC3?

0 commit comments

Comments
 (0)