Commit b88dbe38 authored by Andrzej Pietrasiewicz's avatar Andrzej Pietrasiewicz Committed by Mauro Carvalho Chehab

media: uapi: Add VP9 stateless decoder controls

Add the VP9 stateless decoder controls plus the documentation that goes
with it.
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@collabora.com>
Co-developed-by: default avatarEzequiel Garcia <ezequiel@collabora.com>
Signed-off-by: default avatarEzequiel Garcia <ezequiel@collabora.com>
Signed-off-by: default avatarAdrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: default avatarAndrzej Pietrasiewicz <andrzej.p@collabora.com>
Co-developed-by: default avatarDaniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: default avatarDaniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent bb91e46e
......@@ -417,3 +417,13 @@ VP8
:title: RFC 6386: "VP8 Data Format and Decoding Guide"
:author: J. Bankoski et al.
.. _vp9:
VP9
===
:title: VP9 Bitstream & Decoding Process Specification
:author: Adrian Grange (Google), Peter de Rivaz (Argon Design), Jonathan Hunt (Argon Design)
......@@ -172,6 +172,21 @@ Compressed Formats
- VP9 compressed video frame. The encoder generates one
compressed frame per buffer, and the decoder requires one
compressed frame per buffer.
* .. _V4L2-PIX-FMT-VP9-FRAME:
- ``V4L2_PIX_FMT_VP9_FRAME``
- 'VP9F'
- VP9 parsed frame, including the frame header, as extracted from the container.
This format is adapted for stateless video decoders that implement a
VP9 pipeline with the :ref:`stateless_decoder`.
Metadata associated with the frame to decode is required to be passed
through the ``V4L2_CID_STATELESS_VP9_FRAME`` and
the ``V4L2_CID_STATELESS_VP9_COMPRESSED_HDR`` controls.
See the :ref:`associated Codec Control IDs <v4l2-codec-stateless-vp9>`.
Exactly one output and one capture buffer must be provided for use with
this pixel format. The output buffer must contain the appropriate number
of macroblocks to decode a full corresponding frame to the matching
capture buffer.
* .. _V4L2-PIX-FMT-HEVC:
- ``V4L2_PIX_FMT_HEVC``
......
......@@ -233,6 +233,14 @@ still cause this situation.
- ``p_mpeg2_quantisation``
- A pointer to a struct :c:type:`v4l2_ctrl_mpeg2_quantisation`. Valid if this control is
of type ``V4L2_CTRL_TYPE_MPEG2_QUANTISATION``.
* - struct :c:type:`v4l2_ctrl_vp9_compressed_hdr` *
- ``p_vp9_compressed_hdr_probs``
- A pointer to a struct :c:type:`v4l2_ctrl_vp9_compressed_hdr`. Valid if this
control is of type ``V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR``.
* - struct :c:type:`v4l2_ctrl_vp9_frame` *
- ``p_vp9_frame``
- A pointer to a struct :c:type:`v4l2_ctrl_vp9_frame`. Valid if this
control is of type ``V4L2_CTRL_TYPE_VP9_FRAME``.
* - struct :c:type:`v4l2_ctrl_hdr10_cll_info` *
- ``p_hdr10_cll``
- A pointer to a struct :c:type:`v4l2_ctrl_hdr10_cll_info`. Valid if this control is
......
......@@ -513,6 +513,18 @@ See also the examples in :ref:`control`.
- n/a
- A struct :c:type:`v4l2_ctrl_hevc_decode_params`, containing HEVC
decoding parameters for stateless video decoders.
* - ``V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR``
- n/a
- n/a
- n/a
- A struct :c:type:`v4l2_ctrl_vp9_compressed_hdr`, containing VP9
probabilities updates for stateless video decoders.
* - ``V4L2_CTRL_TYPE_VP9_FRAME``
- n/a
- n/a
- n/a
- A struct :c:type:`v4l2_ctrl_vp9_frame`, containing VP9
frame decode parameters for stateless video decoders.
.. raw:: latex
......
......@@ -149,6 +149,8 @@ replace symbol V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS :c:type:`v4l2_ctrl_type`
replace symbol V4L2_CTRL_TYPE_AREA :c:type:`v4l2_ctrl_type`
replace symbol V4L2_CTRL_TYPE_FWHT_PARAMS :c:type:`v4l2_ctrl_type`
replace symbol V4L2_CTRL_TYPE_VP8_FRAME :c:type:`v4l2_ctrl_type`
replace symbol V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR :c:type:`v4l2_ctrl_type`
replace symbol V4L2_CTRL_TYPE_VP9_FRAME :c:type:`v4l2_ctrl_type`
replace symbol V4L2_CTRL_TYPE_HDR10_CLL_INFO :c:type:`v4l2_ctrl_type`
replace symbol V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY :c:type:`v4l2_ctrl_type`
......
......@@ -283,6 +283,12 @@ static void std_log(const struct v4l2_ctrl *ctrl)
case V4L2_CTRL_TYPE_MPEG2_PICTURE:
pr_cont("MPEG2_PICTURE");
break;
case V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR:
pr_cont("VP9_COMPRESSED_HDR");
break;
case V4L2_CTRL_TYPE_VP9_FRAME:
pr_cont("VP9_FRAME");
break;
default:
pr_cont("unknown type %d", ctrl->type);
break;
......@@ -317,6 +323,168 @@ static void std_log(const struct v4l2_ctrl *ctrl)
#define zero_reserved(s) \
memset(&(s).reserved, 0, sizeof((s).reserved))
static int
validate_vp9_lf_params(struct v4l2_vp9_loop_filter *lf)
{
unsigned int i;
if (lf->flags & ~(V4L2_VP9_LOOP_FILTER_FLAG_DELTA_ENABLED |
V4L2_VP9_LOOP_FILTER_FLAG_DELTA_UPDATE))
return -EINVAL;
/* That all values are in the accepted range. */
if (lf->level > GENMASK(5, 0))
return -EINVAL;
if (lf->sharpness > GENMASK(2, 0))
return -EINVAL;
for (i = 0; i < ARRAY_SIZE(lf->ref_deltas); i++)
if (lf->ref_deltas[i] < -63 || lf->ref_deltas[i] > 63)
return -EINVAL;
for (i = 0; i < ARRAY_SIZE(lf->mode_deltas); i++)
if (lf->mode_deltas[i] < -63 || lf->mode_deltas[i] > 63)
return -EINVAL;
zero_reserved(*lf);
return 0;
}
static int
validate_vp9_quant_params(struct v4l2_vp9_quantization *quant)
{
if (quant->delta_q_y_dc < -15 || quant->delta_q_y_dc > 15 ||
quant->delta_q_uv_dc < -15 || quant->delta_q_uv_dc > 15 ||
quant->delta_q_uv_ac < -15 || quant->delta_q_uv_ac > 15)
return -EINVAL;
zero_reserved(*quant);
return 0;
}
static int
validate_vp9_seg_params(struct v4l2_vp9_segmentation *seg)
{
unsigned int i, j;
if (seg->flags & ~(V4L2_VP9_SEGMENTATION_FLAG_ENABLED |
V4L2_VP9_SEGMENTATION_FLAG_UPDATE_MAP |
V4L2_VP9_SEGMENTATION_FLAG_TEMPORAL_UPDATE |
V4L2_VP9_SEGMENTATION_FLAG_UPDATE_DATA |
V4L2_VP9_SEGMENTATION_FLAG_ABS_OR_DELTA_UPDATE))
return -EINVAL;
for (i = 0; i < ARRAY_SIZE(seg->feature_enabled); i++) {
if (seg->feature_enabled[i] &
~V4L2_VP9_SEGMENT_FEATURE_ENABLED_MASK)
return -EINVAL;
}
for (i = 0; i < ARRAY_SIZE(seg->feature_data); i++) {
const int range[] = { 255, 63, 3, 0 };
for (j = 0; j < ARRAY_SIZE(seg->feature_data[j]); j++) {
if (seg->feature_data[i][j] < -range[j] ||
seg->feature_data[i][j] > range[j])
return -EINVAL;
}
}
zero_reserved(*seg);
return 0;
}
static int
validate_vp9_compressed_hdr(struct v4l2_ctrl_vp9_compressed_hdr *hdr)
{
if (hdr->tx_mode > V4L2_VP9_TX_MODE_SELECT)
return -EINVAL;
return 0;
}
static int
validate_vp9_frame(struct v4l2_ctrl_vp9_frame *frame)
{
int ret;
/* Make sure we're not passed invalid flags. */
if (frame->flags & ~(V4L2_VP9_FRAME_FLAG_KEY_FRAME |
V4L2_VP9_FRAME_FLAG_SHOW_FRAME |
V4L2_VP9_FRAME_FLAG_ERROR_RESILIENT |
V4L2_VP9_FRAME_FLAG_INTRA_ONLY |
V4L2_VP9_FRAME_FLAG_ALLOW_HIGH_PREC_MV |
V4L2_VP9_FRAME_FLAG_REFRESH_FRAME_CTX |
V4L2_VP9_FRAME_FLAG_PARALLEL_DEC_MODE |
V4L2_VP9_FRAME_FLAG_X_SUBSAMPLING |
V4L2_VP9_FRAME_FLAG_Y_SUBSAMPLING |
V4L2_VP9_FRAME_FLAG_COLOR_RANGE_FULL_SWING))
return -EINVAL;
if (frame->flags & V4L2_VP9_FRAME_FLAG_ERROR_RESILIENT &&
frame->flags & V4L2_VP9_FRAME_FLAG_REFRESH_FRAME_CTX)
return -EINVAL;
if (frame->profile > V4L2_VP9_PROFILE_MAX)
return -EINVAL;
if (frame->reset_frame_context > V4L2_VP9_RESET_FRAME_CTX_ALL)
return -EINVAL;
if (frame->frame_context_idx >= V4L2_VP9_NUM_FRAME_CTX)
return -EINVAL;
/*
* Profiles 0 and 1 only support 8-bit depth, profiles 2 and 3 only 10
* and 12 bit depths.
*/
if ((frame->profile < 2 && frame->bit_depth != 8) ||
(frame->profile >= 2 &&
(frame->bit_depth != 10 && frame->bit_depth != 12)))
return -EINVAL;
/* Profile 0 and 2 only accept YUV 4:2:0. */
if ((frame->profile == 0 || frame->profile == 2) &&
(!(frame->flags & V4L2_VP9_FRAME_FLAG_X_SUBSAMPLING) ||
!(frame->flags & V4L2_VP9_FRAME_FLAG_Y_SUBSAMPLING)))
return -EINVAL;
/* Profile 1 and 3 only accept YUV 4:2:2, 4:4:0 and 4:4:4. */
if ((frame->profile == 1 || frame->profile == 3) &&
((frame->flags & V4L2_VP9_FRAME_FLAG_X_SUBSAMPLING) &&
(frame->flags & V4L2_VP9_FRAME_FLAG_Y_SUBSAMPLING)))
return -EINVAL;
if (frame->interpolation_filter > V4L2_VP9_INTERP_FILTER_SWITCHABLE)
return -EINVAL;
/*
* According to the spec, tile_cols_log2 shall be less than or equal
* to 6.
*/
if (frame->tile_cols_log2 > 6)
return -EINVAL;
if (frame->reference_mode > V4L2_VP9_REFERENCE_MODE_SELECT)
return -EINVAL;
ret = validate_vp9_lf_params(&frame->lf);
if (ret)
return ret;
ret = validate_vp9_quant_params(&frame->quant);
if (ret)
return ret;
ret = validate_vp9_seg_params(&frame->seg);
if (ret)
return ret;
zero_reserved(*frame);
return 0;
}
/*
* Compound controls validation requires setting unused fields/flags to zero
* in order to properly detect unchanged controls with std_equal's memcmp.
......@@ -690,6 +858,12 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
case V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX:
break;
case V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR:
return validate_vp9_compressed_hdr(p);
case V4L2_CTRL_TYPE_VP9_FRAME:
return validate_vp9_frame(p);
case V4L2_CTRL_TYPE_AREA:
area = p;
if (!area->width || !area->height)
......@@ -1255,6 +1429,12 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
case V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY:
elem_size = sizeof(struct v4l2_ctrl_hdr10_mastering_display);
break;
case V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR:
elem_size = sizeof(struct v4l2_ctrl_vp9_compressed_hdr);
break;
case V4L2_CTRL_TYPE_VP9_FRAME:
elem_size = sizeof(struct v4l2_ctrl_vp9_frame);
break;
case V4L2_CTRL_TYPE_AREA:
elem_size = sizeof(struct v4l2_area);
break;
......
......@@ -1178,6 +1178,8 @@ const char *v4l2_ctrl_get_name(u32 id)
case V4L2_CID_STATELESS_MPEG2_SEQUENCE: return "MPEG-2 Sequence Header";
case V4L2_CID_STATELESS_MPEG2_PICTURE: return "MPEG-2 Picture Header";
case V4L2_CID_STATELESS_MPEG2_QUANTISATION: return "MPEG-2 Quantisation Matrices";
case V4L2_CID_STATELESS_VP9_COMPRESSED_HDR: return "VP9 Probabilities Updates";
case V4L2_CID_STATELESS_VP9_FRAME: return "VP9 Frame Decode Parameters";
/* Colorimetry controls */
/* Keep the order of the 'case's the same as in v4l2-controls.h! */
......@@ -1506,6 +1508,12 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS:
*type = V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS;
break;
case V4L2_CID_STATELESS_VP9_COMPRESSED_HDR:
*type = V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR;
break;
case V4L2_CID_STATELESS_VP9_FRAME:
*type = V4L2_CTRL_TYPE_VP9_FRAME;
break;
case V4L2_CID_UNIT_CELL_SIZE:
*type = V4L2_CTRL_TYPE_AREA;
*flags |= V4L2_CTRL_FLAG_READ_ONLY;
......
......@@ -1413,6 +1413,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_PIX_FMT_VP8: descr = "VP8"; break;
case V4L2_PIX_FMT_VP8_FRAME: descr = "VP8 Frame"; break;
case V4L2_PIX_FMT_VP9: descr = "VP9"; break;
case V4L2_PIX_FMT_VP9_FRAME: descr = "VP9 Frame"; break;
case V4L2_PIX_FMT_HEVC: descr = "HEVC"; break; /* aka H.265 */
case V4L2_PIX_FMT_HEVC_SLICE: descr = "HEVC Parsed Slice Data"; break;
case V4L2_PIX_FMT_FWHT: descr = "FWHT"; break; /* used in vicodec */
......
......@@ -50,6 +50,8 @@ struct video_device;
* @p_h264_decode_params: Pointer to a struct v4l2_ctrl_h264_decode_params.
* @p_h264_pred_weights: Pointer to a struct v4l2_ctrl_h264_pred_weights.
* @p_vp8_frame: Pointer to a VP8 frame params structure.
* @p_vp9_compressed_hdr_probs: Pointer to a VP9 frame compressed header probs structure.
* @p_vp9_frame: Pointer to a VP9 frame params structure.
* @p_hevc_sps: Pointer to an HEVC sequence parameter set structure.
* @p_hevc_pps: Pointer to an HEVC picture parameter set structure.
* @p_hevc_slice_params: Pointer to an HEVC slice parameters structure.
......@@ -80,6 +82,8 @@ union v4l2_ctrl_ptr {
struct v4l2_ctrl_hevc_sps *p_hevc_sps;
struct v4l2_ctrl_hevc_pps *p_hevc_pps;
struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
struct v4l2_ctrl_vp9_compressed_hdr *p_vp9_compressed_hdr_probs;
struct v4l2_ctrl_vp9_frame *p_vp9_frame;
struct v4l2_ctrl_hdr10_cll_info *p_hdr10_cll;
struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
struct v4l2_area *p_area;
......
This diff is collapsed.
......@@ -703,6 +703,7 @@ struct v4l2_pix_format {
#define V4L2_PIX_FMT_VP8 v4l2_fourcc('V', 'P', '8', '0') /* VP8 */
#define V4L2_PIX_FMT_VP8_FRAME v4l2_fourcc('V', 'P', '8', 'F') /* VP8 parsed frame */
#define V4L2_PIX_FMT_VP9 v4l2_fourcc('V', 'P', '9', '0') /* VP9 */
#define V4L2_PIX_FMT_VP9_FRAME v4l2_fourcc('V', 'P', '9', 'F') /* VP9 parsed frame */
#define V4L2_PIX_FMT_HEVC v4l2_fourcc('H', 'E', 'V', 'C') /* HEVC aka H.265 */
#define V4L2_PIX_FMT_FWHT v4l2_fourcc('F', 'W', 'H', 'T') /* Fast Walsh Hadamard Transform (vicodec) */
#define V4L2_PIX_FMT_FWHT_STATELESS v4l2_fourcc('S', 'F', 'W', 'H') /* Stateless FWHT (vicodec) */
......@@ -1759,6 +1760,8 @@ struct v4l2_ext_control {
struct v4l2_ctrl_mpeg2_sequence __user *p_mpeg2_sequence;
struct v4l2_ctrl_mpeg2_picture __user *p_mpeg2_picture;
struct v4l2_ctrl_mpeg2_quantisation __user *p_mpeg2_quantisation;
struct v4l2_ctrl_vp9_compressed_hdr __user *p_vp9_compressed_hdr_probs;
struct v4l2_ctrl_vp9_frame __user *p_vp9_frame;
void __user *ptr;
};
} __attribute__ ((packed));
......@@ -1823,6 +1826,9 @@ enum v4l2_ctrl_type {
V4L2_CTRL_TYPE_MPEG2_QUANTISATION = 0x0250,
V4L2_CTRL_TYPE_MPEG2_SEQUENCE = 0x0251,
V4L2_CTRL_TYPE_MPEG2_PICTURE = 0x0252,
V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR = 0x0260,
V4L2_CTRL_TYPE_VP9_FRAME = 0x0261,
};
/* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment