aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2010-08-25 08:00:41 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-03-22 03:53:17 -0400
commite02188c90f6ef61f0844c42508fe603c5d4fa42b (patch)
tree7b0ff940b37ba6bf53c7cea7fadbb697ec2d156a /drivers
parent97548ed4c4661502cdfd1aabd5d3876fa4f5cc2e (diff)
[media] media: Pipelines and media streams
Drivers often need to associate pipeline objects to entities, and to take stream state into account when configuring entities and links. The pipeline API helps drivers manage that information. When starting streaming, drivers call media_entity_pipeline_start(). The function marks all entities connected to the given entity through enabled links, either directly or indirectly, as streaming. Similarly, when stopping the stream, drivers call media_entity_pipeline_stop(). The media_entity_pipeline_start() function takes a pointer to a media pipeline and stores it in every entity in the graph. Drivers should embed the media_pipeline structure in higher-level pipeline structures and can then access the pipeline through the media_entity structure. Link configuration will fail with -EBUSY by default if either end of the link is a streaming entity, unless the link is marked with the MEDIA_LNK_FL_DYNAMIC flag. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/media-entity.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 6795c920d460..23640ed44d85 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -197,6 +197,75 @@ media_entity_graph_walk_next(struct media_entity_graph *graph)
197EXPORT_SYMBOL_GPL(media_entity_graph_walk_next); 197EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
198 198
199/* ----------------------------------------------------------------------------- 199/* -----------------------------------------------------------------------------
200 * Pipeline management
201 */
202
203/**
204 * media_entity_pipeline_start - Mark a pipeline as streaming
205 * @entity: Starting entity
206 * @pipe: Media pipeline to be assigned to all entities in the pipeline.
207 *
208 * Mark all entities connected to a given entity through enabled links, either
209 * directly or indirectly, as streaming. The given pipeline object is assigned to
210 * every entity in the pipeline and stored in the media_entity pipe field.
211 *
212 * Calls to this function can be nested, in which case the same number of
213 * media_entity_pipeline_stop() calls will be required to stop streaming. The
214 * pipeline pointer must be identical for all nested calls to
215 * media_entity_pipeline_start().
216 */
217void media_entity_pipeline_start(struct media_entity *entity,
218 struct media_pipeline *pipe)
219{
220 struct media_device *mdev = entity->parent;
221 struct media_entity_graph graph;
222
223 mutex_lock(&mdev->graph_mutex);
224
225 media_entity_graph_walk_start(&graph, entity);
226
227 while ((entity = media_entity_graph_walk_next(&graph))) {
228 entity->stream_count++;
229 WARN_ON(entity->pipe && entity->pipe != pipe);
230 entity->pipe = pipe;
231 }
232
233 mutex_unlock(&mdev->graph_mutex);
234}
235EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
236
237/**
238 * media_entity_pipeline_stop - Mark a pipeline as not streaming
239 * @entity: Starting entity
240 *
241 * Mark all entities connected to a given entity through enabled links, either
242 * directly or indirectly, as not streaming. The media_entity pipe field is
243 * reset to NULL.
244 *
245 * If multiple calls to media_entity_pipeline_start() have been made, the same
246 * number of calls to this function are required to mark the pipeline as not
247 * streaming.
248 */
249void media_entity_pipeline_stop(struct media_entity *entity)
250{
251 struct media_device *mdev = entity->parent;
252 struct media_entity_graph graph;
253
254 mutex_lock(&mdev->graph_mutex);
255
256 media_entity_graph_walk_start(&graph, entity);
257
258 while ((entity = media_entity_graph_walk_next(&graph))) {
259 entity->stream_count--;
260 if (entity->stream_count == 0)
261 entity->pipe = NULL;
262 }
263
264 mutex_unlock(&mdev->graph_mutex);
265}
266EXPORT_SYMBOL_GPL(media_entity_pipeline_stop);
267
268/* -----------------------------------------------------------------------------
200 * Module use count 269 * Module use count
201 */ 270 */
202 271
@@ -364,6 +433,10 @@ int __media_entity_setup_link(struct media_link *link, u32 flags)
364 source = link->source->entity; 433 source = link->source->entity;
365 sink = link->sink->entity; 434 sink = link->sink->entity;
366 435
436 if (!(link->flags & MEDIA_LNK_FL_DYNAMIC) &&
437 (source->stream_count || sink->stream_count))
438 return -EBUSY;
439
367 mdev = source->parent; 440 mdev = source->parent;
368 441
369 if ((flags & MEDIA_LNK_FL_ENABLED) && mdev->link_notify) { 442 if ((flags & MEDIA_LNK_FL_ENABLED) && mdev->link_notify) {