Skip to content

Commit 86cbc3b

Browse files
ranj063kv2019i
authored andcommitted
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 reduce 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 7b01a21 commit 86cbc3b

File tree

4 files changed

+102
-73
lines changed

4 files changed

+102
-73
lines changed

src/audio/kpb.c

Lines changed: 23 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+
/* retrieve params from the 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

@@ -784,12 +797,22 @@ static int kpb_params(struct comp_dev *dev,
784797
static int kpb_prepare(struct comp_dev *dev)
785798
{
786799
struct comp_data *kpb = comp_get_drvdata(dev);
800+
struct sof_ipc_stream_params params;
787801
int ret = 0;
788802
int i;
789803
size_t hb_size_req = KPB_MAX_BUFFER_SIZE(kpb->config.sampling_width, kpb->config.channels);
790804

791805
comp_dbg(dev, "kpb_prepare()");
792806

807+
/* retrieve the params from the base_cfg and update the source/sink buffer params */
808+
kpb_set_params(dev, &params);
809+
810+
ret = kpb_verify_params(dev, &params);
811+
if (ret < 0) {
812+
comp_err(dev, "pcm params verification failed");
813+
return -EINVAL;
814+
}
815+
793816
if (kpb->state == KPB_STATE_RESETTING ||
794817
kpb->state == KPB_STATE_RESET_FINISHING) {
795818
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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
143143

144144
dev->state = COMP_STATE_READY;
145145

146+
#if CONFIG_IPC_MAJOR_4
147+
struct sof_ipc_stream_params params;
148+
149+
/*
150+
* retrieve the stream params based on the module base cfg. There's no need to initialize
151+
* params here because it will be filled in based on the module base_cfg.
152+
*/
153+
ret = module_adapter_params(dev, &params);
154+
if (ret) {
155+
comp_err(dev, "module_adapter_new() %d: module params failed", ret);
156+
goto err;
157+
}
158+
#endif
159+
146160
comp_dbg(dev, "module_adapter_new() done");
147161
return dev;
148162
err:
@@ -199,7 +213,28 @@ int module_adapter_prepare(struct comp_dev *dev)
199213
int i = 0;
200214

201215
comp_dbg(dev, "module_adapter_prepare() start");
216+
#if CONFIG_IPC_MAJOR_4
217+
/*
218+
* if the stream_params are valid, just update the sink/source buffer params. If not,
219+
* retrieve the params from the basecfg, allocate stream_params and then update the
220+
* sink/source buffer params.
221+
*/
222+
if (!mod->stream_params) {
223+
struct sof_ipc_stream_params params;
202224

225+
ret = module_adapter_params(dev, &params);
226+
if (ret) {
227+
comp_err(dev, "module_adapter_new() %d: module params failed", ret);
228+
return ret;
229+
}
230+
} else {
231+
ret = comp_verify_params(dev, mod->verify_params_flags, mod->stream_params);
232+
if (ret < 0) {
233+
comp_err(dev, "module_adapter_params(): comp_verify_params() failed.");
234+
return ret;
235+
}
236+
}
237+
#endif
203238
/* Prepare module */
204239
if (IS_PROCESSING_MODE_SINK_SOURCE(mod))
205240
ret = module_adapter_sink_src_prepare(dev);

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: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ static int test_keyword_cmd(struct comp_dev *dev, int cmd, void *data,
650650
}
651651
}
652652
#endif /* CONFIG_IPC_MAJOR_4 */
653+
static int test_keyword_params(struct comp_dev *dev, struct sof_ipc_stream_params *params);
653654

654655
static struct comp_dev *test_keyword_new(const struct comp_driver *drv,
655656
const struct comp_ipc_config *config,
@@ -749,6 +750,16 @@ static struct comp_dev *test_keyword_new(const struct comp_driver *drv,
749750
dev->direction = SOF_IPC_STREAM_CAPTURE;
750751
dev->direction_set = true;
751752
dev->state = COMP_STATE_READY;
753+
754+
#if CONFIG_IPC_MAJOR_4
755+
struct sof_ipc_stream_params params;
756+
757+
/* retrieve params based on base config for IPC4 */
758+
ret = test_keyword_params(dev, &params);
759+
if (ret < 0)
760+
goto cd_fail;
761+
#endif
762+
752763
return dev;
753764

754765
cd_fail:
@@ -816,30 +827,6 @@ static int test_keyword_params(struct comp_dev *dev,
816827

817828
cd->sample_valid_bytes = params->sample_valid_bytes;
818829

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) {
826-
comp_err(dev, "test_keyword_params(): only single-channel supported");
827-
return -EINVAL;
828-
}
829-
830-
if (!detector_is_sample_width_supported(frame_fmt)) {
831-
comp_err(dev, "test_keyword_params(): only 16-bit format supported");
832-
return -EINVAL;
833-
}
834-
835-
/* calculate the length of the preamble */
836-
if (cd->config.preamble_time) {
837-
cd->keyphrase_samples = cd->config.preamble_time *
838-
(rate / 1000);
839-
} else {
840-
cd->keyphrase_samples = KEYPHRASE_DEFAULT_PREAMBLE_LENGTH;
841-
}
842-
843830
/*
844831
* Threshold might be already set via IPC4_DETECT_TEST_SET_CONFIG,
845832
* otherwise apply default value.
@@ -855,6 +842,32 @@ static int test_keyword_params(struct comp_dev *dev,
855842
cd->config.activation_threshold = err;
856843
}
857844

845+
/* keyword components will only ever have 1 source */
846+
sourceb = comp_dev_get_first_data_producer(dev);
847+
if (sourceb) {
848+
channels = audio_stream_get_channels(&sourceb->stream);
849+
frame_fmt = audio_stream_get_frm_fmt(&sourceb->stream);
850+
rate = audio_stream_get_rate(&sourceb->stream);
851+
852+
if (channels != 1) {
853+
comp_err(dev, "test_keyword_params(): only single-channel supported");
854+
return -EINVAL;
855+
}
856+
857+
if (!detector_is_sample_width_supported(frame_fmt)) {
858+
comp_err(dev, "test_keyword_params(): only 16-bit format supported");
859+
return -EINVAL;
860+
}
861+
862+
/* calculate the length of the preamble */
863+
if (cd->config.preamble_time) {
864+
cd->keyphrase_samples = cd->config.preamble_time *
865+
(rate / 1000);
866+
} else {
867+
cd->keyphrase_samples = KEYPHRASE_DEFAULT_PREAMBLE_LENGTH;
868+
}
869+
}
870+
858871
#if CONFIG_AMS
859872
cd->kpd_uuid_id = AMS_INVALID_MSG_TYPE;
860873
#endif /* CONFIG_AMS */
@@ -926,6 +939,7 @@ static int test_keyword_reset(struct comp_dev *dev)
926939
static int test_keyword_prepare(struct comp_dev *dev)
927940
{
928941
struct comp_data *cd = comp_get_drvdata(dev);
942+
struct sof_ipc_stream_params params;
929943
uint16_t valid_bits = cd->sample_valid_bytes * 8;
930944
uint16_t sample_width;
931945
int ret;
@@ -938,6 +952,12 @@ static int test_keyword_prepare(struct comp_dev *dev)
938952

939953
comp_info(dev, "test_keyword_prepare()");
940954

955+
ret = test_keyword_params(dev, &params);
956+
if (ret < 0) {
957+
comp_err(dev, "test_keyword_prepare(): params config failed.");
958+
return ret;
959+
}
960+
941961
/*
942962
* FIXME: this condition is always "false" for IPC4 as audio format cannot be changed
943963
* without component re-creation. Does this "if" makes sense for IPC3?

0 commit comments

Comments
 (0)