media: media-entity: Simplify media_pipeline_start()
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Thu, 13 Jan 2022 15:00:42 +0000 (17:00 +0200)
committerSakari Ailus <sakari.ailus@linux.intel.com>
Thu, 3 Mar 2022 22:27:06 +0000 (00:27 +0200)
commit3056a8e936bb090865402bfe6f3a730a28790033
treedc9efe7ce7bb99f0264c24825220385ede80adf9
parentf17bc788f7b97c36b8f3fbef14555a2a16ee3f69
media: media-entity: Simplify media_pipeline_start()

The media_pipeline_start() function has two purposes: it constructs a
pipeline by recording the entities that are part of it, gathered from a
graph walk, and validate the media links. The pipeline pointer is stored
in the media_entity structure as part of this process, and the entity's
stream count is increased, to record that the entity is streaming.

When multiple video nodes are present in a pipeline,
media_pipeline_start() is typically called on all of them, with the same
pipeline pointer. This is taken into account in media_pipeline_start()
by skipping validation for entities that are already part of the
pipeline, while returning an error if an entity is part of a different
pipeline.

It turns out that this process is overly complicated. When
media_pipeline_start() is called for the first time, it constructs the
full pipeline, adding all entities and validating all the links.
Subsequent calls to media_pipeline_start() are then nearly no-ops, they
only increase the stream count on the pipeline and on all entities.

The media_entity stream_count field is used for two purposes: checking
if the entity is streaming, and detecting when a call to
media_pipeline_stop() balances needs to reset the entity pipe pointer to
NULL. The former can easily be replaced by a check of the pipe pointer.

Simplify media_pipeline_start() by avoiding the pipeline walk on all
calls but the first one, and drop the media_entity stream_count field.
media_pipeline_stop() is updated accordingly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
[Sakari Ailus: Drop redundant '!= NULL' as discussed]
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
drivers/media/mc/mc-entity.c
include/media/media-entity.h