[v2,1/4] libcamera: media_object: Add MediaPad string representations
diff mbox series

Message ID 20240911211816.73763-2-kieran.bingham@ideasonboard.com
State Accepted
Commit 6837607ca3f5ef0c516198494c5211cd7be0b165
Headers show
Series
  • MediaLink: Provide a string representation
Related show

Commit Message

Kieran Bingham Sept. 11, 2024, 9:18 p.m. UTC
Facilitate easy representations of a MediaPad object by preparing
it as a string and supporting output streams.

A MediaPad will be report in the following style:

  'imx283 1-001a'[0]

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
v2:
 - New patch

 include/libcamera/internal/media_object.h |  4 ++++
 src/libcamera/media_object.cpp            | 25 +++++++++++++++++++++++
 2 files changed, 29 insertions(+)

Comments

Laurent Pinchart Sept. 11, 2024, 10:25 p.m. UTC | #1
On Wed, Sep 11, 2024 at 11:18:13PM +0200, Kieran Bingham wrote:
> Facilitate easy representations of a MediaPad object by preparing
> it as a string and supporting output streams.
> 
> A MediaPad will be report in the following style:
> 
>   'imx283 1-001a'[0]
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

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

> ---
> v2:
>  - New patch
> 
>  include/libcamera/internal/media_object.h |  4 ++++
>  src/libcamera/media_object.cpp            | 25 +++++++++++++++++++++++
>  2 files changed, 29 insertions(+)
> 
> diff --git a/include/libcamera/internal/media_object.h b/include/libcamera/internal/media_object.h
> index c9d77511a991..d80d5f4574c7 100644
> --- a/include/libcamera/internal/media_object.h
> +++ b/include/libcamera/internal/media_object.h
> @@ -71,6 +71,8 @@ public:
>  
>  	void addLink(MediaLink *link);
>  
> +	std::string toString() const;
> +
>  private:
>  	LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaPad)
>  
> @@ -85,6 +87,8 @@ private:
>  	std::vector<MediaLink *> links_;
>  };
>  
> +std::ostream &operator<<(std::ostream &out, const MediaPad &pad);
> +
>  class MediaEntity : public MediaObject
>  {
>  public:
> diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp
> index 1b191a1e4df8..25f16707ab73 100644
> --- a/src/libcamera/media_object.cpp
> +++ b/src/libcamera/media_object.cpp
> @@ -235,6 +235,31 @@ void MediaPad::addLink(MediaLink *link)
>  	links_.push_back(link);
>  }
>  
> +/**
> + * \brief Generate a string representation of the MediaPad
> + * \return A string representing the MediaPad
> + */
> +std::string MediaPad::toString() const
> +{
> +	std::stringstream ss;
> +	ss << *this;
> +
> +	return ss.str();
> +}
> +
> +/**
> + * \brief Insert a text representation of a MediaPad into an output stream
> + * \param[in] out The output stream
> + * \param[in] pad The MediaPad
> + * \return The output stream \a out
> + */
> +std::ostream &operator<<(std::ostream &out, const MediaPad &pad)
> +{
> +	out << "'" << pad.entity()->name() << "'[" << pad.index() << "]";
> +
> +	return out;
> +}
> +
>  /**
>   * \class MediaEntity
>   * \brief The MediaEntity represents an entity in the media graph

Patch
diff mbox series

diff --git a/include/libcamera/internal/media_object.h b/include/libcamera/internal/media_object.h
index c9d77511a991..d80d5f4574c7 100644
--- a/include/libcamera/internal/media_object.h
+++ b/include/libcamera/internal/media_object.h
@@ -71,6 +71,8 @@  public:
 
 	void addLink(MediaLink *link);
 
+	std::string toString() const;
+
 private:
 	LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaPad)
 
@@ -85,6 +87,8 @@  private:
 	std::vector<MediaLink *> links_;
 };
 
+std::ostream &operator<<(std::ostream &out, const MediaPad &pad);
+
 class MediaEntity : public MediaObject
 {
 public:
diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp
index 1b191a1e4df8..25f16707ab73 100644
--- a/src/libcamera/media_object.cpp
+++ b/src/libcamera/media_object.cpp
@@ -235,6 +235,31 @@  void MediaPad::addLink(MediaLink *link)
 	links_.push_back(link);
 }
 
+/**
+ * \brief Generate a string representation of the MediaPad
+ * \return A string representing the MediaPad
+ */
+std::string MediaPad::toString() const
+{
+	std::stringstream ss;
+	ss << *this;
+
+	return ss.str();
+}
+
+/**
+ * \brief Insert a text representation of a MediaPad into an output stream
+ * \param[in] out The output stream
+ * \param[in] pad The MediaPad
+ * \return The output stream \a out
+ */
+std::ostream &operator<<(std::ostream &out, const MediaPad &pad)
+{
+	out << "'" << pad.entity()->name() << "'[" << pad.index() << "]";
+
+	return out;
+}
+
 /**
  * \class MediaEntity
  * \brief The MediaEntity represents an entity in the media graph