linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Add helper functions to print a fourcc
@ 2019-09-16  9:00 Hans Verkuil
  2019-09-16  9:00 ` [PATCH 1/2] videodev2.h: add macros " Hans Verkuil
  2019-09-16  9:00 ` [PATCH 2/2] v4l2-ioctl.c: use new V4L2_FOURCC_CONV/ARGS macros Hans Verkuil
  0 siblings, 2 replies; 6+ messages in thread
From: Hans Verkuil @ 2019-09-16  9:00 UTC (permalink / raw)
  To: linux-media; +Cc: Sakari Ailus, Dave Stevenson

This is a reboot of this old patch:

https://patchwork.kernel.org/patch/9961789/

I've taken Sakari's suggestion and made new patches.

It happens too often that we want to log a fourcc, either in kernel
or in userspace, so I think this will be quite useful.

Regards,

	Hans

Hans Verkuil (2):
  videodev2.h: add macros to print a fourcc
  v4l2-ioctl.c: use new V4L2_FOURCC_CONV/ARGS macros

 drivers/media/v4l2-core/v4l2-ioctl.c |  8 ++------
 include/uapi/linux/videodev2.h       | 13 +++++++++++++
 2 files changed, 15 insertions(+), 6 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] videodev2.h: add macros to print a fourcc
  2019-09-16  9:00 [PATCH 0/2] Add helper functions to print a fourcc Hans Verkuil
@ 2019-09-16  9:00 ` Hans Verkuil
  2019-09-16  9:26   ` Sakari Ailus
  2019-09-16  9:00 ` [PATCH 2/2] v4l2-ioctl.c: use new V4L2_FOURCC_CONV/ARGS macros Hans Verkuil
  1 sibling, 1 reply; 6+ messages in thread
From: Hans Verkuil @ 2019-09-16  9:00 UTC (permalink / raw)
  To: linux-media; +Cc: Sakari Ailus, Dave Stevenson, Hans Verkuil

Add new macros V4L2_FOURCC_CONV and V4L2_FOURCC_ARGS for use
in code that prints a fourcc. These macros can be used in both
kernel and userspace.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Suggested-by: Sakari Ailus <sakari.ailus@iki.fi>
---
 include/uapi/linux/videodev2.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 530638dffd93..7a34eb93437e 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -82,6 +82,19 @@
 	((__u32)(a) | ((__u32)(b) << 8) | ((__u32)(c) << 16) | ((__u32)(d) << 24))
 #define v4l2_fourcc_be(a, b, c, d)	(v4l2_fourcc(a, b, c, d) | (1U << 31))
 
+/*
+ * Helper macros to print a fourcc in a standard format. E.g.:
+ *
+ * printf("fourcc is " V4L2_FOURCC_CONV "\n", V4L2_FOURCC_ARGS(fourcc));
+ *
+ * Note that V4L2_FOURCC_ARGS reuses fourcc, so this can't be an
+ * expression with side-effects.
+ */
+#define V4L2_FOURCC_CONV "%c%c%c%c%s"
+#define V4L2_FOURCC_ARGS(fourcc) \
+	(fourcc) & 0x7f, ((fourcc) >> 8) & 0x7f, ((fourcc) >> 16) & 0x7f, \
+	((fourcc) >> 24) & 0x7f, ((fourcc) & (1U << 31) ? "-BE" : "")
+
 /*
  *	E N U M S
  */
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] v4l2-ioctl.c: use new V4L2_FOURCC_CONV/ARGS macros
  2019-09-16  9:00 [PATCH 0/2] Add helper functions to print a fourcc Hans Verkuil
  2019-09-16  9:00 ` [PATCH 1/2] videodev2.h: add macros " Hans Verkuil
@ 2019-09-16  9:00 ` Hans Verkuil
  2019-09-16  9:27   ` Sakari Ailus
  1 sibling, 1 reply; 6+ messages in thread
From: Hans Verkuil @ 2019-09-16  9:00 UTC (permalink / raw)
  To: linux-media; +Cc: Sakari Ailus, Dave Stevenson, Hans Verkuil

Use these new standard macros to log the fourcc value in a
human readable format.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 51b912743f0f..80030533e1b8 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1383,12 +1383,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
 				return;
 			WARN(1, "Unknown pixelformat 0x%08x\n", fmt->pixelformat);
 			flags = 0;
-			snprintf(fmt->description, sz, "%c%c%c%c%s",
-					(char)(fmt->pixelformat & 0x7f),
-					(char)((fmt->pixelformat >> 8) & 0x7f),
-					(char)((fmt->pixelformat >> 16) & 0x7f),
-					(char)((fmt->pixelformat >> 24) & 0x7f),
-					(fmt->pixelformat & (1UL << 31)) ? "-BE" : "");
+			snprintf(fmt->description, sz, V4L2_FOURCC_CONV,
+				 V4L2_FOURCC_ARGS(fmt->pixelformat));
 			break;
 		}
 	}
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] videodev2.h: add macros to print a fourcc
  2019-09-16  9:00 ` [PATCH 1/2] videodev2.h: add macros " Hans Verkuil
@ 2019-09-16  9:26   ` Sakari Ailus
  2019-09-16  9:31     ` Hans Verkuil
  0 siblings, 1 reply; 6+ messages in thread
From: Sakari Ailus @ 2019-09-16  9:26 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, Dave Stevenson

Hi Hans,

On Mon, Sep 16, 2019 at 11:00:46AM +0200, Hans Verkuil wrote:
> Add new macros V4L2_FOURCC_CONV and V4L2_FOURCC_ARGS for use
> in code that prints a fourcc. These macros can be used in both
> kernel and userspace.
> 
> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> Suggested-by: Sakari Ailus <sakari.ailus@iki.fi>
> ---
>  include/uapi/linux/videodev2.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index 530638dffd93..7a34eb93437e 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -82,6 +82,19 @@
>  	((__u32)(a) | ((__u32)(b) << 8) | ((__u32)(c) << 16) | ((__u32)(d) << 24))
>  #define v4l2_fourcc_be(a, b, c, d)	(v4l2_fourcc(a, b, c, d) | (1U << 31))
>  
> +/*
> + * Helper macros to print a fourcc in a standard format. E.g.:
> + *
> + * printf("fourcc is " V4L2_FOURCC_CONV "\n", V4L2_FOURCC_ARGS(fourcc));
> + *
> + * Note that V4L2_FOURCC_ARGS reuses fourcc, so this can't be an
> + * expression with side-effects.
> + */
> +#define V4L2_FOURCC_CONV "%c%c%c%c%s"
> +#define V4L2_FOURCC_ARGS(fourcc) \
> +	(fourcc) & 0x7f, ((fourcc) >> 8) & 0x7f, ((fourcc) >> 16) & 0x7f, \
> +	((fourcc) >> 24) & 0x7f, ((fourcc) & (1U << 31) ? "-BE" : "")
> +
>  /*
>   *	E N U M S
>   */

KernelDoc comments would be nice. Such as in here:

<URL:https://patchwork.linuxtv.org/patch/48372/>

I'm fine with either patch though.

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] v4l2-ioctl.c: use new V4L2_FOURCC_CONV/ARGS macros
  2019-09-16  9:00 ` [PATCH 2/2] v4l2-ioctl.c: use new V4L2_FOURCC_CONV/ARGS macros Hans Verkuil
@ 2019-09-16  9:27   ` Sakari Ailus
  0 siblings, 0 replies; 6+ messages in thread
From: Sakari Ailus @ 2019-09-16  9:27 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media, Dave Stevenson

On Mon, Sep 16, 2019 at 11:00:47AM +0200, Hans Verkuil wrote:
> Use these new standard macros to log the fourcc value in a
> human readable format.
> 
> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> ---
>  drivers/media/v4l2-core/v4l2-ioctl.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 51b912743f0f..80030533e1b8 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -1383,12 +1383,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
>  				return;
>  			WARN(1, "Unknown pixelformat 0x%08x\n", fmt->pixelformat);
>  			flags = 0;
> -			snprintf(fmt->description, sz, "%c%c%c%c%s",
> -					(char)(fmt->pixelformat & 0x7f),
> -					(char)((fmt->pixelformat >> 8) & 0x7f),
> -					(char)((fmt->pixelformat >> 16) & 0x7f),
> -					(char)((fmt->pixelformat >> 24) & 0x7f),
> -					(fmt->pixelformat & (1UL << 31)) ? "-BE" : "");
> +			snprintf(fmt->description, sz, V4L2_FOURCC_CONV,
> +				 V4L2_FOURCC_ARGS(fmt->pixelformat));
>  			break;
>  		}
>  	}

Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] videodev2.h: add macros to print a fourcc
  2019-09-16  9:26   ` Sakari Ailus
@ 2019-09-16  9:31     ` Hans Verkuil
  0 siblings, 0 replies; 6+ messages in thread
From: Hans Verkuil @ 2019-09-16  9:31 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: linux-media, Dave Stevenson

On 9/16/19 11:26 AM, Sakari Ailus wrote:
> Hi Hans,
> 
> On Mon, Sep 16, 2019 at 11:00:46AM +0200, Hans Verkuil wrote:
>> Add new macros V4L2_FOURCC_CONV and V4L2_FOURCC_ARGS for use
>> in code that prints a fourcc. These macros can be used in both
>> kernel and userspace.
>>
>> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
>> Suggested-by: Sakari Ailus <sakari.ailus@iki.fi>
>> ---
>>  include/uapi/linux/videodev2.h | 13 +++++++++++++
>>  1 file changed, 13 insertions(+)
>>
>> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
>> index 530638dffd93..7a34eb93437e 100644
>> --- a/include/uapi/linux/videodev2.h
>> +++ b/include/uapi/linux/videodev2.h
>> @@ -82,6 +82,19 @@
>>  	((__u32)(a) | ((__u32)(b) << 8) | ((__u32)(c) << 16) | ((__u32)(d) << 24))
>>  #define v4l2_fourcc_be(a, b, c, d)	(v4l2_fourcc(a, b, c, d) | (1U << 31))
>>  
>> +/*
>> + * Helper macros to print a fourcc in a standard format. E.g.:
>> + *
>> + * printf("fourcc is " V4L2_FOURCC_CONV "\n", V4L2_FOURCC_ARGS(fourcc));
>> + *
>> + * Note that V4L2_FOURCC_ARGS reuses fourcc, so this can't be an
>> + * expression with side-effects.
>> + */
>> +#define V4L2_FOURCC_CONV "%c%c%c%c%s"
>> +#define V4L2_FOURCC_ARGS(fourcc) \
>> +	(fourcc) & 0x7f, ((fourcc) >> 8) & 0x7f, ((fourcc) >> 16) & 0x7f, \
>> +	((fourcc) >> 24) & 0x7f, ((fourcc) & (1U << 31) ? "-BE" : "")
>> +
>>  /*
>>   *	E N U M S
>>   */
> 
> KernelDoc comments would be nice. Such as in here:
> 
> <URL:https://patchwork.linuxtv.org/patch/48372/>

I was searching for old patches with the string 'fourcc', not '4cc',
so that's why I missed your patch.

I'll respin with that (slightly updated) patch.

Regards,

	Hans

> 
> I'm fine with either patch though.
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-09-16  9:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-16  9:00 [PATCH 0/2] Add helper functions to print a fourcc Hans Verkuil
2019-09-16  9:00 ` [PATCH 1/2] videodev2.h: add macros " Hans Verkuil
2019-09-16  9:26   ` Sakari Ailus
2019-09-16  9:31     ` Hans Verkuil
2019-09-16  9:00 ` [PATCH 2/2] v4l2-ioctl.c: use new V4L2_FOURCC_CONV/ARGS macros Hans Verkuil
2019-09-16  9:27   ` Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).