[1/4] libcamera: media_device: Add helper to return matching entities
diff mbox series

Message ID 20240916140241.47845-2-kieran.bingham@ideasonboard.com
State Superseded
Headers show
Series
  • MediaPipeline: Complex input device support
Related show

Commit Message

Kieran Bingham Sept. 16, 2024, 2:02 p.m. UTC
Provide a helper on the MediaDevice to return a list of all
available entities which match a given function in the graph.

As a drive by, also fix a whitespace error in the documentation of
MediaDevice::setupLink.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 include/libcamera/internal/media_device.h |  2 ++
 src/libcamera/media_device.cpp            | 24 ++++++++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

Comments

Umang Jain Sept. 27, 2024, 7:48 a.m. UTC | #1
Hi Kieran,

Thank you for the patch.

On 16/09/24 7:32 pm, Kieran Bingham wrote:
> Provide a helper on the MediaDevice to return a list of all
> available entities which match a given function in the graph.
>
> As a drive by, also fix a whitespace error in the documentation of
> MediaDevice::setupLink.
>
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>   include/libcamera/internal/media_device.h |  2 ++
>   src/libcamera/media_device.cpp            | 24 ++++++++++++++++++++++-
>   2 files changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h
> index e412d3a0b7e3..b3a48b98d64b 100644
> --- a/include/libcamera/internal/media_device.h
> +++ b/include/libcamera/internal/media_device.h
> @@ -55,6 +55,8 @@ public:
>   
>   	Signal<> disconnected;
>   
> +	std::vector<MediaEntity *> locateEntities(unsigned int function);
> +
>   protected:
>   	std::string logPrefix() const override;
>   
> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
> index d71dad74df70..d1e0dee2ff0f 100644
> --- a/src/libcamera/media_device.cpp
> +++ b/src/libcamera/media_device.cpp
> @@ -793,7 +793,7 @@ void MediaDevice::fixupEntityFlags(struct media_v2_entity *entity)
>    * low-level link setup as it performs no checks on the validity of the \a
>    * flags, and assumes that the supplied \a flags are valid for the link (e.g.
>    * immutable links cannot be disabled).
> -*
> + *
>    * \sa MediaLink::setEnabled(bool enable)
>    *
>    * \return 0 on success or a negative error code otherwise
> @@ -828,4 +828,26 @@ int MediaDevice::setupLink(const MediaLink *link, unsigned int flags)
>   	return 0;
>   }
>   
> +/**
> + * \brief Identify all entities of a common function in the MediaDevice
> + * \param[in] function The entity function to search for
> + *
> + * Search all entities within the graph of the MediaDevice and return
> + * a vector of those which match the given function.
> + *
> + * \return A vector of matching entities
> + */
> +std::vector<MediaEntity *> MediaDevice::locateEntities(unsigned int function)
> +{
> +	std::vector<MediaEntity *> found;
> +
> +	/* Gather all the entities matching the function they expose. */
> +	for (MediaEntity *entity : entities()) {
> +		if (entity->function() == function)
> +			found.push_back(entity);
> +	}
> +
> +	return found;
> +}
> +
>   } /* namespace libcamera */
Jacopo Mondi Sept. 27, 2024, 1:47 p.m. UTC | #2
Hi Kieran

On Mon, Sep 16, 2024 at 04:02:38PM GMT, Kieran Bingham wrote:
> Provide a helper on the MediaDevice to return a list of all
> available entities which match a given function in the graph.
>
> As a drive by, also fix a whitespace error in the documentation of
> MediaDevice::setupLink.
>
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  include/libcamera/internal/media_device.h |  2 ++
>  src/libcamera/media_device.cpp            | 24 ++++++++++++++++++++++-
>  2 files changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h
> index e412d3a0b7e3..b3a48b98d64b 100644
> --- a/include/libcamera/internal/media_device.h
> +++ b/include/libcamera/internal/media_device.h
> @@ -55,6 +55,8 @@ public:
>
>  	Signal<> disconnected;
>
> +	std::vector<MediaEntity *> locateEntities(unsigned int function);
> +
>  protected:
>  	std::string logPrefix() const override;
>
> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
> index d71dad74df70..d1e0dee2ff0f 100644
> --- a/src/libcamera/media_device.cpp
> +++ b/src/libcamera/media_device.cpp
> @@ -793,7 +793,7 @@ void MediaDevice::fixupEntityFlags(struct media_v2_entity *entity)
>   * low-level link setup as it performs no checks on the validity of the \a
>   * flags, and assumes that the supplied \a flags are valid for the link (e.g.
>   * immutable links cannot be disabled).
> -*
> + *
>   * \sa MediaLink::setEnabled(bool enable)
>   *
>   * \return 0 on success or a negative error code otherwise
> @@ -828,4 +828,26 @@ int MediaDevice::setupLink(const MediaLink *link, unsigned int flags)
>  	return 0;
>  }
>
> +/**
> + * \brief Identify all entities of a common function in the MediaDevice
> + * \param[in] function The entity function to search for
> + *
> + * Search all entities within the graph of the MediaDevice and return
> + * a vector of those which match the given function.

I would add that 'function' is expected to be expressed using the
MEDIA_ENT_F_* macros defined by the Media Controller API.

> + *
> + * \return A vector of matching entities
> + */
> +std::vector<MediaEntity *> MediaDevice::locateEntities(unsigned int function)
> +{
> +	std::vector<MediaEntity *> found;
> +
> +	/* Gather all the entities matching the function they expose. */
> +	for (MediaEntity *entity : entities()) {
> +		if (entity->function() == function)
> +			found.push_back(entity);
> +	}
> +
> +	return found;
> +}
> +

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

Thanks
  j

>  } /* namespace libcamera */
> --
> 2.46.0
>
Kieran Bingham Oct. 2, 2024, 2:29 p.m. UTC | #3
Quoting Jacopo Mondi (2024-09-27 14:47:23)
> Hi Kieran
> 
> On Mon, Sep 16, 2024 at 04:02:38PM GMT, Kieran Bingham wrote:
> > Provide a helper on the MediaDevice to return a list of all
> > available entities which match a given function in the graph.
> >
> > As a drive by, also fix a whitespace error in the documentation of
> > MediaDevice::setupLink.
> >
> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > ---
> >  include/libcamera/internal/media_device.h |  2 ++
> >  src/libcamera/media_device.cpp            | 24 ++++++++++++++++++++++-
> >  2 files changed, 25 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h
> > index e412d3a0b7e3..b3a48b98d64b 100644
> > --- a/include/libcamera/internal/media_device.h
> > +++ b/include/libcamera/internal/media_device.h
> > @@ -55,6 +55,8 @@ public:
> >
> >       Signal<> disconnected;
> >
> > +     std::vector<MediaEntity *> locateEntities(unsigned int function);
> > +
> >  protected:
> >       std::string logPrefix() const override;
> >
> > diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
> > index d71dad74df70..d1e0dee2ff0f 100644
> > --- a/src/libcamera/media_device.cpp
> > +++ b/src/libcamera/media_device.cpp
> > @@ -793,7 +793,7 @@ void MediaDevice::fixupEntityFlags(struct media_v2_entity *entity)
> >   * low-level link setup as it performs no checks on the validity of the \a
> >   * flags, and assumes that the supplied \a flags are valid for the link (e.g.
> >   * immutable links cannot be disabled).
> > -*
> > + *
> >   * \sa MediaLink::setEnabled(bool enable)
> >   *
> >   * \return 0 on success or a negative error code otherwise
> > @@ -828,4 +828,26 @@ int MediaDevice::setupLink(const MediaLink *link, unsigned int flags)
> >       return 0;
> >  }
> >
> > +/**
> > + * \brief Identify all entities of a common function in the MediaDevice
> > + * \param[in] function The entity function to search for
> > + *
> > + * Search all entities within the graph of the MediaDevice and return
> > + * a vector of those which match the given function.
> 
> I would add that 'function' is expected to be expressed using the
> MEDIA_ENT_F_* macros defined by the Media Controller API.
> 

Updated to:

 * Search all entities within the graph of the MediaDevice and return
 * a vector of those which match the given function as defined by the
 * MEDIA_ENT_F_* macros of the media controller API.


> > + *
> > + * \return A vector of matching entities
> > + */
> > +std::vector<MediaEntity *> MediaDevice::locateEntities(unsigned int function)
> > +{
> > +     std::vector<MediaEntity *> found;
> > +
> > +     /* Gather all the entities matching the function they expose. */
> > +     for (MediaEntity *entity : entities()) {
> > +             if (entity->function() == function)
> > +                     found.push_back(entity);
> > +     }
> > +
> > +     return found;
> > +}
> > +
> 
> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> 
> Thanks
>   j
> 
> >  } /* namespace libcamera */
> > --
> > 2.46.0
> >
Daniel Scally Oct. 8, 2024, 2:34 p.m. UTC | #4
Hi Kieran

On 02/10/2024 15:29, Kieran Bingham wrote:
> Quoting Jacopo Mondi (2024-09-27 14:47:23)
>> Hi Kieran
>>
>> On Mon, Sep 16, 2024 at 04:02:38PM GMT, Kieran Bingham wrote:
>>> Provide a helper on the MediaDevice to return a list of all
>>> available entities which match a given function in the graph.
>>>
>>> As a drive by, also fix a whitespace error in the documentation of
>>> MediaDevice::setupLink.
>>>
>>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>>> ---
>>>   include/libcamera/internal/media_device.h |  2 ++
>>>   src/libcamera/media_device.cpp            | 24 ++++++++++++++++++++++-
>>>   2 files changed, 25 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h
>>> index e412d3a0b7e3..b3a48b98d64b 100644
>>> --- a/include/libcamera/internal/media_device.h
>>> +++ b/include/libcamera/internal/media_device.h
>>> @@ -55,6 +55,8 @@ public:
>>>
>>>        Signal<> disconnected;
>>>
>>> +     std::vector<MediaEntity *> locateEntities(unsigned int function);
>>> +
>>>   protected:
>>>        std::string logPrefix() const override;
>>>
>>> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
>>> index d71dad74df70..d1e0dee2ff0f 100644
>>> --- a/src/libcamera/media_device.cpp
>>> +++ b/src/libcamera/media_device.cpp
>>> @@ -793,7 +793,7 @@ void MediaDevice::fixupEntityFlags(struct media_v2_entity *entity)
>>>    * low-level link setup as it performs no checks on the validity of the \a
>>>    * flags, and assumes that the supplied \a flags are valid for the link (e.g.
>>>    * immutable links cannot be disabled).
>>> -*
>>> + *
>>>    * \sa MediaLink::setEnabled(bool enable)
>>>    *
>>>    * \return 0 on success or a negative error code otherwise
>>> @@ -828,4 +828,26 @@ int MediaDevice::setupLink(const MediaLink *link, unsigned int flags)
>>>        return 0;
>>>   }
>>>
>>> +/**
>>> + * \brief Identify all entities of a common function in the MediaDevice
>>> + * \param[in] function The entity function to search for
>>> + *
>>> + * Search all entities within the graph of the MediaDevice and return
>>> + * a vector of those which match the given function.
>> I would add that 'function' is expected to be expressed using the
>> MEDIA_ENT_F_* macros defined by the Media Controller API.
>>
> Updated to:
>
>   * Search all entities within the graph of the MediaDevice and return
>   * a vector of those which match the given function as defined by the
>   * MEDIA_ENT_F_* macros of the media controller API.
>
On the back of which:


Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>

>>> + *
>>> + * \return A vector of matching entities
>>> + */
>>> +std::vector<MediaEntity *> MediaDevice::locateEntities(unsigned int function)
>>> +{
>>> +     std::vector<MediaEntity *> found;
>>> +
>>> +     /* Gather all the entities matching the function they expose. */
>>> +     for (MediaEntity *entity : entities()) {
>>> +             if (entity->function() == function)
>>> +                     found.push_back(entity);
>>> +     }
>>> +
>>> +     return found;
>>> +}
>>> +
>> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
>>
>> Thanks
>>    j
>>
>>>   } /* namespace libcamera */
>>> --
>>> 2.46.0
>>>

Patch
diff mbox series

diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h
index e412d3a0b7e3..b3a48b98d64b 100644
--- a/include/libcamera/internal/media_device.h
+++ b/include/libcamera/internal/media_device.h
@@ -55,6 +55,8 @@  public:
 
 	Signal<> disconnected;
 
+	std::vector<MediaEntity *> locateEntities(unsigned int function);
+
 protected:
 	std::string logPrefix() const override;
 
diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
index d71dad74df70..d1e0dee2ff0f 100644
--- a/src/libcamera/media_device.cpp
+++ b/src/libcamera/media_device.cpp
@@ -793,7 +793,7 @@  void MediaDevice::fixupEntityFlags(struct media_v2_entity *entity)
  * low-level link setup as it performs no checks on the validity of the \a
  * flags, and assumes that the supplied \a flags are valid for the link (e.g.
  * immutable links cannot be disabled).
-*
+ *
  * \sa MediaLink::setEnabled(bool enable)
  *
  * \return 0 on success or a negative error code otherwise
@@ -828,4 +828,26 @@  int MediaDevice::setupLink(const MediaLink *link, unsigned int flags)
 	return 0;
 }
 
+/**
+ * \brief Identify all entities of a common function in the MediaDevice
+ * \param[in] function The entity function to search for
+ *
+ * Search all entities within the graph of the MediaDevice and return
+ * a vector of those which match the given function.
+ *
+ * \return A vector of matching entities
+ */
+std::vector<MediaEntity *> MediaDevice::locateEntities(unsigned int function)
+{
+	std::vector<MediaEntity *> found;
+
+	/* Gather all the entities matching the function they expose. */
+	for (MediaEntity *entity : entities()) {
+		if (entity->function() == function)
+			found.push_back(entity);
+	}
+
+	return found;
+}
+
 } /* namespace libcamera */