[PATCH v2 1/2] libcamera: pipeline: Add function to clear acquired media devices

Kieran Bingham kieran.bingham at ideasonboard.com
Thu Apr 24 13:30:17 CEST 2025


Quoting Paul Elder (2025-03-26 08:47:58)
> Some pipeline handler implementations, such as the simple pipeline
> handler, can encounter systems with multiple media devices that can be
> supported.
> 
> In a subsequent patch, the simple pipeline handler will be updated so
> that it will continue to match other media graphs even if the first
> media graph it encounters has an invalid media device. In this case,
> there would be a mix of invalid and valid media devices in
> mediaDevices_.
> 
> Add a function to clear mediaDevices_ so that this can be
> prevented.
> 
> Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>

> ---
> New in v2
> ---
>  include/libcamera/internal/pipeline_handler.h |  2 ++
>  src/libcamera/pipeline_handler.cpp            | 15 +++++++++++++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h
> index 972a2fa65310..5fa8bc2f66ee 100644
> --- a/include/libcamera/internal/pipeline_handler.h
> +++ b/include/libcamera/internal/pipeline_handler.h
> @@ -71,6 +71,8 @@ public:
>         CameraManager *cameraManager() const { return manager_; }
>  
>  protected:
> +       void clearMediaDevices();
> +
>         void registerCamera(std::shared_ptr<Camera> camera);
>         void hotplugMediaDevice(MediaDevice *media);
>  
> diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
> index d84dff3c9f19..8f12957b75fa 100644
> --- a/src/libcamera/pipeline_handler.cpp
> +++ b/src/libcamera/pipeline_handler.cpp
> @@ -142,6 +142,21 @@ MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator,
>         return media.get();
>  }
>  
> +/**
> + * \brief Clear the list of acquired media devices for this PipelineHandler instance
> + *
> + * This is meant to be used when the Pipeline Handler needs to search multiple
> + * media graphs to create multiple instances of itself, and a partial match
> + * needs to be canceled as an invalid media device was detected. This is to
> + * prevent mediaDevices_ from having a mix of invalid media devices from a
> + * previous failed match and valid media devices from the current succeeding
> + * match.
> + */
> +void PipelineHandler::clearMediaDevices()
> +{
> +       mediaDevices_.clear();
> +}
> +
>  /**
>   * \brief Acquire exclusive access to the pipeline handler for the process
>   *
> -- 
> 2.47.2
>


More information about the libcamera-devel mailing list