codec_adapter: Differentiate between consumed/produced bytes

With decoders, usually, consumed bytes is not equal
with produced bytes. We need to take this into account
in order to copy the entire produced bytes by the processing algorithm.

- consumed bytes -> number of bytes consumed from the input buffer.
- produced bytes -> number of bytes produced into the output buffer.

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
This commit is contained in:
Daniel Baluta 2021-03-02 17:35:07 +02:00 committed by Daniel Baluta
parent f305790e51
commit ed027d045b
3 changed files with 16 additions and 7 deletions

View File

@ -421,6 +421,13 @@ int cadence_codec_process(struct comp_dev *dev)
goto err;
}
API_CALL(cd, XA_API_CMD_GET_CURIDX_INPUT_BUF, 0, &codec->cpd.consumed, ret);
if (ret != LIB_NO_ERROR) {
comp_err(dev, "cadence_codec_process() error %x: could not get consumed bytes",
ret);
goto err;
}
comp_dbg(dev, "cadence_codec_process() done");
return 0;

View File

@ -364,7 +364,7 @@ static void generate_zeroes(struct comp_buffer *sink, uint32_t bytes)
static int codec_adapter_copy(struct comp_dev *dev)
{
int ret = 0;
uint32_t bytes_to_process, copy_bytes, processed = 0;
uint32_t bytes_to_process, copy_bytes, processed = 0, produced = 0;
struct comp_data *cd = comp_get_drvdata(dev);
struct codec_data *codec = &cd->codec;
struct comp_buffer *source = cd->ca_source;
@ -407,18 +407,19 @@ static int codec_adapter_copy(struct comp_dev *dev)
codec_adapter_copy_from_lib_to_sink(&codec->cpd, &local_buff->stream,
codec->cpd.produced);
bytes_to_process -= codec->cpd.produced;
processed += codec->cpd.produced;
bytes_to_process -= codec->cpd.consumed;
processed += codec->cpd.consumed;
produced += codec->cpd.produced;
}
if (!processed && !cd->deep_buff_bytes) {
if (!produced && !cd->deep_buff_bytes) {
comp_dbg(dev, "codec_adapter_copy(): nothing processed in this call");
goto end;
} else if (!processed && cd->deep_buff_bytes) {
} else if (!produced && cd->deep_buff_bytes) {
goto db_verify;
}
audio_stream_produce(&local_buff->stream, processed);
audio_stream_produce(&local_buff->stream, produced);
comp_update_buffer_consume(source, processed);
db_verify:

View File

@ -159,7 +159,8 @@ struct codec_processing_data {
uint32_t in_buff_size; /**< Specifies the size of codec input buffer. */
uint32_t out_buff_size; /**< Specifies the size of codec output buffer.*/
uint32_t avail; /**< Specifies how much data is available for codec to process.*/
uint32_t produced; /**< Specifies how much data the codec processed in its last task.*/
uint32_t produced; /**< Specifies how much data the codec produced in its last task.*/
uint32_t consumed; /**< Specified how much data the codec consumed in its last task */
void *in_buff; /**< A pointer to codec input buffer. */
void *out_buff; /**< A pointer to codec output buffer. */
};