[libcamera-devel,v2,2/4] libcamera: media_device: Add functions to get a MediaLink

Message ID 20190108170407.4770-3-jacopo@jmondi.org
State Superseded
Headers show
Series
  • libcamera: media device: Add link handling
Related show

Commit Message

Jacopo Mondi Jan. 8, 2019, 5:04 p.m. UTC
Add three overloaded functions 'link()' to retrieve a link between two
pads. Each overloaded implementation exposes a different method to
identify the source and sink pads.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
v1->v2:
- Drop error handling: let the ioctl fail and report the error
- Drop the const qualifier to link() methods
- Incorporate comments changes

 src/libcamera/include/media_device.h |  6 +++
 src/libcamera/media_device.cpp       | 79 ++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+)

--
2.20.1

Comments

Laurent Pinchart Jan. 8, 2019, 6:11 p.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Tuesday, 8 January 2019 19:04:05 EET Jacopo Mondi wrote:
> Add three overloaded functions 'link()' to retrieve a link between two
> pads. Each overloaded implementation exposes a different method to
> identify the source and sink pads.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
> v1->v2:
> - Drop error handling: let the ioctl fail and report the error
> - Drop the const qualifier to link() methods
> - Incorporate comments changes
> 
>  src/libcamera/include/media_device.h |  6 +++
>  src/libcamera/media_device.cpp       | 79 ++++++++++++++++++++++++++++
>  2 files changed, 85 insertions(+)
> 
> diff --git a/src/libcamera/include/media_device.h
> b/src/libcamera/include/media_device.h index 9f45fc7..397d349 100644
> --- a/src/libcamera/include/media_device.h
> +++ b/src/libcamera/include/media_device.h
> @@ -40,6 +40,12 @@ public:
>  	const std::vector<MediaEntity *> &entities() const { return entities_; }
>  	MediaEntity *getEntityByName(const std::string &name) const;
> 
> +	MediaLink *link(const std::string sourceName, unsigned int sourceIdx,
> +			const std::string sinkName, unsigned int sinkIdx);

sourceName and sinkName should be references. Don't forget to update the \sa 
in the documentation accordingly.

> +	MediaLink *link(const MediaEntity *source, unsigned int sourceIdx,
> +			const MediaEntity *sink, unsigned int sinkIdx);
> +	MediaLink *link(const MediaPad *source, const MediaPad *sink);
> +
>  private:
>  	std::string driver_;
>  	std::string devnode_;
> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
> index b0d10ed..7ce5c22 100644
> --- a/src/libcamera/media_device.cpp
> +++ b/src/libcamera/media_device.cpp
> @@ -306,6 +306,85 @@ MediaEntity *MediaDevice::getEntityByName(const
> std::string &name) const return nullptr;
>  }
> 
> +/**
> + * \brief Retrieve the MediaLink connecting two pads, identified by entity
> + * names and pad indexes
> + * \param sourceName The source entity name
> + * \param sourceIdx The index of the source pad
> + * \param sinkName The sink entity name
> + * \param sinkIdx The index of the sink pad
> + *
> + * Find the link that connects the pads at index \a sourceIdx of the source
> + * entity with name \a sourceName, to the pad at index \a sinkIdx of the +
> * sink entity with name \a sinkName, if any.
> + *
> + * \sa MediaDevice::link(const MediaEntity *source, unsigned int sourceIdx,
> const MediaEntity *sink, unsigned int sinkIdx) const + * \sa
> MediaDevice::link(const MediaPad *source, const MediaPad *sink) const + *
> + * \return The link that connects the two entities, or nullptr if not such

s/entities/pads/

> a + * link exists
> + */
> +MediaLink *MediaDevice::link(const std::string sourceName, unsigned int
> sourceIdx, +			     const std::string sinkName, unsigned int sinkIdx)
> +{
> +	const MediaEntity *source = getEntityByName(sourceName);
> +	const MediaEntity *sink = getEntityByName(sinkName);
> +	if (!source || !sink)
> +		return nullptr;
> +
> +	return link(source, sourceIdx, sink, sinkIdx);
> +}
> +
> +/**
> + * \brief Retrieve the MediaLink connecting two pads, identified by the
> + * entities they belong to and pad indexes
> + * \param source The source entity
> + * \param sourceIdx The index of the source pad
> + * \param sink The sink entity
> + * \param sinkIdx The index of the sink pad
> + *
> + * Find the link that connects the pads at index \a sourceIdx of the source
> + * entity \a source, to the pad at index \a sinkIdx of the sink entity \a
> + * sink, if any.
> + *
> + * \sa MediaDevice::link(const std::string sourceName, unsigned int
> sourceIdx, const std::string sinkName, unsigned int sinkIdx) const + * \sa
> MediaDevice::link(const MediaPad *source, const MediaPad *sink) const + *
> + * \return The link that connects the two entities, or nullptr if not such

s/entities/pads/

> a + * link exists
> + */
> +MediaLink *MediaDevice::link(const MediaEntity *source, unsigned int
> sourceIdx,
> +			     const MediaEntity *sink, unsigned int sinkIdx)
> +{
> +
> +	const MediaPad *sourcePad = source->getPadByIndex(sourceIdx);
> +	const MediaPad *sinkPad = sink->getPadByIndex(sinkIdx);
> +	if (!sourcePad || !sinkPad)
> +		return nullptr;
> +
> +	return link(sourcePad, sinkPad);
> +}
> +
> +/**
> + * \brief Retrieve the MediaLink that connects two pads
> + * \param source The source pad
> + * \param sink The sink pad
> + *
> + * \sa MediaDevice::link(const std::string sourceName, unsigned int
> sourceIdx, const std::string sinkName, unsigned int sinkIdx) const + * \sa
> MediaDevice::link(const MediaEntity *source, unsigned int sourceIdx, const
> MediaEntity *sink, unsigned int sinkIdx) const + *
> + * \return The link that connects the two entities, nullptr otherwise

"The link that connects the two pads, or nullptr if not such link exists"

> + */
> +MediaLink *MediaDevice::link(const MediaPad *source, const MediaPad *sink)
> +{
> +	for (MediaLink *link : source->links()) {
> +		if (link->sink()->id() == sink->id())
> +			return link;
> +	}
> +
> +	return nullptr;
> +}
> +
>  /**
>   * \var MediaDevice::objects_
>   * \brief Global map of media objects (entities, pads, links) keyed by
> their

With the small issues above fixed,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Patch

diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h
index 9f45fc7..397d349 100644
--- a/src/libcamera/include/media_device.h
+++ b/src/libcamera/include/media_device.h
@@ -40,6 +40,12 @@  public:
 	const std::vector<MediaEntity *> &entities() const { return entities_; }
 	MediaEntity *getEntityByName(const std::string &name) const;

+	MediaLink *link(const std::string sourceName, unsigned int sourceIdx,
+			const std::string sinkName, unsigned int sinkIdx);
+	MediaLink *link(const MediaEntity *source, unsigned int sourceIdx,
+			const MediaEntity *sink, unsigned int sinkIdx);
+	MediaLink *link(const MediaPad *source, const MediaPad *sink);
+
 private:
 	std::string driver_;
 	std::string devnode_;
diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
index b0d10ed..7ce5c22 100644
--- a/src/libcamera/media_device.cpp
+++ b/src/libcamera/media_device.cpp
@@ -306,6 +306,85 @@  MediaEntity *MediaDevice::getEntityByName(const std::string &name) const
 	return nullptr;
 }

+/**
+ * \brief Retrieve the MediaLink connecting two pads, identified by entity
+ * names and pad indexes
+ * \param sourceName The source entity name
+ * \param sourceIdx The index of the source pad
+ * \param sinkName The sink entity name
+ * \param sinkIdx The index of the sink pad
+ *
+ * Find the link that connects the pads at index \a sourceIdx of the source
+ * entity with name \a sourceName, to the pad at index \a sinkIdx of the
+ * sink entity with name \a sinkName, if any.
+ *
+ * \sa MediaDevice::link(const MediaEntity *source, unsigned int sourceIdx, const MediaEntity *sink, unsigned int sinkIdx) const
+ * \sa MediaDevice::link(const MediaPad *source, const MediaPad *sink) const
+ *
+ * \return The link that connects the two entities, or nullptr if not such a
+ * link exists
+ */
+MediaLink *MediaDevice::link(const std::string sourceName, unsigned int sourceIdx,
+			     const std::string sinkName, unsigned int sinkIdx)
+{
+	const MediaEntity *source = getEntityByName(sourceName);
+	const MediaEntity *sink = getEntityByName(sinkName);
+	if (!source || !sink)
+		return nullptr;
+
+	return link(source, sourceIdx, sink, sinkIdx);
+}
+
+/**
+ * \brief Retrieve the MediaLink connecting two pads, identified by the
+ * entities they belong to and pad indexes
+ * \param source The source entity
+ * \param sourceIdx The index of the source pad
+ * \param sink The sink entity
+ * \param sinkIdx The index of the sink pad
+ *
+ * Find the link that connects the pads at index \a sourceIdx of the source
+ * entity \a source, to the pad at index \a sinkIdx of the sink entity \a
+ * sink, if any.
+ *
+ * \sa MediaDevice::link(const std::string sourceName, unsigned int sourceIdx, const std::string sinkName, unsigned int sinkIdx) const
+ * \sa MediaDevice::link(const MediaPad *source, const MediaPad *sink) const
+ *
+ * \return The link that connects the two entities, or nullptr if not such a
+ * link exists
+ */
+MediaLink *MediaDevice::link(const MediaEntity *source, unsigned int sourceIdx,
+			     const MediaEntity *sink, unsigned int sinkIdx)
+{
+
+	const MediaPad *sourcePad = source->getPadByIndex(sourceIdx);
+	const MediaPad *sinkPad = sink->getPadByIndex(sinkIdx);
+	if (!sourcePad || !sinkPad)
+		return nullptr;
+
+	return link(sourcePad, sinkPad);
+}
+
+/**
+ * \brief Retrieve the MediaLink that connects two pads
+ * \param source The source pad
+ * \param sink The sink pad
+ *
+ * \sa MediaDevice::link(const std::string sourceName, unsigned int sourceIdx, const std::string sinkName, unsigned int sinkIdx) const
+ * \sa MediaDevice::link(const MediaEntity *source, unsigned int sourceIdx, const MediaEntity *sink, unsigned int sinkIdx) const
+ *
+ * \return The link that connects the two entities, nullptr otherwise
+ */
+MediaLink *MediaDevice::link(const MediaPad *source, const MediaPad *sink)
+{
+	for (MediaLink *link : source->links()) {
+		if (link->sink()->id() == sink->id())
+			return link;
+	}
+
+	return nullptr;
+}
+
 /**
  * \var MediaDevice::objects_
  * \brief Global map of media objects (entities, pads, links) keyed by their