git: a8c126b6903e - main - video: add V4L2 compat symbols for ffmpeg/opencv

Adrian Chadd <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a7ca6db.47e23.20efd083__33590.3717133746$1786554104$gmane$org@gitrepo.freebsd.org>
The branch main has been updated by adrian:

URL: https://cgit.FreeBSD.org/src/commit/?id=a8c126b6903e83a10a726019d3d347b20bfc86e3

commit a8c126b6903e83a10a726019d3d347b20bfc86e3
Author:     Abdelkader Boudih <[email protected]>
AuthorDate: 2026-08-12 16:52:04 +0000
Commit:     Adrian Chadd <[email protected]>
CommitDate: 2026-08-12 16:52:12 +0000

    video: add V4L2 compat symbols for ffmpeg/opencv
    
    Adds v4l2_std_id, struct v4l2_standard/v4l2_plane, VIDIOC_G_STD/S_STD/
    ENUMSTD, V4L2_STD_NTSC*, the MPLANE capability flag, multiplanar types
    (VIDEO_MAX_PLANES, v4l2_plane_pix_format, v4l2_pix_format_mplane,
    V4L2_TYPE_IS_MULTIPLANAR), V4L2_PIX_FMT_JPEG/YUV411P/SN9C10X, and the
    MPEG control class (V4L2_CID_MPEG_BASE, V4L2_CID_MPEG_VIDEO_B_FRAMES).
    
    video(4) capture devices are digital-only and never expose these, but
    ffmpeg's libavdevice/v4l2.c and opencv's cap_v4l.cpp both reference
    them unconditionally. Fixes their build against sys/videoio.h.
    
    PR:             297454
    
    Reviewed by:    manu, adrian
    Differential Revision:  https://reviews.freebsd.org/D58793
---
 sys/sys/videoio.h | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 101 insertions(+), 3 deletions(-)

diff --git a/sys/sys/videoio.h b/sys/sys/videoio.h
index bcf7ccaf8cb2..775ff68d699a 100644
--- a/sys/sys/videoio.h
+++ b/sys/sys/videoio.h
@@ -43,6 +43,8 @@
 #include <sys/ioccom.h>
 #include <sys/time.h>
 
+typedef u_int64_t v4l2_std_id;
+
 /*
  *  Four-character-code (FOURCC)
  */
@@ -193,12 +195,46 @@ struct v4l2_pix_format {
 	u_int32_t		xfer_func;	/* enum v4l2_xfer_func */
 };
 
+/*
+ *  Multi-planar capture (VIDIOC_*_MPLANE)
+ */
+#define VIDEO_MAX_PLANES	8
+
+struct v4l2_plane_pix_format {
+	u_int32_t	sizeimage;
+	u_int32_t	bytesperline;
+	u_int16_t	reserved[6];
+} __packed;
+
+struct v4l2_pix_format_mplane {
+	u_int32_t			width;
+	u_int32_t			height;
+	u_int32_t			pixelformat;
+	u_int32_t			field;
+	u_int32_t			colorspace;
+	struct v4l2_plane_pix_format	plane_fmt[VIDEO_MAX_PLANES];
+	u_int8_t			num_planes;
+	u_int8_t			flags;
+	union {
+		u_int8_t		ycbcr_enc;
+		u_int8_t		hsv_enc;
+	};
+	u_int8_t			quantization;
+	u_int8_t			xfer_func;
+	u_int8_t			reserved[7];
+} __packed;
+
+#define V4L2_TYPE_IS_MULTIPLANAR(type)				\
+	((type) == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||	\
+	 (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
+
 struct v4l2_format {
 	u_int32_t	type;
 	union {
-		struct v4l2_pix_format	pix;
-		void			*_align;
-		u_int8_t		raw_data[200];
+		struct v4l2_pix_format		pix;
+		struct v4l2_pix_format_mplane	pix_mp;
+		void				*_align;
+		u_int8_t			raw_data[200];
 	} fmt;
 };
 
@@ -237,6 +273,7 @@ struct v4l2_buffer {
 	union {
 		u_int32_t		offset;
 		unsigned long		userptr;
+		struct v4l2_plane	*planes;
 		int32_t			fd;
 	} m;
 	u_int32_t			length;
@@ -286,6 +323,27 @@ struct v4l2_input {
 	u_int32_t	reserved[3];
 };
 
+struct v4l2_standard {
+	u_int32_t		index;
+	v4l2_std_id		id;
+	u_int8_t		name[24];
+	struct v4l2_fract	frameperiod;
+	u_int32_t		framelines;
+	u_int32_t		reserved[4];
+};
+
+struct v4l2_plane {
+	u_int32_t	bytesused;
+	u_int32_t	length;
+	union {
+		u_int32_t	mem_offset;
+		unsigned long	userptr;
+		int32_t		fd;
+	} m;
+	u_int32_t	data_offset;
+	u_int32_t	reserved[11];
+};
+
 struct v4l2_control {
 	u_int32_t	id;
 	int32_t		value;
@@ -365,11 +423,21 @@ struct v4l2_frmivalenum {
 #define V4L2_PIX_FMT_M420	v4l2_fourcc('M', '4', '2', '0')
 #define V4L2_PIX_FMT_YVU420	v4l2_fourcc('Y', 'V', '1', '2')
 #define V4L2_PIX_FMT_YUV420	v4l2_fourcc('Y', 'U', '1', '2')
+#define V4L2_PIX_FMT_YUV410	v4l2_fourcc('Y', 'U', 'V', '9')
+#define V4L2_PIX_FMT_YVU410	v4l2_fourcc('Y', 'V', 'U', '9')
+#define V4L2_PIX_FMT_YUV422P	v4l2_fourcc('4', '2', '2', 'P')
 
 /* Compressed formats */
 #define V4L2_PIX_FMT_MJPEG	v4l2_fourcc('M', 'J', 'P', 'G')
+#define V4L2_PIX_FMT_JPEG	v4l2_fourcc('J', 'P', 'E', 'G')
 #define V4L2_PIX_FMT_H264	v4l2_fourcc('H', '2', '6', '4')
 #define V4L2_PIX_FMT_HEVC	v4l2_fourcc('H', 'E', 'V', 'C')
+#define V4L2_PIX_FMT_MPEG4	v4l2_fourcc('M', 'P', 'G', '4')
+#define V4L2_PIX_FMT_CPIA1	v4l2_fourcc('C', 'P', 'I', 'A')
+
+/* YUV411 planar and vendor webcam formats */
+#define V4L2_PIX_FMT_YUV411P	v4l2_fourcc('4', '1', '1', 'P')
+#define V4L2_PIX_FMT_SN9C10X	v4l2_fourcc('S', '9', '1', '0')
 
 /* Grey formats */
 #define V4L2_PIX_FMT_GREY	v4l2_fourcc('G', 'R', 'E', 'Y')
@@ -379,9 +447,17 @@ struct v4l2_frmivalenum {
 
 /* RGB formats */
 #define V4L2_PIX_FMT_RGB24	v4l2_fourcc('R', 'G', 'B', '3')
+#define V4L2_PIX_FMT_RGB555	v4l2_fourcc('R', 'G', 'B', 'O')
+#define V4L2_PIX_FMT_RGB555X	v4l2_fourcc('R', 'G', 'B', 'Q')
 #define V4L2_PIX_FMT_RGB565	v4l2_fourcc('R', 'G', 'B', 'P')
+#define V4L2_PIX_FMT_RGB565X	v4l2_fourcc('R', 'G', 'B', 'R')
 #define V4L2_PIX_FMT_BGR24	v4l2_fourcc('B', 'G', 'R', '3')
+#define V4L2_PIX_FMT_BGR32	v4l2_fourcc('B', 'G', 'R', '4')
+#define V4L2_PIX_FMT_RGB32	v4l2_fourcc('R', 'G', 'B', '4')
 #define V4L2_PIX_FMT_XBGR32	v4l2_fourcc('X', 'R', '2', '4')
+#define V4L2_PIX_FMT_ABGR32	v4l2_fourcc('A', 'R', '2', '4')
+#define V4L2_PIX_FMT_ARGB32	v4l2_fourcc('B', 'A', '2', '4')
+#define V4L2_PIX_FMT_XRGB32	v4l2_fourcc('B', 'X', '2', '4')
 
 /* Bayer formats */
 #define V4L2_PIX_FMT_SBGGR8	v4l2_fourcc('B', 'A', '8', '1')
@@ -401,6 +477,7 @@ struct v4l2_frmivalenum {
  *  Capability flags
  */
 #define V4L2_CAP_VIDEO_CAPTURE		0x00000001
+#define V4L2_CAP_VIDEO_CAPTURE_MPLANE	0x00001000
 #define V4L2_CAP_STREAMING		0x04000000
 #define V4L2_CAP_EXT_PIX_FORMAT		0x00200000
 #define V4L2_CAP_READWRITE		0x01000000
@@ -424,6 +501,7 @@ struct v4l2_frmivalenum {
  *  Format flags
  */
 #define V4L2_FMT_FLAG_COMPRESSED	0x0001
+#define V4L2_FMT_FLAG_EMULATED		0x0002
 
 /*
  *  Buffer capabilities
@@ -435,11 +513,28 @@ struct v4l2_frmivalenum {
  */
 #define V4L2_INPUT_TYPE_CAMERA		2
 
+/*
+ *  Analog TV standards
+ */
+#define V4L2_STD_NTSC_M		((v4l2_std_id)0x00001000)
+#define V4L2_STD_NTSC_M_JP	((v4l2_std_id)0x00002000)
+#define V4L2_STD_NTSC_443	((v4l2_std_id)0x00004000)
+#define V4L2_STD_NTSC_M_KR	((v4l2_std_id)0x00008000)
+#define V4L2_STD_NTSC		(V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | \
+				 V4L2_STD_NTSC_443 | V4L2_STD_NTSC_M_KR)
+
 /*
  *  Control IDs
  */
 #define V4L2_CTRL_CLASS_USER		0x00980000
+#define V4L2_CTRL_CLASS_MPEG		0x00990000
 #define V4L2_CID_BASE			(V4L2_CTRL_CLASS_USER | 0x900)
+
+/*
+ *  MPEG/codec control class
+ */
+#define V4L2_CID_MPEG_BASE		(V4L2_CTRL_CLASS_MPEG | 0x900)
+#define V4L2_CID_MPEG_VIDEO_B_FRAMES	(V4L2_CID_MPEG_BASE+14)
 #define V4L2_CID_BRIGHTNESS		(V4L2_CID_BASE + 0)
 #define V4L2_CID_CONTRAST		(V4L2_CID_BASE + 1)
 #define V4L2_CID_SATURATION		(V4L2_CID_BASE + 2)
@@ -483,6 +578,9 @@ struct v4l2_frmivalenum {
 #define VIDIOC_STREAMOFF	_IOW('V', 19, int)
 #define VIDIOC_G_PARM		_IOWR('V', 21, struct v4l2_streamparm)
 #define VIDIOC_S_PARM		_IOWR('V', 22, struct v4l2_streamparm)
+#define VIDIOC_G_STD		_IOR('V', 23, v4l2_std_id)
+#define VIDIOC_S_STD		_IOW('V', 24, v4l2_std_id)
+#define VIDIOC_ENUMSTD		_IOWR('V', 25, struct v4l2_standard)
 #define VIDIOC_ENUMINPUT	_IOWR('V', 26, struct v4l2_input)
 #define VIDIOC_G_CTRL		_IOWR('V', 27, struct v4l2_control)
 #define VIDIOC_S_CTRL		_IOWR('V', 28, struct v4l2_control)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.