Skip to content

Commit 6927781

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_bind when the intermediate buffers between modules are created. 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 6927781

5 files changed

Lines changed: 78 additions & 63 deletions

File tree

src/audio/kpb.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ static int kpb_get_attribute(struct comp_dev *dev,
330330
return 0;
331331
}
332332

333+
static int kbp_verify_params(struct comp_dev *dev,
334+
struct sof_ipc_stream_params *params);
335+
333336
/**
334337
* \brief Initialize KPB sinks when binding.
335338
* \param[in] dev - component device pointer.
@@ -339,6 +342,7 @@ static int kpb_get_attribute(struct comp_dev *dev,
339342
static int kpb_bind(struct comp_dev *dev, struct bind_info *bind_data)
340343
{
341344
struct comp_data *kpb = comp_get_drvdata(dev);
345+
struct sof_ipc_stream_params params;
342346
struct ipc4_module_bind_unbind *bu;
343347
int buf_id;
344348
int ret = 0;
@@ -356,6 +360,7 @@ static int kpb_bind(struct comp_dev *dev, struct bind_info *bind_data)
356360
*/
357361
struct comp_buffer *sink;
358362

363+
kpb_set_params(dev, &params);
359364
comp_dev_for_each_consumer(dev, sink) {
360365
int sink_buf_id;
361366

@@ -372,6 +377,10 @@ static int kpb_bind(struct comp_dev *dev, struct bind_info *bind_data)
372377
else
373378
kpb->host_sink = sink;
374379
}
380+
381+
/* set buffer params based on the basecfg */
382+
if (sink_buf_id != 0)
383+
buffer_set_params(sink, &params, BUFFER_UPDATE_FORCE);
375384
}
376385

377386
return ret;
@@ -453,6 +462,8 @@ static void kpb_set_params(struct comp_dev *dev,
453462
{}
454463
#endif /* CONFIG_IPC_MAJOR_4 */
455464

465+
static int kpb_params(struct comp_dev *dev, struct sof_ipc_stream_params *params);
466+
456467
/*
457468
* \brief Create a key phrase buffer component.
458469
* \param[in] config - generic ipc component pointer.
@@ -534,6 +545,17 @@ static struct comp_dev *kpb_new(const struct comp_driver *drv,
534545
dev->state = COMP_STATE_READY;
535546
kpb_change_state(kpb, KPB_STATE_CREATED);
536547

548+
#if CONFIG_IPC_MAJOR_4
549+
struct sof_ipc_stream_params params;
550+
551+
/* set params based on base config for IPC4 */
552+
ret = kpb_params(dev, &params);
553+
if (ret < 0) {
554+
rfree(dev);
555+
return NULL;
556+
}
557+
#endif
558+
537559
return dev;
538560
}
539561

src/audio/module_adapter/module_adapter.c

Lines changed: 16 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:
@@ -1185,9 +1198,10 @@ int module_adapter_reset(struct comp_dev *dev)
11851198
buffer_zero(buffer);
11861199
}
11871200

1201+
#if CONFIG_IPC_MAJOR_3
11881202
rfree(mod->stream_params);
11891203
mod->stream_params = NULL;
1190-
1204+
#endif
11911205
comp_dbg(dev, "module_adapter_reset(): done");
11921206

11931207
return comp_set_state(dev, COMP_TRIGGER_RESET);
@@ -1219,6 +1233,7 @@ void module_adapter_free(struct comp_dev *dev)
12191233

12201234
#if CONFIG_IPC_MAJOR_4
12211235
rfree(mod->priv.cfg.input_pins);
1236+
rfree(mod->stream_params);
12221237
#endif
12231238

12241239
rfree(mod);

src/audio/module_adapter/module_adapter_ipc4.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,12 @@ int module_adapter_bind(struct comp_dev *dev, struct bind_info *bind_data)
253253

254254
mod->stream_copy_single_to_single = !module_adapter_multi_sink_source_prepare(dev);
255255

256-
return 0;
256+
/* call comp_verify_params() to update the buffer params */
257+
ret = comp_verify_params(dev, mod->verify_params_flags, mod->stream_params);
258+
if (ret < 0)
259+
comp_err(dev, "module_adapter_bind(): comp_verify_params() failed.");
260+
261+
return ret;
257262
}
258263
EXPORT_SYMBOL(module_adapter_bind);
259264

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: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,25 @@ static struct ipc_msg *ipc4_kd_notification_init(uint32_t word_id,
481481
return msg;
482482
}
483483

484+
/**
485+
* \brief Set buffer params for source buffer
486+
* \param[in] dev - component device pointer.
487+
* \param[in] bind_data - bind/unbind data.
488+
* \return: none.
489+
*/
490+
static int test_keyword_bind(struct comp_dev *dev, struct bind_info *bind_data)
491+
{
492+
struct sof_ipc_stream_params params;
493+
struct comp_buffer *sourceb;
494+
495+
sourceb = comp_dev_get_first_data_producer(dev);
496+
497+
test_keyword_set_params(dev, &params);
498+
buffer_set_params(sourceb, &params, BUFFER_UPDATE_FORCE);
499+
500+
return 0;
501+
}
502+
484503
#else /* CONFIG_IPC_MAJOR_4 */
485504
static int test_keyword_set_config(struct comp_dev *dev,
486505
struct sof_ipc_ctrl_data *cdata)
@@ -650,6 +669,7 @@ static int test_keyword_cmd(struct comp_dev *dev, int cmd, void *data,
650669
}
651670
}
652671
#endif /* CONFIG_IPC_MAJOR_4 */
672+
static int test_keyword_params(struct comp_dev *dev, struct sof_ipc_stream_params *params);
653673

654674
static struct comp_dev *test_keyword_new(const struct comp_driver *drv,
655675
const struct comp_ipc_config *config,
@@ -749,6 +769,16 @@ static struct comp_dev *test_keyword_new(const struct comp_driver *drv,
749769
dev->direction = SOF_IPC_STREAM_CAPTURE;
750770
dev->direction_set = true;
751771
dev->state = COMP_STATE_READY;
772+
773+
#if CONFIG_IPC_MAJOR_4
774+
struct sof_ipc_stream_params params;
775+
776+
/* set params based on base config for IPC4 */
777+
ret = test_keyword_params(dev, &params);
778+
if (ret < 0)
779+
goto cd_fail;
780+
#endif
781+
752782
return dev;
753783

754784
cd_fail:
@@ -801,9 +831,6 @@ static int test_keyword_params(struct comp_dev *dev,
801831
struct sof_ipc_stream_params *params)
802832
{
803833
struct comp_data *cd = comp_get_drvdata(dev);
804-
struct comp_buffer *sourceb;
805-
unsigned int channels, rate;
806-
enum sof_ipc_frame frame_fmt;
807834
int err;
808835

809836
test_keyword_set_params(dev, params);
@@ -816,26 +843,20 @@ static int test_keyword_params(struct comp_dev *dev,
816843

817844
cd->sample_valid_bytes = params->sample_valid_bytes;
818845

819-
/* keyword components will only ever have 1 source */
820-
sourceb = comp_dev_get_first_data_producer(dev);
821-
channels = audio_stream_get_channels(&sourceb->stream);
822-
frame_fmt = audio_stream_get_frm_fmt(&sourceb->stream);
823-
rate = audio_stream_get_rate(&sourceb->stream);
824-
825-
if (channels != 1) {
846+
if (params->channels != 1) {
826847
comp_err(dev, "test_keyword_params(): only single-channel supported");
827848
return -EINVAL;
828849
}
829850

830-
if (!detector_is_sample_width_supported(frame_fmt)) {
851+
if (!detector_is_sample_width_supported(params->frame_fmt)) {
831852
comp_err(dev, "test_keyword_params(): only 16-bit format supported");
832853
return -EINVAL;
833854
}
834855

835856
/* calculate the length of the preamble */
836857
if (cd->config.preamble_time) {
837858
cd->keyphrase_samples = cd->config.preamble_time *
838-
(rate / 1000);
859+
(params->rate / 1000);
839860
} else {
840861
cd->keyphrase_samples = KEYPHRASE_DEFAULT_PREAMBLE_LENGTH;
841862
}
@@ -1073,6 +1094,7 @@ static const struct comp_driver comp_keyword = {
10731094
.set_large_config = test_keyword_set_large_config,
10741095
.get_large_config = test_keyword_get_large_config,
10751096
.get_attribute = test_keyword_get_attribute,
1097+
.bind = test_keyword_bind,
10761098
#else
10771099
.cmd = test_keyword_cmd,
10781100
#endif /* CONFIG_IPC_MAJOR_4 */

0 commit comments

Comments
 (0)