From 87574da19ed7b81e3d7b8e24049622fb8b2c3c9e Mon Sep 17 00:00:00 2001 From: Karol Trzcinski Date: Thu, 9 Jul 2020 19:02:46 +0200 Subject: [PATCH] dma: Remove redundant sink/source bytes parameter from dma_buffer_copy* This value is strictly correlated with given samples number, passing sink/source bytes number as separate parameter may lead to data desynchronization. Temporary number of samples and sink_bytes is calculated in dma_buffer_copy_*() function, but it should be removed in future. 'process' should be modified to take only number of bytes to process from source stream and return number of output bytes in sink stream, to allow easily handling of compressed audio streams. Signed-off-by: Karol Trzcinski --- src/audio/dai.c | 15 ++++----------- src/audio/host.c | 13 ++++--------- src/include/sof/lib/dma.h | 10 ++++------ src/lib/dma.c | 18 ++++++++++++------ 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/audio/dai.c b/src/audio/dai.c index c909b54b8..fab6f3601 100644 --- a/src/audio/dai.c +++ b/src/audio/dai.c @@ -73,9 +73,6 @@ static void dai_dma_cb(void *arg, enum notify_id type, void *data) struct comp_dev *dev = arg; struct dai_data *dd = comp_get_drvdata(dev); uint32_t bytes = next->elem.size; - uint32_t sink_bytes; - uint32_t samples = bytes / - audio_stream_sample_bytes(&dd->dma_buffer->stream); void *buffer_ptr; comp_dbg(dev, "dai_dma_cb()"); @@ -101,18 +98,14 @@ static void dai_dma_cb(void *arg, enum notify_id type, void *data) return; } - sink_bytes = samples * - audio_stream_sample_bytes(&dd->local_buffer->stream); - if (dev->direction == SOF_IPC_STREAM_PLAYBACK) { - dma_buffer_copy_to(dd->local_buffer, sink_bytes, - dd->dma_buffer, bytes, - dd->process, samples); + dma_buffer_copy_to(dd->local_buffer, dd->dma_buffer, + dd->process, bytes); buffer_ptr = dd->local_buffer->stream.r_ptr; } else { - dma_buffer_copy_from(dd->dma_buffer, bytes, dd->local_buffer, - sink_bytes, dd->process, samples); + dma_buffer_copy_from(dd->dma_buffer, dd->local_buffer, + dd->process, bytes); buffer_ptr = dd->local_buffer->stream.w_ptr; } diff --git a/src/audio/host.c b/src/audio/host.c index aa3ebbac7..5d664e0cc 100644 --- a/src/audio/host.c +++ b/src/audio/host.c @@ -130,18 +130,13 @@ static uint32_t host_dma_get_split(struct host_data *hd, uint32_t bytes) static void host_update_position(struct comp_dev *dev, uint32_t bytes) { struct host_data *hd = comp_get_drvdata(dev); - uint32_t samples; - - samples = bytes / audio_stream_sample_bytes(&hd->local_buffer->stream); if (dev->direction == SOF_IPC_STREAM_PLAYBACK) - dma_buffer_copy_from(hd->dma_buffer, bytes, - hd->local_buffer, bytes, - hd->process, samples); + dma_buffer_copy_from(hd->dma_buffer, hd->local_buffer, + hd->process, bytes); else - dma_buffer_copy_to(hd->local_buffer, bytes, - hd->dma_buffer, bytes, - hd->process, samples); + dma_buffer_copy_to(hd->local_buffer, hd->dma_buffer, + hd->process, bytes); dev->position += bytes; diff --git a/src/include/sof/lib/dma.h b/src/include/sof/lib/dma.h index bf0b59575..ef5383498 100644 --- a/src/include/sof/lib/dma.h +++ b/src/include/sof/lib/dma.h @@ -607,14 +607,12 @@ typedef void (*dma_process)(const struct audio_stream *, struct audio_stream *, uint32_t); /* copies data from DMA buffer using provided processing function */ -void dma_buffer_copy_from(struct comp_buffer *source, uint32_t source_bytes, - struct comp_buffer *sink, uint32_t sink_bytes, - dma_process_func process, uint32_t samples); +void dma_buffer_copy_from(struct comp_buffer *source, struct comp_buffer *sink, + dma_process_func process, uint32_t source_bytes); /* copies data to DMA buffer using provided processing function */ -void dma_buffer_copy_to(struct comp_buffer *source, uint32_t source_bytes, - struct comp_buffer *sink, uint32_t sink_bytes, - dma_process_func process, uint32_t samples); +void dma_buffer_copy_to(struct comp_buffer *source, struct comp_buffer *sink, + dma_process_func process, uint32_t sink_bytes); /* generic DMA DSP <-> Host copier */ diff --git a/src/lib/dma.c b/src/lib/dma.c index fb7e76573..936484b45 100644 --- a/src/lib/dma.c +++ b/src/lib/dma.c @@ -189,11 +189,14 @@ void dma_sg_free(struct dma_sg_elem_array *elem_array) dma_sg_init(elem_array); } -void dma_buffer_copy_from(struct comp_buffer *source, uint32_t source_bytes, - struct comp_buffer *sink, uint32_t sink_bytes, - dma_process_func process, uint32_t samples) +void dma_buffer_copy_from(struct comp_buffer *source, struct comp_buffer *sink, + dma_process_func process, uint32_t source_bytes) { struct audio_stream *istream = &source->stream; + uint32_t samples = source_bytes / + audio_stream_sample_bytes(istream); + uint32_t sink_bytes = audio_stream_sample_bytes(&sink->stream) * + samples; /* source buffer contains data copied by DMA */ audio_stream_invalidate(istream, source_bytes); @@ -209,11 +212,14 @@ void dma_buffer_copy_from(struct comp_buffer *source, uint32_t source_bytes, comp_update_buffer_produce(sink, sink_bytes); } -void dma_buffer_copy_to(struct comp_buffer *source, uint32_t source_bytes, - struct comp_buffer *sink, uint32_t sink_bytes, - dma_process_func process, uint32_t samples) +void dma_buffer_copy_to(struct comp_buffer *source, struct comp_buffer *sink, + dma_process_func process, uint32_t sink_bytes) { struct audio_stream *ostream = &sink->stream; + uint32_t samples = sink_bytes / + audio_stream_sample_bytes(ostream); + uint32_t source_bytes = audio_stream_sample_bytes(&source->stream) * + samples; buffer_invalidate(source, source_bytes);