[libcamera-devel] [PATCH 3/3] vimc: Join pipeline if one already exists

Dafna Hirschfeld dafna3 at gmail.com
Mon Dec 2 17:31:22 CET 2019


Hi,

On Sat, May 18, 2019 at 4:16 AM Niklas Söderlund <
niklas.soderlund+renesas at ragnatech.se> wrote:

> A sensor which is running is already part of a pipeline and trying to
> start a new pipeline is not possible. This prevents two capture devices
> connected to the same sensor from running at the same time.
>
> Instead of failing to start the second capture device allow it to join
> the already running pipeline by looking it up at the sensor. This allows
> two (or more) capture devices to independently be started and stopped
> while still being connected to the same sensor.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
> ---
>  drivers/media/platform/vimc/vimc-capture.c | 35 +++++++++++++++++++++-
>  1 file changed, 34 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/vimc/vimc-capture.c
> b/drivers/media/platform/vimc/vimc-capture.c
> index e7d0fc2228a6f0c1..f9eb1e327e311b4a 100644
> --- a/drivers/media/platform/vimc/vimc-capture.c
> +++ b/drivers/media/platform/vimc/vimc-capture.c
> @@ -264,16 +264,49 @@ static void vimc_cap_return_all_buffers(struct
> vimc_cap_device *vcap,
>         spin_unlock(&vcap->qlock);
>  }
>
> +static struct media_entity *vimc_cap_get_sensor(struct vimc_cap_device
> *vcap)
> +{
> +       struct media_entity *entity = &vcap->vdev.entity;
> +       struct media_device *mdev = entity->graph_obj.mdev;
> +       struct media_graph graph;
> +
> +       mutex_lock(&mdev->graph_mutex);
> +       if (media_graph_walk_init(&graph, mdev)) {
>
adding error debug?


> +               mutex_unlock(&mdev->graph_mutex);
> +               return NULL;
> +       }

+
> +       media_graph_walk_start(&graph, entity);
> +
> +       while ((entity = media_graph_walk_next(&graph)))
> +               if (entity->function == MEDIA_ENT_F_CAM_SENSOR)
> +                       break;
> +
> +       mutex_unlock(&mdev->graph_mutex);
> +
> +       media_graph_walk_cleanup(&graph);
> +
> +       return entity;
> +}
> +
>
Iterating the pipeline from the capture back to the source is already done
int the function vimc_streamer_pipeline_init
but there it iterates it using the media_entity_remote_pad function and not
with the graph_walk api, so better use the same
form of iteration in both places.
In addition, the vimc streamer code uses the function vimc_is_source to
check that the source is reached instead of MEDIA_ENT_F_CAM_SENSOR
so better be consistent with that too.
Last, I think it is enough to iterate back until an entity with non NULL
pipe pointer is reached.

 static int vimc_cap_start_streaming(struct vb2_queue *vq, unsigned int
> count)
>  {
>         struct vimc_cap_device *vcap = vb2_get_drv_priv(vq);
>         struct media_entity *entity = &vcap->vdev.entity;
> +       struct media_pipeline *pipe = NULL;
> +       struct media_entity *sensorent;
>
better call it sensor_ent,

>         int ret;
>
>         vcap->sequence = 0;
>
>         /* Start the media pipeline */
> -       ret = media_pipeline_start(entity, &vcap->stream.pipe);
> +       sensorent = vimc_cap_get_sensor(vcap);
> +       if (sensorent && sensorent->pipe)
>
if sensorent is null, this must be an error so better change the code to
something like
if (!sensorent) {
        dev_err("err blabla");
        ret -EPIPE;
}
if(seneorent->pipe)

> +               pipe = sensorent->pipe;
> +       else
> +               pipe = &vcap->stream.pipe;
> +
>
and with the new code this can be one line with the "? :" operator.


> +       ret = media_pipeline_start(entity, pipe);
>         if (ret) {
>                 vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_QUEUED);
>                 return ret;
> --
>
Thanks,
Dafna

> 2.21.0
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20191202/ebd7d70d/attachment.htm>


More information about the libcamera-devel mailing list