[Sound-open-firmware] [PATCH v2 1/3] comp: default function to set comp state

Ranjani Sridharan ranjani.sridharan at linux.intel.com
Mon Sep 4 22:00:34 CEST 2017


This patch adds a the comp_set_state() used for
the mandatory pipeline commands, START, STOP, PAUSE and RELEASE. It also
updates the cmd method in existing components to use comp_set_state().

Signed-off-by: Ranjani Sridharan <ranjani.sridharan at linux.intel.com>
---
 src/audio/component.c              | 38 ++++++++++++++++++++++++++++++++++++++
 src/audio/eq_fir.c                 | 23 +----------------------
 src/audio/host.c                   | 16 ++++------------
 src/audio/src.c                    | 26 +++-----------------------
 src/audio/tone.c                   | 29 ++++++-----------------------
 src/audio/volume.c                 | 21 ++++-----------------
 src/include/reef/audio/component.h |  3 +++
 7 files changed, 59 insertions(+), 97 deletions(-)

diff --git a/src/audio/component.c b/src/audio/component.c
index 6369e2e..232ef02 100644
--- a/src/audio/component.c
+++ b/src/audio/component.c
@@ -117,6 +117,44 @@ void comp_unregister(struct comp_driver *drv)
 	spin_unlock(&cd->lock);
 }
 
+int comp_set_state(struct comp_dev *dev, int cmd)
+{
+	int ret = 0;
+
+	switch (cmd) {
+	case COMP_CMD_START:
+	case COMP_CMD_RELEASE:
+		dev->state = COMP_STATE_RUNNING;
+		break;
+	case COMP_CMD_STOP:
+		if (dev->state == COMP_STATE_RUNNING ||
+		dev->state == COMP_STATE_DRAINING ||
+		dev->state == COMP_STATE_PAUSED) {
+			comp_buffer_reset(dev);
+			dev->state = COMP_STATE_SETUP;
+		} else {
+			trace_comp_error("CEs");
+			ret = -EINVAL;
+		}
+		break;
+	case COMP_CMD_PAUSE:
+		/* only support pausing for running */
+		if (dev->state == COMP_STATE_RUNNING)
+			dev->state = COMP_STATE_PAUSED;
+		else {
+			trace_comp_error("CEp");
+			ret = -EINVAL;
+		}
+		break;
+	default:
+		trace_comp_error("CEd");
+		ret = -EINVAL;
+		break;
+	}
+
+	return ret;
+}
+
 void sys_comp_init(void)
 {
 	cd = rzalloc(RZONE_SYS, RFLAGS_NONE, sizeof(*cd));
diff --git a/src/audio/eq_fir.c b/src/audio/eq_fir.c
index 540c68f..98cd43e 100644
--- a/src/audio/eq_fir.c
+++ b/src/audio/eq_fir.c
@@ -382,32 +382,11 @@ static int eq_fir_cmd(struct comp_dev *dev, int cmd, void *data)
 		ret = fir_cmd(dev, cdata);
 		break;
 	case COMP_CMD_START:
-		trace_src("EFs");
-		dev->state = COMP_STATE_RUNNING;
-		break;
 	case COMP_CMD_STOP:
-		trace_src("ESp");
-		if (dev->state == COMP_STATE_RUNNING ||
-			dev->state == COMP_STATE_DRAINING ||
-			dev->state == COMP_STATE_PAUSED) {
-			comp_buffer_reset(dev);
-			dev->state = COMP_STATE_SETUP;
-		}
-		break;
 	case COMP_CMD_PAUSE:
-		trace_src("EPe");
-		/* only support pausing for running */
-		if (dev->state == COMP_STATE_RUNNING)
-			dev->state = COMP_STATE_PAUSED;
-
-		break;
 	case COMP_CMD_RELEASE:
-		trace_src("ERl");
-		dev->state = COMP_STATE_RUNNING;
-		break;
 	default:
-		trace_src("EDf");
-		ret = -EINVAL;
+		ret = comp_set_state(dev, cmd);
 		break;
 	}
 
diff --git a/src/audio/host.c b/src/audio/host.c
index e71e95f..f81fd66 100644
--- a/src/audio/host.c
+++ b/src/audio/host.c
@@ -553,28 +553,20 @@ static int host_cmd(struct comp_dev *dev, int cmd, void *data)
 
 	// TODO: align cmd macros.
 	switch (cmd) {
-	case COMP_CMD_PAUSE:
-		/* only support pausing for running, channel is paused by DAI */
-		if (dev->state == COMP_STATE_RUNNING)
-			dev->state = COMP_STATE_PAUSED;
-		break;
 	case COMP_CMD_STOP:
 		if (dev->state == COMP_STATE_RUNNING ||
 			dev->state == COMP_STATE_DRAINING ||
 			dev->state == COMP_STATE_PAUSED)
 			ret = host_stop(dev);
 		break;
-	case COMP_CMD_RELEASE:
-		/* channel is released by DAI */
-		dev->state = COMP_STATE_RUNNING;
-		break;
-	case COMP_CMD_START:
-		dev->state = COMP_STATE_RUNNING;
-		break;
 	case COMP_CMD_SUSPEND:
 	case COMP_CMD_RESUME:
 		break;
+	case COMP_CMD_START:
+	case COMP_CMD_PAUSE:
+	case COMP_CMD_RELEASE:
 	default:
+		ret = comp_set_state(dev, cmd);
 		break;
 	}
 
diff --git a/src/audio/src.c b/src/audio/src.c
index c11ef3f..056822f 100644
--- a/src/audio/src.c
+++ b/src/audio/src.c
@@ -404,7 +404,7 @@ static int src_params(struct comp_dev *dev)
 static int src_ctrl_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata)
 {
 	struct comp_data *cd = comp_get_drvdata(dev);
-	int i;
+	int i, ret = 0;
 
 	switch (cdata->cmd) {
 	case SOF_CTRL_CMD_MUTE:
@@ -438,35 +438,15 @@ static int src_cmd(struct comp_dev *dev, int cmd, void *data)
 	case COMP_CMD_SET_VALUE:
 		return src_ctrl_cmd(dev, cdata);
 	case COMP_CMD_START:
-		trace_src("SSt");
-		dev->state = COMP_STATE_RUNNING;
-		break;
 	case COMP_CMD_STOP:
-		trace_src("SSp");
-		if (dev->state == COMP_STATE_RUNNING ||
-			dev->state == COMP_STATE_DRAINING ||
-			dev->state == COMP_STATE_PAUSED) {
-			comp_buffer_reset(dev);
-			dev->state = COMP_STATE_SETUP;
-		}
-		break;
 	case COMP_CMD_PAUSE:
-		trace_src("SPe");
-		/* only support pausing for running */
-		if (dev->state == COMP_STATE_RUNNING)
-			dev->state = COMP_STATE_PAUSED;
-
-		break;
 	case COMP_CMD_RELEASE:
-		trace_src("SRl");
-		dev->state = COMP_STATE_RUNNING;
-		break;
 	default:
-		trace_src("SDf");
+		ret = comp_set_state(dev, cmd);
 		break;
 	}
 
-	return 0;
+	return ret;
 }
 
 /* copy and process stream data from source to sink buffers */
diff --git a/src/audio/tone.c b/src/audio/tone.c
index 448c472..5d844b2 100644
--- a/src/audio/tone.c
+++ b/src/audio/tone.c
@@ -433,6 +433,10 @@ static int tone_params(struct comp_dev *dev)
 static int tone_ctrl_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata)
 {
 	struct comp_data *cd = comp_get_drvdata(dev);
+	struct sof_ipc_comp_tone *ct;
+	int ret = 0;
+
+	trace_tone("tri");
 
 	switch (cdata->cmd) {
 	case SOF_CTRL_CMD_MUTE:
@@ -475,36 +479,15 @@ static int tone_cmd(struct comp_dev *dev, int cmd, void *data)
 	case COMP_CMD_SET_VALUE:
 		return tone_ctrl_cmd(dev, cdata);
 	case COMP_CMD_START:
-		trace_tone("TSt");
-		dev->state = COMP_STATE_RUNNING;
-		break;
 	case COMP_CMD_STOP:
-		trace_tone("TSp");
-		if (dev->state == COMP_STATE_RUNNING ||
-			dev->state == COMP_STATE_DRAINING ||
-			dev->state == COMP_STATE_PAUSED) {
-			comp_buffer_reset(dev);
-			dev->state = COMP_STATE_SETUP;
-		}
-		break;
 	case COMP_CMD_PAUSE:
-		trace_tone("TPe");
-		/* only support pausing for running */
-		if (dev->state == COMP_STATE_RUNNING)
-			dev->state = COMP_STATE_PAUSED;
-
-		break;
 	case COMP_CMD_RELEASE:
-		trace_tone("TRl");
-		dev->state = COMP_STATE_RUNNING;
-		break;
 	default:
-		trace_tone("TDf");
-
+		ret = comp_set_state(dev, cmd);
 		break;
 	}
 
-	return 0;
+	return ret;
 }
 
 /* copy and process stream data from source to sink buffers */
diff --git a/src/audio/volume.c b/src/audio/volume.c
index 6cbd6ff..cde117c 100644
--- a/src/audio/volume.c
+++ b/src/audio/volume.c
@@ -383,7 +383,8 @@ static inline void volume_set_chan_unmute(struct comp_dev *dev, int chan)
 static int volume_ctrl_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata)
 {
 	struct comp_data *cd = comp_get_drvdata(dev);
-	int i, j;
+	struct sof_ipc_ctrl_values *cv;
+	int i, j, ret = 0;
 
 	switch (cdata->cmd) {
 	case SOF_CTRL_CMD_VOLUME:
@@ -436,29 +437,15 @@ static int volume_cmd(struct comp_dev *dev, int cmd, void *data)
 	case COMP_CMD_SET_VALUE:
 		return volume_ctrl_cmd(dev, cdata);
 	case COMP_CMD_START:
-		dev->state = COMP_STATE_RUNNING;
-		break;
 	case COMP_CMD_STOP:
-		if (dev->state == COMP_STATE_RUNNING ||
-		    dev->state == COMP_STATE_DRAINING ||
-		    dev->state == COMP_STATE_PAUSED) {
-			comp_buffer_reset(dev);
-			dev->state = COMP_STATE_SETUP;
-		}
-		break;
 	case COMP_CMD_PAUSE:
-		/* only support pausing for running */
-		if (dev->state == COMP_STATE_RUNNING)
-			dev->state = COMP_STATE_PAUSED;
-		break;
 	case COMP_CMD_RELEASE:
-		dev->state = COMP_STATE_RUNNING;
-		break;
 	default:
+		ret = comp_set_state(dev, cmd);
 		break;
 	}
 
-	return 0;
+	return ret;
 }
 
 /* copy and process stream data from source to sink buffers */
diff --git a/src/include/reef/audio/component.h b/src/include/reef/audio/component.h
index 35c80de..e20ffed 100644
--- a/src/include/reef/audio/component.h
+++ b/src/include/reef/audio/component.h
@@ -214,6 +214,9 @@ static inline void comp_free(struct comp_dev *dev)
 	dev->drv->ops.free(dev);
 }
 
+/* component state set */
+int comp_set_state(struct comp_dev *dev, int cmd);
+
 /* component parameter init - mandatory */
 static inline int comp_params(struct comp_dev *dev)
 {
-- 
2.9.3



More information about the Sound-open-firmware mailing list