[PATCH 1/2] videodev2.h: add macros to print a fourcc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
Suggested-by: Sakari Ailus <sakari.ailus@xxxxxx>
---
 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




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux