Skip to content

Commit

Permalink
component: pipeline: Refactor direction testing in pipeline propagation
Browse files Browse the repository at this point in the history
Clean up some cut/paste code that had spread around, replacing it with
a simpler "comp_same_dir()" predicate.  No behavioral changes, just
refactoring.

Also remove the big comment that was repeated in triplicate.  It
explained this as error handling (i.e. it must be broken topology from
which we want to recover), but in fact cross-pipeline widget
connections in modern SOF do run in opposite directions (c.f. echo
cancellation, which need to look at the output stream to process
microphone input, or smart amp devices that do the reverse).

So just explain it as policy: we don't propagate across
opposite-direction pipelines, period.  Usages that need them need to
manage their pipeline lifecycles manually.

Signed-off-by: Andy Ross <andyross@google.com>
  • Loading branch information
andyross authored and kv2019i committed Dec 15, 2023
1 parent 68c6357 commit 7e5d40a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 63 deletions.
26 changes: 5 additions & 21 deletions src/audio/pipeline/pipeline-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ static int pipeline_comp_reset(struct comp_dev *current,
{
struct pipeline *p = ctx->comp_data;
struct pipeline *p_current = current->pipeline;
int end_type;
int is_single_ppl = comp_is_single_pipeline(current, p->source_comp);
int is_same_sched = pipeline_is_same_sched_comp(p_current, p);
int err;
Expand All @@ -339,26 +338,11 @@ static int pipeline_comp_reset(struct comp_dev *current,
if (!is_single_ppl && IPC4_MOD_ID(current->ipc_config.id))
return 0;

if (!is_single_ppl && !is_same_sched) {
/* If pipeline connected to the starting one is in improper
* direction (CAPTURE towards DAI, PLAYBACK towards HOST),
* stop propagation. Direction param of the pipeline can not be
* trusted at this point, as it might not be configured yet,
* hence checking for endpoint component type.
*/
end_type = comp_get_endpoint_type(p_current->sink_comp);
switch (dir) {
case SOF_IPC_STREAM_PLAYBACK:
if (end_type == COMP_ENDPOINT_HOST ||
end_type == COMP_ENDPOINT_NODE)
return 0;
break;
case SOF_IPC_STREAM_CAPTURE:
if (end_type == COMP_ENDPOINT_DAI ||
end_type == COMP_ENDPOINT_NODE)
return 0;
}
}
/* Propagate reset across pipelines only in the same direction
* and with the same scheduling behavior
*/
if (!is_single_ppl && !is_same_sched && !comp_same_dir(current, dir))
return 0;

/* two cases for a component still being active here:
* 1. trigger function failed to handle stop event
Expand Down
49 changes: 7 additions & 42 deletions src/audio/pipeline/pipeline-params.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,15 @@ static int pipeline_comp_params(struct comp_dev *current,
.skip_incomplete = true,
};
int stream_direction = ppl_data->params->params.direction;
int end_type;
int err;

pipe_dbg(current->pipeline, "pipeline_comp_params(), current->comp.id = %u, dir = %u",
dev_comp_id(current), dir);

if (!comp_is_single_pipeline(current, ppl_data->start)) {
/* If pipeline connected to the starting one is in improper
* direction (CAPTURE towards DAI, PLAYBACK towards HOST),
* stop propagation of parameters not to override their config.
* Direction param of the pipeline can not be trusted at this
* point, as it might not be configured yet, hence checking
* for endpoint component type.
*/
end_type = comp_get_endpoint_type(current->pipeline->sink_comp);
if (stream_direction == SOF_IPC_STREAM_PLAYBACK) {
if (end_type == COMP_ENDPOINT_HOST ||
end_type == COMP_ENDPOINT_NODE)
return 0;
}

if (stream_direction == SOF_IPC_STREAM_CAPTURE) {
if (end_type == COMP_ENDPOINT_DAI ||
end_type == COMP_ENDPOINT_NODE)
return 0;
}
}
/* Don't propagate to pipelines in the opposite direction */
if (!comp_is_single_pipeline(current, ppl_data->start) &&
!comp_same_dir(current, stream_direction))
return 0;

/* don't do any params if current is running */
if (current->state == COMP_STATE_ACTIVE)
Expand Down Expand Up @@ -279,8 +261,6 @@ static int pipeline_comp_prepare(struct comp_dev *current,
struct pipeline_walk_context *ctx, int dir)
{
struct pipeline_data *ppl_data = ctx->comp_data;
int stream_direction = dir;
int end_type;
int err;

pipe_dbg(current->pipeline, "pipeline_comp_prepare(), current->comp.id = %u, dir = %u",
Expand All @@ -291,24 +271,9 @@ static int pipeline_comp_prepare(struct comp_dev *current,
if (IPC4_MOD_ID(current->ipc_config.id))
return 0;

/* If pipeline connected to the starting one is in improper
* direction (CAPTURE towards DAI, PLAYBACK towards HOST),
* stop propagation. Direction param of the pipeline can not be
* trusted at this point, as it might not be configured yet,
* hence checking for endpoint component type.
*/
end_type = comp_get_endpoint_type(current->pipeline->sink_comp);
if (stream_direction == SOF_IPC_STREAM_PLAYBACK) {
if (end_type == COMP_ENDPOINT_HOST ||
end_type == COMP_ENDPOINT_NODE)
return 0;
}

if (stream_direction == SOF_IPC_STREAM_CAPTURE) {
if (end_type == COMP_ENDPOINT_DAI ||
end_type == COMP_ENDPOINT_NODE)
return 0;
}
/* Propagate prepare only to pipelines in the same direction */
if (!comp_same_dir(current, dir))
return 0;
}

if (current->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_LL) {
Expand Down
12 changes: 12 additions & 0 deletions src/include/sof/audio/component_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,18 @@ static inline uint64_t comp_get_total_data_processed(struct comp_dev *dev, uint3
return ret;
}

/** Returns true if the component's pipeline matches the specified direction */
static inline bool comp_same_dir(struct comp_dev *comp, enum sof_ipc_stream_direction dir)
{
int end_type = comp_get_endpoint_type(comp->pipeline->sink_comp);

if (dir == SOF_IPC_STREAM_PLAYBACK && end_type != COMP_ENDPOINT_DAI)
return false;
if (dir == SOF_IPC_STREAM_CAPTURE && end_type != COMP_ENDPOINT_HOST)
return false;
return true;
}

/** @}*/

#endif /* __SOF_AUDIO_COMPONENT_INT_H__ */

0 comments on commit 7e5d40a

Please sign in to comment.