audio: codec_adapter: Make sure local_buff has enough room for processing

We need to make sure that the local buffer has enough room to hold
the output of the processing.

This means that for each type of decoding algorithm we need to know
the maximum possible output size and skip processing if local buffer
size is less than that.

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
This commit is contained in:
Daniel Baluta 2021-04-13 20:25:54 +03:00 committed by Liam Girdwood
parent dfb29d5227
commit ba6ba3cfc6
1 changed files with 15 additions and 0 deletions

View File

@ -359,6 +359,14 @@ static void generate_zeroes(struct comp_buffer *sink, uint32_t bytes)
comp_update_buffer_produce(sink, bytes); comp_update_buffer_produce(sink, bytes);
} }
static int get_output_bytes(struct comp_dev *dev)
{
struct comp_data *cd = comp_get_drvdata(dev);
return codec_get_samples(dev) * cd->stream_params.sample_container_bytes *
cd->stream_params.channels;
}
int codec_adapter_copy(struct comp_dev *dev) int codec_adapter_copy(struct comp_dev *dev)
{ {
int ret = 0; int ret = 0;
@ -404,6 +412,13 @@ int codec_adapter_copy(struct comp_dev *dev)
break; break;
} }
/* Process only we have enough free data in the local
* buffer. If we don't have enough free space process()
* will override the data in the local buffer
*/
if (local_buff->stream.free < get_output_bytes(dev))
goto db_verify;
buffer_invalidate(source, codec_buff_size); buffer_invalidate(source, codec_buff_size);
codec_adapter_copy_from_source_to_lib(&source->stream, &codec->cpd, codec_adapter_copy_from_source_to_lib(&source->stream, &codec->cpd,
codec_buff_size); codec_buff_size);