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
11 11
12#include <linux/string.h>12#include <linux/string.h>
13#include <linux/kernel.h>13#include <linux/kernel.h>
14#include <linux/videodev2.h>
14#include "codec-fwht.h"15#include "codec-fwht.h"
15 16
16#define OVERFLOW_BIT BIT(14)17#define OVERFLOW_BIT BIT(14)
drivers/media/test-drivers/vicodec/codec-fwht.h+0−32
@@ -56,38 +56,6 @@ · 55 unmodified lines
56#define FWHT_MAGIC1 0x4f4f4f4f56#define FWHT_MAGIC1 0x4f4f4f4f
57#define FWHT_MAGIC2 0xffffffff57#define FWHT_MAGIC2 0xffffffff
58 58
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
91/*59/*
92 * A macro to calculate the needed padding in order to make sure60 * A macro to calculate the needed padding in order to make sure
93 * both luma and chroma components resolutions are rounded up to61 * 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
1746 V4L2_BUF_TYPE_VIDEO_CAPTURE);1746 V4L2_BUF_TYPE_VIDEO_CAPTURE);
1747 1747
1748 switch (ctrl->id) {1748 switch (ctrl->id) {
1749 case V4L2_CID_MPEG_VIDEO_FWHT_PARAMS:1749 case V4L2_CID_STATELESS_FWHT_PARAMS:
1750 if (!q_dst->info)1750 if (!q_dst->info)
1751 return -EINVAL;1751 return -EINVAL;
1752 params = ctrl->p_new.p_fwht_params;1752 params = ctrl->p_new.p_fwht_params;
@@ -1799,7 +1799,7 @@ static int vicodec_s_ctrl(struct v4l2_ctrl *ctrl) · 46 unmodified lines
1799 case V4L2_CID_FWHT_P_FRAME_QP:1799 case V4L2_CID_FWHT_P_FRAME_QP:
1800 ctx->state.p_frame_qp = ctrl->val;1800 ctx->state.p_frame_qp = ctrl->val;
1801 return 0;1801 return 0;
1802 case V4L2_CID_MPEG_VIDEO_FWHT_PARAMS:1802 case V4L2_CID_STATELESS_FWHT_PARAMS:
1803 params = ctrl->p_new.p_fwht_params;1803 params = ctrl->p_new.p_fwht_params;
1804 update_header_from_stateless_params(ctx, params);1804 update_header_from_stateless_params(ctx, params);
1805 ctx->state.ref_frame_ts = params->backward_ref_ts;1805 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
1815 1815
1816static const struct v4l2_ctrl_config vicodec_ctrl_stateless_state = {1816static const struct v4l2_ctrl_config vicodec_ctrl_stateless_state = {
1817 .ops = &vicodec_ctrl_ops,1817 .ops = &vicodec_ctrl_ops,
1818 .id = V4L2_CID_MPEG_VIDEO_FWHT_PARAMS,1818 .id = V4L2_CID_STATELESS_FWHT_PARAMS,
1819 .elem_size = sizeof(struct v4l2_ctrl_fwht_params),1819 .elem_size = sizeof(struct v4l2_ctrl_fwht_params),
1820};1820};
1821 1821
drivers/media/v4l2-core/v4l2-ctrls.c+18−2
@@ -943,7 +943,6 @@ const char *v4l2_ctrl_get_name(u32 id) · 942 unmodified lines
943 case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: return "Force Key Frame";943 case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: return "Force Key Frame";
944 case V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS: return "MPEG-2 Slice Parameters";944 case V4L2_CID_MPEG_VIDEO_MPEG2_SLICE_PARAMS: return "MPEG-2 Slice Parameters";
945 case V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION: return "MPEG-2 Quantization Matrices";945 case V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION: return "MPEG-2 Quantization Matrices";
946 case V4L2_CID_MPEG_VIDEO_FWHT_PARAMS: return "FWHT Stateless Parameters";
947 case V4L2_CID_FWHT_I_FRAME_QP: return "FWHT I-Frame QP Value";946 case V4L2_CID_FWHT_I_FRAME_QP: return "FWHT I-Frame QP Value";
948 case V4L2_CID_FWHT_P_FRAME_QP: return "FWHT P-Frame QP Value";947 case V4L2_CID_FWHT_P_FRAME_QP: return "FWHT P-Frame QP Value";
949 948
@@ -1185,6 +1184,7 @@ const char *v4l2_ctrl_get_name(u32 id) · 235 unmodified lines
1185 case V4L2_CID_STATELESS_H264_PRED_WEIGHTS: return "H264 Prediction Weight Table";1184 case V4L2_CID_STATELESS_H264_PRED_WEIGHTS: return "H264 Prediction Weight Table";
1186 case V4L2_CID_STATELESS_H264_SLICE_PARAMS: return "H264 Slice Parameters";1185 case V4L2_CID_STATELESS_H264_SLICE_PARAMS: return "H264 Slice Parameters";
1187 case V4L2_CID_STATELESS_H264_DECODE_PARAMS: return "H264 Decode Parameters";1186 case V4L2_CID_STATELESS_H264_DECODE_PARAMS: return "H264 Decode Parameters";
1187 case V4L2_CID_STATELESS_FWHT_PARAMS: return "FWHT Stateless Parameters";
1188 default:1188 default:
1189 return NULL;1189 return NULL;
1190 }1190 }
@@ -1433,7 +1433,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, · 242 unmodified lines
1433 case V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION:1433 case V4L2_CID_MPEG_VIDEO_MPEG2_QUANTIZATION:
1434 *type = V4L2_CTRL_TYPE_MPEG2_QUANTIZATION;1434 *type = V4L2_CTRL_TYPE_MPEG2_QUANTIZATION;
1435 break;1435 break;
1436 case V4L2_CID_MPEG_VIDEO_FWHT_PARAMS:1436 case V4L2_CID_STATELESS_FWHT_PARAMS:
1437 *type = V4L2_CTRL_TYPE_FWHT_PARAMS;1437 *type = V4L2_CTRL_TYPE_FWHT_PARAMS;
1438 break;1438 break;
1439 case V4L2_CID_STATELESS_H264_SPS:1439 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
1627{1627{
1628 struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;1628 struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
1629 struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;1629 struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
1630 struct v4l2_ctrl_fwht_params *p_fwht_params;
1630 void *p = ptr.p + idx * ctrl->elem_size;1631 void *p = ptr.p + idx * ctrl->elem_size;
1631 1632
1632 if (ctrl->p_def.p_const)1633 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
1653 p_vp8_frame_header = p;1654 p_vp8_frame_header = p;
1654 p_vp8_frame_header->num_dct_parts = 1;1655 p_vp8_frame_header->num_dct_parts = 1;
1655 break;1656 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;
1656 }1663 }
1657}1664}
1658 1665
@@ -1755,6 +1762,9 @@ static void std_log(const struct v4l2_ctrl *ctrl) · 96 unmodified lines
1755 case V4L2_CTRL_TYPE_H264_PRED_WEIGHTS:1762 case V4L2_CTRL_TYPE_H264_PRED_WEIGHTS:
1756 pr_cont("H264_PRED_WEIGHTS");1763 pr_cont("H264_PRED_WEIGHTS");
1757 break;1764 break;
1765 case V4L2_CTRL_TYPE_FWHT_PARAMS:
1766 pr_cont("FWHT_PARAMS");
1767 break;
1758 default:1768 default:
1759 pr_cont("unknown type %d", ctrl->type);1769 pr_cont("unknown type %d", ctrl->type);
1760 break;1770 break;
@@ -1798,6 +1808,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx, · 37 unmodified lines
1798{1808{
1799 struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;1809 struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
1800 struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;1810 struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
1811 struct v4l2_ctrl_fwht_params *p_fwht_params;
1801 struct v4l2_ctrl_h264_sps *p_h264_sps;1812 struct v4l2_ctrl_h264_sps *p_h264_sps;
1802 struct v4l2_ctrl_h264_pps *p_h264_pps;1813 struct v4l2_ctrl_h264_pps *p_h264_pps;
1803 struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;1814 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
1857 break;1868 break;
1858 1869
1859 case V4L2_CTRL_TYPE_FWHT_PARAMS:1870 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;
1860 break;1876 break;
1861 1877
1862 case V4L2_CTRL_TYPE_H264_SPS:1878 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
18struct 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
18 * This will move to the public headers once this API is fully stable.18 * This will move to the public headers once this API is fully stable.
19 */19 */
20#include <media/mpeg2-ctrls.h>20#include <media/mpeg2-ctrls.h>
21#include <media/fwht-ctrls.h>
22#include <media/vp8-ctrls.h>21#include <media/vp8-ctrls.h>
23#include <media/hevc-ctrls.h>22#include <media/hevc-ctrls.h>
24 23
include/uapi/linux/v4l2-controls.h+70−0
@@ -1565,6 +1565,76 @@ struct v4l2_ctrl_h264_decode_params { · 1564 unmodified lines
1565};1565};
1566 1566
1567 1567
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 */
1626struct 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
1568/* MPEG-compression definitions kept for backwards compatibility */1638/* MPEG-compression definitions kept for backwards compatibility */
1569#ifndef __KERNEL__1639#ifndef __KERNEL__
1570#define V4L2_CTRL_CLASS_MPEG V4L2_CTRL_CLASS_CODEC1640#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
1740 struct v4l2_ctrl_h264_pred_weights __user *p_h264_pred_weights;1740 struct v4l2_ctrl_h264_pred_weights __user *p_h264_pred_weights;
1741 struct v4l2_ctrl_h264_slice_params __user *p_h264_slice_params;1741 struct v4l2_ctrl_h264_slice_params __user *p_h264_slice_params;
1742 struct v4l2_ctrl_h264_decode_params __user *p_h264_decode_params;1742 struct v4l2_ctrl_h264_decode_params __user *p_h264_decode_params;
1743 struct v4l2_ctrl_fwht_params __user *p_fwht_params;
1743 void __user *ptr;1744 void __user *ptr;
1744 };1745 };
1745} __attribute__ ((packed));1746} __attribute__ ((packed));
@@ -1793,6 +1794,8 @@ enum v4l2_ctrl_type { · 47 unmodified lines
1793 V4L2_CTRL_TYPE_H264_SLICE_PARAMS = 0x0203,1794 V4L2_CTRL_TYPE_H264_SLICE_PARAMS = 0x0203,
1794 V4L2_CTRL_TYPE_H264_DECODE_PARAMS = 0x0204,1795 V4L2_CTRL_TYPE_H264_DECODE_PARAMS = 0x0204,
1795 V4L2_CTRL_TYPE_H264_PRED_WEIGHTS = 0x0205,1796 V4L2_CTRL_TYPE_H264_PRED_WEIGHTS = 0x0205,
1797
1798 V4L2_CTRL_TYPE_FWHT_PARAMS = 0x0220,
1796};1799};
1797 1800
1798/* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */1801/* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */