module_adapter: No need to calculate buffer sizes with simple_copy

When using simple_copy for components like volume, there is no need to
allocate intermediate sink buffers. So, move the check before the
calculation for sink buffers size.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
This commit is contained in:
Ranjani Sridharan 2022-07-07 14:15:04 -07:00 committed by Liam Girdwood
parent 419ee3e9ec
commit def800e421
1 changed files with 37 additions and 37 deletions

View File

@ -168,6 +168,43 @@ int module_adapter_prepare(struct comp_dev *dev)
mod->deep_buff_bytes = 0;
/* compute number of input buffers */
list_for_item(blist, &dev->bsource_list)
mod->num_input_buffers++;
/* compute number of output buffers */
list_for_item(blist, &dev->bsink_list)
mod->num_output_buffers++;
if (!mod->num_input_buffers || !mod->num_output_buffers) {
comp_err(dev, "module_adapter_prepare(): invalid number of source/sink buffers");
return -EINVAL;
}
/* allocate memory for input buffers */
mod->input_buffers = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
sizeof(*mod->input_buffers) * mod->num_input_buffers);
if (!mod->input_buffers) {
comp_err(dev, "module_adapter_prepare(): failed to allocate input buffers");
return -ENOMEM;
}
/* allocate memory for output buffers */
mod->output_buffers = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
sizeof(*mod->output_buffers) * mod->num_output_buffers);
if (!mod->output_buffers) {
comp_err(dev, "module_adapter_prepare(): failed to allocate output buffers");
ret = -ENOMEM;
goto in_free;
}
/*
* no need to allocate intermediate sink buffers if the module produces only period bytes
* every period and has only 1 input and 1 output buffer
*/
if (mod->simple_copy)
return 0;
/* Module is prepared, now we need to configure processing settings.
* If module internal buffer is not equal to natural multiple of pipeline
* buffer we have a situation where module adapter have to deep buffer certain amount
@ -213,43 +250,6 @@ int module_adapter_prepare(struct comp_dev *dev)
buff_size = MAX(mod->period_bytes, md->mpd.out_buff_size) * buff_periods;
mod->output_buffer_size = buff_size;
/* compute number of input buffers */
list_for_item(blist, &dev->bsource_list)
mod->num_input_buffers++;
/* compute number of output buffers */
list_for_item(blist, &dev->bsink_list)
mod->num_output_buffers++;
if (!mod->num_input_buffers || !mod->num_output_buffers) {
comp_err(dev, "module_adapter_prepare(): invalid number of source/sink buffers");
return -EINVAL;
}
/* allocate memory for input buffers */
mod->input_buffers = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
sizeof(*mod->input_buffers) * mod->num_input_buffers);
if (!mod->input_buffers) {
comp_err(dev, "module_adapter_prepare(): failed to allocate input buffers");
return -ENOMEM;
}
/* allocate memory for output buffers */
mod->output_buffers = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
sizeof(*mod->output_buffers) * mod->num_output_buffers);
if (!mod->output_buffers) {
comp_err(dev, "module_adapter_prepare(): failed to allocate output buffers");
ret = -ENOMEM;
goto in_free;
}
/*
* no need to allocate intermediate sink buffers if the module produces only period bytes
* every period and has only 1 input and 1 output buffer
*/
if (mod->simple_copy)
return 0;
/* allocate memory for input buffer data */
list_for_item(blist, &dev->bsource_list) {
size_t size = MAX(mod->deep_buff_bytes, mod->period_bytes);