Blob Blame History Raw
From 99067b14797a6877c3a98017c56e60c239930919 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Fri, 1 Nov 2019 02:00:53 +0100
Subject: [PATCH 80/86] v4l2: bundle struct v4l2_create_buffers definition

* configure.ac (AC_CHECK_TYPES): Add a check for
struct v4l2_create_buffers definition.
* v4l2.c (DEF_MPERS_TYPE(struct_v4l2_create_buffers)): Remove
VIDIOC_CREATE_BUFS guard.
(struct_v4l2_create_buffers): typedef to a structure definition and not
struct v4l2_create_buffers.
[HAVE_STRUCT_V4L2_CREATE_BUFFERS]: Check struct v4l2_create_buffers
with CHECK_V4L2_STRUCT_RESERVED_SIZE.
---
 configure.ac |  7 +++++++
 v4l2.c       | 25 ++++++++++++++++---------
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/configure.ac b/configure.ac
index 63f57f9..e47ba38 100644
--- a/configure.ac
+++ b/configure.ac
@@ -774,6 +774,13 @@ AC_CHECK_DECLS(m4_normalize([
 #include <linux/types.h>
 #include <linux/videodev2.h>])
 
+AC_CHECK_TYPES(m4_normalize([
+	struct v4l2_create_buffers
+]),,, [#include <sys/time.h>
+#include <linux/ioctl.h>
+#include <linux/types.h>
+#include <linux/videodev2.h>])
+
 AC_CHECK_MEMBERS(m4_normalize([
 	struct v4l2_capability.device_caps,
 	struct v4l2_ext_control.string,
diff --git a/v4l2.c b/v4l2.c
index b45f7f8..561aee2 100644
--- a/v4l2.c
+++ b/v4l2.c
@@ -35,9 +35,7 @@
 
 #include DEF_MPERS_TYPE(struct_v4l2_buffer)
 #include DEF_MPERS_TYPE(struct_v4l2_clip)
-#ifdef VIDIOC_CREATE_BUFS
-# include DEF_MPERS_TYPE(struct_v4l2_create_buffers)
-#endif
+#include DEF_MPERS_TYPE(struct_v4l2_create_buffers)
 #include DEF_MPERS_TYPE(struct_v4l2_ext_control)
 #include DEF_MPERS_TYPE(struct_v4l2_ext_controls)
 #include DEF_MPERS_TYPE(struct_v4l2_format)
@@ -47,9 +45,22 @@
 
 typedef struct v4l2_buffer struct_v4l2_buffer;
 typedef struct v4l2_clip struct_v4l2_clip;
-#ifdef VIDIOC_CREATE_BUFS
-typedef struct v4l2_create_buffers struct_v4l2_create_buffers;
+
+typedef struct {
+	uint32_t index;
+	uint32_t count;
+	uint32_t memory;
+	struct_v4l2_format format;
+	/** V4L2_BUF_CAP_SUPPORTS_*, added by Linux commit v4.20-rc1~51^2~14 */
+	uint32_t capabilities;
+	uint32_t reserved[7];
+} struct_v4l2_create_buffers;
+
+#ifdef HAVE_STRUCT_V4L2_CREATE_BUFFERS
+CHECK_V4L2_STRUCT_RESERVED_SIZE(v4l2_create_buffers);
 #endif
+
+
 typedef struct v4l2_ext_control struct_v4l2_ext_control;
 typedef struct v4l2_ext_controls struct_v4l2_ext_controls;
 typedef struct v4l2_format struct_v4l2_format;
@@ -967,7 +978,6 @@ print_v4l2_frmivalenum(struct tcb *const tcp, const kernel_ulong_t arg)
 }
 #endif /* VIDIOC_ENUM_FRAMEINTERVALS */
 
-#ifdef VIDIOC_CREATE_BUFS
 static int
 print_v4l2_create_buffers(struct tcb *const tcp, const kernel_ulong_t arg)
 {
@@ -999,7 +1009,6 @@ print_v4l2_create_buffers(struct tcb *const tcp, const kernel_ulong_t arg)
 
 	return RVAL_IOCTL_DECODED | RVAL_STR;
 }
-#endif /* VIDIOC_CREATE_BUFS */
 
 MPERS_PRINTER_DECL(int, v4l2_ioctl, struct tcb *const tcp,
 		   const unsigned int code, const kernel_ulong_t arg)
@@ -1102,10 +1111,8 @@ MPERS_PRINTER_DECL(int, v4l2_ioctl, struct tcb *const tcp,
 		return print_v4l2_frmivalenum(tcp, arg);
 #endif /* VIDIOC_ENUM_FRAMEINTERVALS */
 
-#ifdef VIDIOC_CREATE_BUFS
 	case VIDIOC_CREATE_BUFS: /* RW */
 		return print_v4l2_create_buffers(tcp, arg);
-#endif /* VIDIOC_CREATE_BUFS */
 
 	default:
 		return RVAL_DECODED;
-- 
2.1.4