[v2,2/4] libcamera: media_object: Add MediaLink string representations
diff mbox series

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

Commit Message

Kieran Bingham Sept. 11, 2024, 9:18 p.m. UTC
Various parts of libcamera print the representation of a MediaLink by
inline joining the parts to make a string representation.

This repeated use case can be supported with a common helper to print
the MediaLink in a common manner using the existing toString() and
operator<< overload style to make it easier to report on MediaLink
types.

This implementation will report in the following style:

  'imx283 1-001a'[0] -> 'video-mux'[0]

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
v2:
 - Fix documentation
 - Use MediaPad helper 

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

Comments

Stefan Klug Sept. 12, 2024, 8:58 a.m. UTC | #1
Hi Kieran,

Missed v2, so

On Wed, Sep 11, 2024 at 11:18:14PM +0200, Kieran Bingham wrote:
> Various parts of libcamera print the representation of a MediaLink by
> inline joining the parts to make a string representation.
> 
> This repeated use case can be supported with a common helper to print
> the MediaLink in a common manner using the existing toString() and
> operator<< overload style to make it easier to report on MediaLink
> types.
> 
> This implementation will report in the following style:
> 
>   'imx283 1-001a'[0] -> 'video-mux'[0]
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> 

Regards,
Stefan

> ---
> v2:
>  - Fix documentation
>  - Use MediaPad helper 
> 
>  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 d80d5f4574c7..9356d204d6e5 100644
> --- a/include/libcamera/internal/media_object.h
> +++ b/include/libcamera/internal/media_object.h
> @@ -48,6 +48,8 @@ public:
>  	unsigned int flags() const { return flags_; }
>  	int setEnabled(bool enable);
>  
> +	std::string toString() const;
> +
>  private:
>  	LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaLink)
>  
> @@ -61,6 +63,8 @@ private:
>  	unsigned int flags_;
>  };
>  
> +std::ostream &operator<<(std::ostream &out, const MediaLink &link);
> +
>  class MediaPad : public MediaObject
>  {
>  public:
> diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp
> index 25f16707ab73..3e3772a628c2 100644
> --- a/src/libcamera/media_object.cpp
> +++ b/src/libcamera/media_object.cpp
> @@ -146,6 +146,31 @@ MediaLink::MediaLink(const struct media_v2_link *link, MediaPad *source,
>  {
>  }
>  
> +/**
> + * \brief Generate a string representation of the MediaLink
> + * \return A string representing the MediaLink
> + */
> +std::string MediaLink::toString() const
> +{
> +	std::stringstream ss;
> +	ss << *this;
> +
> +	return ss.str();
> +}
> +
> +/**
> + * \brief Insert a text representation of a Link into an output stream
> + * \param[in] out The output stream
> + * \param[in] link The MediaLink
> + * \return The output stream \a out
> + */
> +std::ostream &operator<<(std::ostream &out, const MediaLink &link)
> +{
> +	out << *link.source() << " -> " << *link.sink();
> +
> +	return out;
> +}
> +
>  /**
>   * \fn MediaLink::source()
>   * \brief Retrieve the link's source pad
> -- 
> 2.46.0
>

Patch
diff mbox series

diff --git a/include/libcamera/internal/media_object.h b/include/libcamera/internal/media_object.h
index d80d5f4574c7..9356d204d6e5 100644
--- a/include/libcamera/internal/media_object.h
+++ b/include/libcamera/internal/media_object.h
@@ -48,6 +48,8 @@  public:
 	unsigned int flags() const { return flags_; }
 	int setEnabled(bool enable);
 
+	std::string toString() const;
+
 private:
 	LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaLink)
 
@@ -61,6 +63,8 @@  private:
 	unsigned int flags_;
 };
 
+std::ostream &operator<<(std::ostream &out, const MediaLink &link);
+
 class MediaPad : public MediaObject
 {
 public:
diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp
index 25f16707ab73..3e3772a628c2 100644
--- a/src/libcamera/media_object.cpp
+++ b/src/libcamera/media_object.cpp
@@ -146,6 +146,31 @@  MediaLink::MediaLink(const struct media_v2_link *link, MediaPad *source,
 {
 }
 
+/**
+ * \brief Generate a string representation of the MediaLink
+ * \return A string representing the MediaLink
+ */
+std::string MediaLink::toString() const
+{
+	std::stringstream ss;
+	ss << *this;
+
+	return ss.str();
+}
+
+/**
+ * \brief Insert a text representation of a Link into an output stream
+ * \param[in] out The output stream
+ * \param[in] link The MediaLink
+ * \return The output stream \a out
+ */
+std::ostream &operator<<(std::ostream &out, const MediaLink &link)
+{
+	out << *link.source() << " -> " << *link.sink();
+
+	return out;
+}
+
 /**
  * \fn MediaLink::source()
  * \brief Retrieve the link's source pad