[Sound-open-firmware] [PATCH v3 1/3] comp: default function to set comp state
Ranjani Sridharan
ranjani.sridharan at linux.intel.com
Mon Sep 4 22:31:12 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 | 25 +++----------------------
src/audio/tone.c | 28 +++++-----------------------
src/audio/volume.c | 19 +++----------------
src/include/reef/audio/component.h | 3 +++
7 files changed, 57 insertions(+), 95 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..34cab7a 100644
--- a/src/audio/src.c
+++ b/src/audio/src.c
@@ -431,6 +431,7 @@ static int src_ctrl_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata)
static int src_cmd(struct comp_dev *dev, int cmd, void *data)
{
struct sof_ipc_ctrl_data *cdata = data;
+ int ret = 0;
trace_src("SCm");
@@ -438,35 +439,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..aec8a72 100644
--- a/src/audio/tone.c
+++ b/src/audio/tone.c
@@ -434,6 +434,8 @@ static int tone_ctrl_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata)
{
struct comp_data *cd = comp_get_drvdata(dev);
+ trace_tone("tri");
+
switch (cdata->cmd) {
case SOF_CTRL_CMD_MUTE:
trace_tone("TMu");
@@ -468,6 +470,7 @@ static int tone_ctrl_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata)
static int tone_cmd(struct comp_dev *dev, int cmd, void *data)
{
struct sof_ipc_ctrl_data *cdata = data;
+ int ret = 0;
trace_tone("tri");
@@ -475,36 +478,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..6fa36c4 100644
--- a/src/audio/volume.c
+++ b/src/audio/volume.c
@@ -429,6 +429,7 @@ static int volume_ctrl_cmd(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata
static int volume_cmd(struct comp_dev *dev, int cmd, void *data)
{
struct sof_ipc_ctrl_data *cdata = data;
+ int ret = 0;
trace_volume("cmd");
@@ -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