[Sound-open-firmware] [PATCH v3 19/27] volume: add R/W pointer check for volume_copy()

Keyon Jie yang.jie at linux.intel.com
Sat Feb 11 03:17:59 CET 2017


We should only copy when there is data, as we are using pulling
mode, should sink side should have free space always, we check
source->avail only and copy only some bytes when avail < period
size.

Signed-off-by: Keyon Jie <yang.jie at linux.intel.com>
---
 src/audio/volume.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/audio/volume.c b/src/audio/volume.c
index ee49b3a..822c92d 100644
--- a/src/audio/volume.c
+++ b/src/audio/volume.c
@@ -473,6 +473,16 @@ static int volume_copy(struct comp_dev *dev)
 	trace_value((uint32_t)(sink->w_ptr - sink->addr));
 #endif
 
+	if (source->avail < cframes * source->params.frame_size ||
+			sink->free < cframes * sink->params.frame_size)
+		cframes = source->avail / source->params.frame_size;
+
+	/* no data to copy */
+	if (cframes == 0) {
+		trace_value(source->avail);
+		return 0;
+	}
+
 	/* copy and scale volume */
 	cd->scale_vol(dev, sink, source, cframes);
 
@@ -538,7 +548,7 @@ found:
 
 	/* copy periods from host */
 	if (source->params.direction == STREAM_DIRECTION_PLAYBACK) {
-		for (i = 0; i < PLAT_HOST_PERIODS; i++)
+		for (i = 0; i < PLAT_INT_PERIODS; i++)
 			volume_copy(dev);
 	}
 
-- 
2.7.4



More information about the Sound-open-firmware mailing list