[Sound-open-firmware] [PATCH] comps: make sure correct state transitions are used and verified.
Use the correct component states and verify this at runtime.
Signed-off-by: Liam Girdwood liam.r.girdwood@linux.intel.com --- src/audio/component.c | 18 ++++++++++++++---- src/audio/host.c | 10 ++++------ src/audio/mixer.c | 6 ++++-- src/audio/volume.c | 3 ++- 4 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/src/audio/component.c b/src/audio/component.c index fd0d65e..1cf4799 100644 --- a/src/audio/component.c +++ b/src/audio/component.c @@ -122,13 +122,23 @@ int comp_set_state(struct comp_dev *dev, int cmd)
switch (cmd) { case COMP_CMD_START: + if (dev->state == COMP_STATE_PREPARE) { + dev->state = COMP_STATE_ACTIVE; + } else { + trace_comp_error("CES"); + ret = -EINVAL; + } + break; case COMP_CMD_RELEASE: - dev->state = COMP_STATE_ACTIVE; + if (dev->state == COMP_STATE_PAUSED) { + dev->state = COMP_STATE_ACTIVE; + } else { + trace_comp_error("CEr"); + ret = -EINVAL; + } break; case COMP_CMD_STOP: - if (dev->state == COMP_STATE_ACTIVE || - dev->state == COMP_STATE_PAUSED) { - comp_buffer_reset(dev); + if (dev->state == COMP_STATE_ACTIVE) { dev->state = COMP_STATE_READY; } else { trace_comp_error("CEs"); diff --git a/src/audio/host.c b/src/audio/host.c index 36e4c29..8aa29ad 100644 --- a/src/audio/host.c +++ b/src/audio/host.c @@ -527,7 +527,7 @@ static int host_stop(struct comp_dev *dev) /* now reset downstream buffer */ comp_buffer_reset(dev);
- dev->state = COMP_STATE_READY; + dev->state = COMP_STATE_PAUSED; return 0; }
@@ -549,18 +549,16 @@ static int host_cmd(struct comp_dev *dev, int cmd, void *data)
trace_host("cmd");
- // TODO: align cmd macros. switch (cmd) { + case COMP_CMD_PAUSE: case COMP_CMD_STOP: - if (dev->state == COMP_STATE_ACTIVE || - dev->state == COMP_STATE_PAUSED) + if (dev->state == COMP_STATE_ACTIVE) ret = host_stop(dev); 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); @@ -616,7 +614,7 @@ static int host_reset(struct comp_dev *dev) hd->host_pos = NULL; hd->source = NULL; hd->sink = NULL; - dev->state = COMP_STATE_INIT; + dev->state = COMP_STATE_READY;
return 0; } diff --git a/src/audio/mixer.c b/src/audio/mixer.c index 30ac8cc..85aa601 100644 --- a/src/audio/mixer.c +++ b/src/audio/mixer.c @@ -99,7 +99,7 @@ static struct comp_dev *mixer_new(struct sof_ipc_comp *comp) }
comp_set_drvdata(dev, md); - + dev->state = COMP_STATE_READY; return dev; }
@@ -274,7 +274,7 @@ static int mixer_reset(struct comp_dev *dev) return 1; /* should not reset the downstream components */ }
- dev->state = COMP_STATE_INIT; + dev->state = COMP_STATE_READY; return 0; }
@@ -312,6 +312,8 @@ static int mixer_prepare(struct comp_dev *dev) } }
+ dev->state = COMP_STATE_PREPARE; + /* prepare downstream */ return downstream; } diff --git a/src/audio/volume.c b/src/audio/volume.c index 13cba42..45bbe27 100644 --- a/src/audio/volume.c +++ b/src/audio/volume.c @@ -332,6 +332,7 @@ static struct comp_dev *volume_new(struct sof_ipc_comp *comp) cd->tvolume[i] = VOL_MAX; }
+ dev->state = COMP_STATE_READY; return dev; }
@@ -649,7 +650,7 @@ static int volume_reset(struct comp_dev *dev) { trace_volume("res");
- dev->state = COMP_STATE_INIT; + dev->state = COMP_STATE_READY; return 0; }
participants (1)
-
Liam Girdwood