[Sound-open-firmware] [PATCH v2 25/26] component: host/volume/mixer: reset buffers for stop cmd

Keyon Jie yang.jie at linux.intel.com
Thu Feb 9 16:04:17 CET 2017


For command stop, excepting reset components, we may need reset
the buffer next to the component, otherwise, if the next start
command comes(without reset before it), the buffer pointers may
be disordered.

Signed-off-by: Keyon Jie <yang.jie at linux.intel.com>
---
 src/audio/host.c                   |  3 +++
 src/audio/mixer.c                  |  6 +++++-
 src/audio/volume.c                 |  4 +++-
 src/include/reef/audio/component.h | 27 +++++++++++++++++++++++++++
 4 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/audio/host.c b/src/audio/host.c
index 5c9f1ad..b818351 100644
--- a/src/audio/host.c
+++ b/src/audio/host.c
@@ -688,6 +688,9 @@ static int host_stop(struct comp_dev *dev)
 	local_elem->src = source_elem->src;
 	hd->next_inc = hd->period->size;
 
+	/* now reset downstream buffer */
+	comp_buffer_reset(dev);
+
 	dev->state = COMP_STATE_SETUP;
 	return 0;
 }
diff --git a/src/audio/mixer.c b/src/audio/mixer.c
index 754090f..c653fd9 100644
--- a/src/audio/mixer.c
+++ b/src/audio/mixer.c
@@ -184,7 +184,6 @@ static int mixer_cmd(struct comp_dev *dev, int cmd, void *data)
 	switch(cmd) {
 	case COMP_CMD_START:
 		trace_mixer("MSa");
-	case COMP_CMD_STOP:
 	case COMP_CMD_PAUSE:
 	case COMP_CMD_RELEASE:
 	case COMP_CMD_DRAIN:
@@ -192,6 +191,11 @@ static int mixer_cmd(struct comp_dev *dev, int cmd, void *data)
 	case COMP_CMD_RESUME:
 		finish = mixer_status_change(dev);
 		break;
+	case COMP_CMD_STOP:
+		finish = mixer_status_change(dev);
+		if (finish == 0)
+			comp_buffer_reset(dev);
+		break;
 	case COMP_CMD_VOLUME:
 		vol_dev = mixer_volume_component(dev);
 		if (vol_dev != NULL)
diff --git a/src/audio/volume.c b/src/audio/volume.c
index 822c92d..f347847 100644
--- a/src/audio/volume.c
+++ b/src/audio/volume.c
@@ -431,8 +431,10 @@ static int volume_cmd(struct comp_dev *dev, int cmd, void *data)
 	case COMP_CMD_STOP:
 		if (dev->state == COMP_STATE_RUNNING ||
 		    dev->state == COMP_STATE_DRAINING ||
-		    dev->state == COMP_STATE_PAUSED)
+		    dev->state == COMP_STATE_PAUSED) {
+			comp_buffer_reset(dev);
 			dev->state = COMP_STATE_SETUP;
+		}
 		break;
 	case COMP_CMD_PAUSE:
 		/* only support pausing for running */
diff --git a/src/include/reef/audio/component.h b/src/include/reef/audio/component.h
index 9275abd..3abae3d 100644
--- a/src/include/reef/audio/component.h
+++ b/src/include/reef/audio/component.h
@@ -39,6 +39,7 @@
 #include <reef/reef.h>
 #include <reef/dma.h>
 #include <reef/stream.h>
+#include <reef/alloc.h>
 
 /* audio component states
  * the states may transform as below:
@@ -310,6 +311,32 @@ static inline int comp_dai_loopback(struct comp_dev *dev,
 	return 0;
 }
 
+/* reset component downstream buffers  */
+static inline int comp_buffer_reset(struct comp_dev *dev)
+{
+	struct list_item *clist;
+
+	/* reset downstream buffers */
+	list_for_item(clist, &dev->bsink_list) {
+		struct comp_buffer *buffer;
+
+		buffer = container_of(clist, struct comp_buffer, source_list);
+
+		/* dont reset buffer if the component is not connected */
+		if (!buffer->connected)
+			continue;
+
+		/* reset buffer next to the component*/
+		bzero(buffer->addr, buffer->desc.size);
+		buffer->w_ptr = buffer->r_ptr = buffer->addr;
+		buffer->end_addr = buffer->addr + buffer->desc.size;
+		buffer->free = buffer->desc.size;
+		buffer->avail = 0;
+	}
+
+	return 0;
+}
+
 /* default base component initialisations */
 void sys_comp_dai_init(void);
 void sys_comp_host_init(void);
-- 
2.7.4



More information about the Sound-open-firmware mailing list