From b020954c947af0ed219f6c000b88efbb57abd4fa Mon Sep 17 00:00:00 2001 From: Shengjiu Wang Date: Fri, 15 May 2020 15:51:43 +0800 Subject: MLK-24044: ASoC: fsl_easrc_m2m: Fix output length not accurate We need to accumulate the input data length for calculating the output length because there are data need to be prefilled in the beginning. If the fraction part beyond the integrity of sample is not considered in calculating, which may cause the output task timeout. Signed-off-by: Shengjiu Wang Reviewed-by: Viorel Suman --- sound/soc/fsl/fsl_easrc_m2m.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'sound/soc/fsl/fsl_easrc_m2m.c') diff --git a/sound/soc/fsl/fsl_easrc_m2m.c b/sound/soc/fsl/fsl_easrc_m2m.c index 7f068d8ad362..82d06afbecb7 100644 --- a/sound/soc/fsl/fsl_easrc_m2m.c +++ b/sound/soc/fsl/fsl_easrc_m2m.c @@ -10,6 +10,7 @@ struct fsl_easrc_m2m { unsigned int easrc_active; unsigned int first_convert; unsigned int sg_nodes[2]; + unsigned int in_filled_len; struct scatterlist sg[2][9]; struct dma_async_tx_descriptor *desc[2]; spinlock_t lock; /* protect mem resource */ @@ -181,17 +182,15 @@ static long fsl_easrc_calc_outbuf_len(struct fsl_easrc_m2m *m2m, in_width = snd_pcm_format_physical_width(ctx->in_params.sample_format) / 8; out_width = snd_pcm_format_physical_width(ctx->out_params.sample_format) / 8; - in_samples = pbuf->input_buffer_length / (in_width * channels); - out_samples = ctx->out_params.sample_rate * in_samples / - ctx->in_params.sample_rate; - out_length = out_samples * out_width * channels; - - if (out_samples <= ctx->out_missed_sample) { + m2m->in_filled_len += pbuf->input_buffer_length; + if (m2m->in_filled_len <= ctx->in_filled_sample * in_width * channels) { out_length = 0; - ctx->out_missed_sample -= out_samples; } else { - out_length -= ctx->out_missed_sample * out_width * channels; - ctx->out_missed_sample = 0; + in_samples = m2m->in_filled_len / (in_width * channels) - ctx->in_filled_sample; + out_samples = ctx->out_params.sample_rate * in_samples / + ctx->in_params.sample_rate; + out_length = out_samples * out_width * channels; + m2m->in_filled_len = ctx->in_filled_sample * in_width * channels; } return out_length; -- cgit v1.2.3