Linux Media Controller development
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: linux-media@vger.kernel.org
Cc: Sakari Ailus <sakari.ailus@iki.fi>,
	Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Gregor Jasny <gjasny@googlemail.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>
Subject: Re: [v4l-utils] [PATCH 1/8] utils: media-ctl: Print MUST_CONNECT pad flags
Date: Wed, 3 Apr 2024 11:40:34 +0300	[thread overview]
Message-ID: <20240403084034.GA4168@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20240402000033.4007-2-laurent.pinchart@ideasonboard.com>

Hi Sakari,

Thank you for the patch.

On Tue, Apr 02, 2024 at 03:00:26AM +0300, Laurent Pinchart wrote:
> From: Sakari Ailus <sakari.ailus@linux.intel.com>
> 
> Print the MUST_CONNECT pad flag for each pad.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
>  utils/media-ctl/media-ctl.c | 50 +++++++++++++++++++++----------------
>  1 file changed, 28 insertions(+), 22 deletions(-)
> 
> diff --git a/utils/media-ctl/media-ctl.c b/utils/media-ctl/media-ctl.c
> index 2081f111f2db..1b40552253f1 100644
> --- a/utils/media-ctl/media-ctl.c
> +++ b/utils/media-ctl/media-ctl.c
> @@ -368,26 +368,6 @@ static const char *media_entity_subtype_to_string(unsigned type)
>  	}
>  }
>  
> -static const char *media_pad_type_to_string(unsigned flag)
> -{
> -	static const struct {
> -		__u32 flag;
> -		const char *name;
> -	} flags[] = {
> -		{ MEDIA_PAD_FL_SINK, "Sink" },
> -		{ MEDIA_PAD_FL_SOURCE, "Source" },
> -	};
> -
> -	unsigned int i;
> -
> -	for (i = 0; i < ARRAY_SIZE(flags); i++) {
> -		if (flags[i].flag & flag)
> -			return flags[i].name;
> -	}
> -
> -	return "Unknown";
> -}
> -
>  static void media_print_topology_dot(struct media_device *media)
>  {
>  	unsigned int nents = media_get_entities_count(media);
> @@ -525,6 +505,25 @@ static void media_print_pad_text(struct media_entity *entity,
>  		v4l2_subdev_print_subdev_dv(entity);
>  }
>  
> +static unsigned int weight(uint32_t word)
> +{
> +	unsigned int w = 0, i;
> +
> +	for (i = 0; i < sizeof(word) << 3; i++, word >>= 1)
> +		w += word & 1U;
> +
> +	return w;
> +}
> +
> +static const char *comma(uint32_t flag, uint32_t prev_flags, uint32_t flags)
> +{
> +	static const char *empty = "", *comma = ", ";
> +	if (!(flag & flags))
> +		return empty;
> +
> +	return weight(prev_flags & flags) ? comma : empty;

Unless I'm mistaken, we can write this

	return prev_flags & flags ? comma : empty;

and drop the weight function.

> +}
> +
>  static void media_print_topology_text_entity(struct media_device *media,
>  					     struct media_entity *entity)
>  {
> @@ -567,8 +566,15 @@ static void media_print_topology_text_entity(struct media_device *media,
>  	for (j = 0; j < info->pads; j++) {
>  		const struct media_pad *pad = media_entity_get_pad(entity, j);
>  
> -		printf("\tpad%u: %s\n", j, media_pad_type_to_string(pad->flags));
> -
> +		printf("\tpad%u: %s%s%s%s%s\n", j,
> +		       pad->flags & MEDIA_PAD_FL_SINK ? "Sink" : "",
> +		       comma(MEDIA_PAD_FL_SOURCE, MEDIA_PAD_FL_SINK,
> +			     pad->flags),
> +		       pad->flags & MEDIA_PAD_FL_SOURCE ? "Source" : "",
> +		       comma(MEDIA_PAD_FL_MUST_CONNECT,
> +			     MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_SOURCE,
> +			     pad->flags),
> +		       pad->flags & MEDIA_PAD_FL_MUST_CONNECT ? "Must connect" : "");

To be honest, this looks overly complicated. How about printing the
flags with a loop ?

>  		media_print_pad_text(entity, pad, routes, num_routes);
>  
>  		for (k = 0; k < num_links; k++) {

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2024-04-03  8:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02  0:00 [v4l-utils] [PATCH 0/8] Support for the generic line-based metadata support Laurent Pinchart
2024-04-02  0:00 ` [v4l-utils] [PATCH 1/8] utils: media-ctl: Print MUST_CONNECT pad flags Laurent Pinchart
2024-04-03  8:40   ` Laurent Pinchart [this message]
2024-04-03  8:43     ` Tomi Valkeinen
2024-04-03  8:56       ` Hans Verkuil
2024-04-04 20:17         ` Sakari Ailus
2024-04-04 22:04           ` Laurent Pinchart
2024-04-02  0:00 ` [v4l-utils] [PATCH 2/8] v4l2-compliance: Constify pointers and references in formats tests Laurent Pinchart
2024-04-03  8:44   ` Tomi Valkeinen
2024-04-03  8:46   ` Hans Verkuil
2024-04-02  0:00 ` [v4l-utils] [PATCH 3/8] v4l-utils: sync-with-kernel Laurent Pinchart
2024-04-02  0:00 ` [v4l-utils] [PATCH 4/8] utils: media-ctl: Support changed routing API Laurent Pinchart
2024-04-02  0:00 ` [v4l-utils] [PATCH 5/8] utils: media-ctl: Also print INTERNAL pad flag Laurent Pinchart
2024-04-02  0:00 ` [v4l-utils] [PATCH 6/8] v4l2-compliance: Support the changed routing API Laurent Pinchart
2024-04-02 10:54   ` Tomi Valkeinen
2024-04-05  6:37     ` Sakari Ailus
2024-04-02  0:00 ` [v4l-utils] [PATCH 7/8] v4l2-compliance: Add tests for V4L2_FMT_FLAG_META_LINE_BASED flag Laurent Pinchart
2024-04-02  0:00 ` [v4l-utils] [PATCH 8/8] v4l2-compliance: Test IMMUTABLE route flag Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240403084034.GA4168@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=gjasny@googlemail.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=sakari.ailus@iki.fi \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tomi.valkeinen@ideasonboard.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox