History

media: vicodec: mark the stateless FWHT API as stable

The FWHT stateless 'uAPI' was staging and marked explicitly in the V4L2 specification that it will change and is unstable. Note that these control IDs were never exported as a public API, they were only defined in kernel-local headers (fwht-ctrls.h). Now, the FWHT stateless controls is ready to be part of the stable uAPI. While not too late: - Rename V4L2_CID_MPEG_VIDEO_FWHT_PARAMS to V4L2_CID_STATELESS_FWHT_PARAMS. - Move the contents of fwht-ctrls.h to v4l2-controls.h. - Move the public parts of drivers/media/test-drivers/vicodec/codec-fwht.h to v4l2-controls.h. - Add V4L2_CTRL_TYPE_FWHT_PARAMS control initialization and validation. - Add p_fwht_params to struct v4l2_ext_control.

Hans Verkuil committed 5 years ago

Commit 206bc0f1 parent 3abfc318 files · +95 −69Browse files

Unified · Split

8 files
  1. drivers/media/test-drivers/vicodec/codec-fwht.c +1 −0
  2. drivers/media/test-drivers/vicodec/codec-fwht.h +0 −32
  3. drivers/media/test-drivers/vicodec/vicodec-core.c +3 −3
  4. drivers/media/v4l2-core/v4l2-ctrls.c +18 −2
  5. include/media/fwht-ctrls.h +0 −31
  6. include/media/v4l2-ctrls.h +0 −1
  7. include/uapi/linux/v4l2-controls.h +70 −0
  8. include/uapi/linux/videodev2.h +3 −0
drivers/media/test-drivers/vicodec/codec-fwht.c+1−0
@@ -11,6 +11,7 @@ · 10 unmodified lines
1111
1212 #include <linux/string.h>
1313 #include <linux/kernel.h>
14+#include <linux/videodev2.h>
1415 #include "codec-fwht.h"
1516
1617 #define OVERFLOW_BIT BIT(14)
drivers/media/test-drivers/vicodec/codec-fwht.h+0−32
@@ -56,38 +56,6 @@ · 55 unmodified lines
5656 #define FWHT_MAGIC1 0x4f4f4f4f
5757 #define FWHT_MAGIC2 0xffffffff
5858
59−#define V4L2_FWHT_VERSION 3
60−
61−/* Set if this is an interlaced format */
62−#define V4L2_FWHT_FL_IS_INTERLACED BIT(0)
63−/* Set if this is a bottom-first (NTSC) interlaced format */
64−#define V4L2_FWHT_FL_IS_BOTTOM_FIRST BIT(1)
65−/* Set if each 'frame' contains just one field */
66−#define V4L2_FWHT_FL_IS_ALTERNATE BIT(2)
67−/*
68− * If V4L2_FWHT_FL_IS_ALTERNATE was set, then this is set if this
69− * 'frame' is the bottom field, else it is the top field.
70− */
71−#define V4L2_FWHT_FL_IS_BOTTOM_FIELD BIT(3)
72−/* Set if this frame is uncompressed */
73−#define V4L2_FWHT_FL_LUMA_IS_UNCOMPRESSED BIT(4)
74−#define V4L2_FWHT_FL_CB_IS_UNCOMPRESSED BIT(5)
75−#define V4L2_FWHT_FL_CR_IS_UNCOMPRESSED BIT(6)
76−#define V4L2_FWHT_FL_CHROMA_FULL_HEIGHT BIT(7)
77−#define V4L2_FWHT_FL_CHROMA_FULL_WIDTH BIT(8)
78−#define V4L2_FWHT_FL_ALPHA_IS_UNCOMPRESSED BIT(9)
79−#define V4L2_FWHT_FL_I_FRAME BIT(10)
80−
81−/* A 4-values flag - the number of components - 1 */
82−#define V4L2_FWHT_FL_COMPONENTS_NUM_MSK GENMASK(18, 16)
83−#define V4L2_FWHT_FL_COMPONENTS_NUM_OFFSET 16
84−
85−#define V4L2_FWHT_FL_PIXENC_MSK GENMASK(20, 19)
86−#define V4L2_FWHT_FL_PIXENC_OFFSET 19
87−#define V4L2_FWHT_FL_PIXENC_YUV (1 << V4L2_FWHT_FL_PIXENC_OFFSET)
88−#define V4L2_FWHT_FL_PIXENC_RGB (2 << V4L2_FWHT_FL_PIXENC_OFFSET)
89−#define V4L2_FWHT_FL_PIXENC_HSV (3 << V4L2_FWHT_FL_PIXENC_OFFSET)
90−
9159 /*
9260 * A macro to calculate the needed padding in order to make sure
9361 * both luma and chroma components resolutions are rounded up to
drivers/media/test-drivers/vicodec/vicodec-core.c+3−3
@@ -1746,7 +1746,7 @@ static int vicodec_try_ctrl(struct v4l2_ctrl *ctrl) · 1745 unmodified lines
17461746 V4L2_BUF_TYPE_VIDEO_CAPTURE);
17471747
17481748 switch (ctrl->id) {
1749− case V4L2_CID_MPEG_VIDEO_FWHT_PARAMS:
1749+ case V4L2_CID_STATELESS_FWHT_PARAMS:
17501750 if (!q_dst->info)
17511751 return -EINVAL;
17521752 params = ctrl->p_new.p_fwht_params;
@@ -1799,7 +1799,7 @@ static int vicodec_s_ctrl(struct v4l2_ctrl *ctrl) · 46 unmodified lines
17991799 case V4L2_CID_FWHT_P_FRAME_QP:
18001800 ctx->state.p_frame_qp = ctrl->val;
18011801 return 0;
1802− case V4L2_CID_MPEG_VIDEO_FWHT_PARAMS:
1802+ case V4L2_CID_STATELESS_FWHT_PARAMS:
18031803 params = ctrl->p_new.p_fwht_params;
18041804 update_header_from_stateless_params(ctx, params);
18051805 ctx->state.ref_frame_ts = params->backward_ref_ts;
@@ -1815,7 +1815,7 @@ static const struct v4l2_ctrl_ops vicodec_ctrl_ops = { · 9 unmodified lines
18151815
18161816 static const struct v4l2_ctrl_config vicodec_ctrl_stateless_state = {
18171817 .ops = &vicodec_ctrl_ops,
1818− .id = V4L2_CID_MPEG_VIDEO_FWHT_PARAMS,
1818+ .id = V4L2_CID_STATELESS_FWHT_PARAMS,
18191819 .elem_size = sizeof(struct v4l2_ctrl_fwht_params),
18201820 };
18211821
drivers/media/v4l2-core/v4l2-ctrls.c+18−2
@@ -943,7 +943,6 @@ const char *v4l2_ctrl_get_name(u32 id) · 942 unmodified lines
943943 case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: return "Force Key Frame";
944944 case V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS: return "MPEG-2 Slice Parameters";
945945 case V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION: return "MPEG-2 Quantization Matrices";
946− case V4L2_CID_MPEG_VIDEO_FWHT_PARAMS: return "FWHT Stateless Parameters";
947946 case V4L2_CID_FWHT_I_FRAME_QP: return "FWHT I-Frame QP Value";
948947 case V4L2_CID_FWHT_P_FRAME_QP: return "FWHT P-Frame QP Value";
949948
@@ -1185,6 +1184,7 @@ const char *v4l2_ctrl_get_name(u32 id) · 235 unmodified lines
11851184 case V4L2_CID_STATELESS_H264_PRED_WEIGHTS: return "H264 Prediction Weight Table";
11861185 case V4L2_CID_STATELESS_H264_SLICE_PARAMS: return "H264 Slice Parameters";
11871186 case V4L2_CID_STATELESS_H264_DECODE_PARAMS: return "H264 Decode Parameters";
1187+ case V4L2_CID_STATELESS_FWHT_PARAMS: return "FWHT Stateless Parameters";
11881188 default:
11891189 return NULL;
11901190 }
@@ -1433,7 +1433,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, · 242 unmodified lines
14331433 case V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION:
14341434 *type = V4L2_CTRL_TYPE_MPEG2_QUANTIZATION;
14351435 break;
1436− case V4L2_CID_MPEG_VIDEO_FWHT_PARAMS:
1436+ case V4L2_CID_STATELESS_FWHT_PARAMS:
14371437 *type = V4L2_CTRL_TYPE_FWHT_PARAMS;
14381438 break;
14391439 case V4L2_CID_STATELESS_H264_SPS:
@@ -1627,6 +1627,7 @@ static void std_init_compound(const struct v4l2_ctrl *ctrl, u32 idx, · 187 unmodified lines
16271627 {
16281628 struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
16291629 struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
1630+ struct v4l2_ctrl_fwht_params *p_fwht_params;
16301631 void *p = ptr.p + idx * ctrl->elem_size;
16311632
16321633 if (ctrl->p_def.p_const)
@@ -1653,6 +1654,12 @@ static void std_init_compound(const struct v4l2_ctrl *ctrl, u32 idx, · 20 unmodified lines
16531654 p_vp8_frame_header = p;
16541655 p_vp8_frame_header->num_dct_parts = 1;
16551656 break;
1657+ case V4L2_CTRL_TYPE_FWHT_PARAMS:
1658+ p_fwht_params = p;
1659+ p_fwht_params->version = V4L2_FWHT_VERSION;
1660+ p_fwht_params->width = 1280;
1661+ p_fwht_params->height = 720;
1662+ break;
16561663 }
16571664 }
16581665
@@ -1755,6 +1762,9 @@ static void std_log(const struct v4l2_ctrl *ctrl) · 96 unmodified lines
17551762 case V4L2_CTRL_TYPE_H264_PRED_WEIGHTS:
17561763 pr_cont("H264_PRED_WEIGHTS");
17571764 break;
1765+ case V4L2_CTRL_TYPE_FWHT_PARAMS:
1766+ pr_cont("FWHT_PARAMS");
1767+ break;
17581768 default:
17591769 pr_cont("unknown type %d", ctrl->type);
17601770 break;
@@ -1798,6 +1808,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx, · 37 unmodified lines
17981808 {
17991809 struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
18001810 struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
1811+ struct v4l2_ctrl_fwht_params *p_fwht_params;
18011812 struct v4l2_ctrl_h264_sps *p_h264_sps;
18021813 struct v4l2_ctrl_h264_pps *p_h264_pps;
18031814 struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;
@@ -1857,6 +1868,11 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx, · 53 unmodified lines
18571868 break;
18581869
18591870 case V4L2_CTRL_TYPE_FWHT_PARAMS:
1871+ p_fwht_params = p;
1872+ if (p_fwht_params->version < V4L2_FWHT_VERSION)
1873+ return -EINVAL;
1874+ if (!p_fwht_params->width || !p_fwht_params->height)
1875+ return -EINVAL;
18601876 break;
18611877
18621878 case V4L2_CTRL_TYPE_H264_SPS:
include/media/fwht-ctrls.h+0−31
@@ -1,31 +0,0 @@
1−/* SPDX-License-Identifier: GPL-2.0 */
2−/*
3− * These are the FWHT state controls for use with stateless FWHT
4− * codec drivers.
5− *
6− * It turns out that these structs are not stable yet and will undergo
7− * more changes. So keep them private until they are stable and ready to
8− * become part of the official public API.
9− */
10−
11−#ifndef _FWHT_CTRLS_H_
12−#define _FWHT_CTRLS_H_
13−
14−#define V4L2_CTRL_TYPE_FWHT_PARAMS 0x0105
15−
16−#define V4L2_CID_MPEG_VIDEO_FWHT_PARAMS (V4L2_CID_CODEC_BASE + 292)
17−
18−struct v4l2_ctrl_fwht_params {
19− __u64 backward_ref_ts;
20− __u32 version;
21− __u32 width;
22− __u32 height;
23− __u32 flags;
24− __u32 colorspace;
25− __u32 xfer_func;
26− __u32 ycbcr_enc;
27− __u32 quantization;
28−};
29−
30−
31−#endif
include/media/v4l2-ctrls.h+0−1
@@ -18,7 +18,6 @@ · 17 unmodified lines
1818 * This will move to the public headers once this API is fully stable.
1919 */
2020 #include <media/mpeg2-ctrls.h>
21−#include <media/fwht-ctrls.h>
2221 #include <media/vp8-ctrls.h>
2322 #include <media/hevc-ctrls.h>
2423
include/uapi/linux/v4l2-controls.h+70−0
@@ -1565,6 +1565,76 @@ struct v4l2_ctrl_h264_decode_params { · 1564 unmodified lines
15651565 };
15661566
15671567
1568+/* Stateless FWHT control, used by the vicodec driver */
1569+
1570+/* Current FWHT version */
1571+#define V4L2_FWHT_VERSION 3
1572+
1573+/* Set if this is an interlaced format */
1574+#define V4L2_FWHT_FL_IS_INTERLACED BIT(0)
1575+/* Set if this is a bottom-first (NTSC) interlaced format */
1576+#define V4L2_FWHT_FL_IS_BOTTOM_FIRST BIT(1)
1577+/* Set if each 'frame' contains just one field */
1578+#define V4L2_FWHT_FL_IS_ALTERNATE BIT(2)
1579+/*
1580+ * If V4L2_FWHT_FL_IS_ALTERNATE was set, then this is set if this
1581+ * 'frame' is the bottom field, else it is the top field.
1582+ */
1583+#define V4L2_FWHT_FL_IS_BOTTOM_FIELD BIT(3)
1584+/* Set if the Y' plane is uncompressed */
1585+#define V4L2_FWHT_FL_LUMA_IS_UNCOMPRESSED BIT(4)
1586+/* Set if the Cb plane is uncompressed */
1587+#define V4L2_FWHT_FL_CB_IS_UNCOMPRESSED BIT(5)
1588+/* Set if the Cr plane is uncompressed */
1589+#define V4L2_FWHT_FL_CR_IS_UNCOMPRESSED BIT(6)
1590+/* Set if the chroma plane is full height, if cleared it is half height */
1591+#define V4L2_FWHT_FL_CHROMA_FULL_HEIGHT BIT(7)
1592+/* Set if the chroma plane is full width, if cleared it is half width */
1593+#define V4L2_FWHT_FL_CHROMA_FULL_WIDTH BIT(8)
1594+/* Set if the alpha plane is uncompressed */
1595+#define V4L2_FWHT_FL_ALPHA_IS_UNCOMPRESSED BIT(9)
1596+/* Set if this is an I Frame */
1597+#define V4L2_FWHT_FL_I_FRAME BIT(10)
1598+
1599+/* A 4-values flag - the number of components - 1 */
1600+#define V4L2_FWHT_FL_COMPONENTS_NUM_MSK GENMASK(18, 16)
1601+#define V4L2_FWHT_FL_COMPONENTS_NUM_OFFSET 16
1602+
1603+/* A 4-values flag - the pixel encoding type */
1604+#define V4L2_FWHT_FL_PIXENC_MSK GENMASK(20, 19)
1605+#define V4L2_FWHT_FL_PIXENC_OFFSET 19
1606+#define V4L2_FWHT_FL_PIXENC_YUV (1 << V4L2_FWHT_FL_PIXENC_OFFSET)
1607+#define V4L2_FWHT_FL_PIXENC_RGB (2 << V4L2_FWHT_FL_PIXENC_OFFSET)
1608+#define V4L2_FWHT_FL_PIXENC_HSV (3 << V4L2_FWHT_FL_PIXENC_OFFSET)
1609+
1610+#define V4L2_CID_STATELESS_FWHT_PARAMS (V4L2_CID_CODEC_STATELESS_BASE + 100)
1611+/**
1612+ * struct v4l2_ctrl_fwht_params - FWHT parameters
1613+ *
1614+ * @backward_ref_ts: timestamp of the V4L2 capture buffer to use as reference.
1615+ * The timestamp refers to the timestamp field in struct v4l2_buffer.
1616+ * Use v4l2_timeval_to_ns() to convert the struct timeval to a __u64.
1617+ * @version: must be V4L2_FWHT_VERSION.
1618+ * @width: width of frame.
1619+ * @height: height of frame.
1620+ * @flags: FWHT flags (see V4L2_FWHT_FL_*).
1621+ * @colorspace: the colorspace (enum v4l2_colorspace).
1622+ * @xfer_func: the transfer function (enum v4l2_xfer_func).
1623+ * @ycbcr_enc: the Y'CbCr encoding (enum v4l2_ycbcr_encoding).
1624+ * @quantization: the quantization (enum v4l2_quantization).
1625+ */
1626+struct v4l2_ctrl_fwht_params {
1627+ __u64 backward_ref_ts;
1628+ __u32 version;
1629+ __u32 width;
1630+ __u32 height;
1631+ __u32 flags;
1632+ __u32 colorspace;
1633+ __u32 xfer_func;
1634+ __u32 ycbcr_enc;
1635+ __u32 quantization;
1636+};
1637+
15681638 /* MPEG-compression definitions kept for backwards compatibility */
15691639 #ifndef __KERNEL__
15701640 #define V4L2_CTRL_CLASS_MPEG V4L2_CTRL_CLASS_CODEC
include/uapi/linux/videodev2.h+3−0
@@ -1740,6 +1740,7 @@ struct v4l2_ext_control { · 1739 unmodified lines
17401740 struct v4l2_ctrl_h264_pred_weights __user *p_h264_pred_weights;
17411741 struct v4l2_ctrl_h264_slice_params __user *p_h264_slice_params;
17421742 struct v4l2_ctrl_h264_decode_params __user *p_h264_decode_params;
1743+ struct v4l2_ctrl_fwht_params __user *p_fwht_params;
17431744 void __user *ptr;
17441745 };
17451746 } __attribute__ ((packed));
@@ -1793,6 +1794,8 @@ enum v4l2_ctrl_type { · 47 unmodified lines
17931794 V4L2_CTRL_TYPE_H264_SLICE_PARAMS = 0x0203,
17941795 V4L2_CTRL_TYPE_H264_DECODE_PARAMS = 0x0204,
17951796 V4L2_CTRL_TYPE_H264_PRED_WEIGHTS = 0x0205,
1797+
1798+ V4L2_CTRL_TYPE_FWHT_PARAMS = 0x0220,
17961799 };
17971800
17981801 /* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */