From: Ezequiel Garcia <ezequiel@collabora.com>
To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: kernel@collabora.com, Jonas Karlman <jonas@kwiboo.se>,
Hans Verkuil <hverkuil@xs4all.nl>,
Nicolas Dufresne <nicolas.dufresne@collabora.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Maxime Ripard <mripard@kernel.org>,
Paul Kocialkowski <paul.kocialkowski@bootlin.com>,
Jernej Skrabec <jernej.skrabec@siol.net>
Subject: Re: [PATCH v3 07/13] media: controls: Validate H264 stateless controls
Date: Thu, 19 Nov 2020 09:09:38 -0300 [thread overview]
Message-ID: <8cc657c5d41c8794fb62d854dfb6380f1553dc21.camel@collabora.com> (raw)
In-Reply-To: <20201118184700.331213-8-ezequiel@collabora.com>
Hello,
On Wed, 2020-11-18 at 15:46 -0300, Ezequiel Garcia wrote:
> Check that all the fields that correspond or are related
> to a H264 specification syntax element have legal values.
>
> Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
> ---
> drivers/media/v4l2-core/v4l2-ctrls.c | 83 ++++++++++++++++++++++++++++
> 1 file changed, 83 insertions(+)
>
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
> index 21c1928a9df8..adcf47bddbe3 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
> @@ -1775,6 +1775,9 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
> {
> struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
> struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
> + struct v4l2_ctrl_h264_sps *p_h264_sps;
> + struct v4l2_ctrl_h264_pps *p_h264_pps;
> + struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weigths;
> struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;
> struct v4l2_ctrl_h264_decode_params *p_h264_dec_params;
> struct v4l2_ctrl_hevc_sps *p_hevc_sps;
> @@ -1834,20 +1837,100 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
> break;
>
> case V4L2_CTRL_TYPE_H264_SPS:
> + p_h264_sps = p;
> +
> + /* Only monochrome and 4:2:0 allowed */
> + if (p_h264_sps->profile_idc < V4L2_H264_PROFILE_IDC_HIGH_422 &&
> + p_h264_sps->chroma_format_idc > 1)
> + return -EINVAL;
> + /* 4:2:2 allowed */
> + else if (p_h264_sps->profile_idc < V4L2_H264_PROFILE_IDC_HIGH_444 &&
> + p_h264_sps->chroma_format_idc > 2)
> + return -EINVAL;
> + else if (p_h264_sps->chroma_format_idc > 3)
> + return -EINVAL;
> +
> + if (p_h264_sps->bit_depth_luma_minus8 > 6)
> + return -EINVAL;
> + if (p_h264_sps->bit_depth_chroma_minus8 > 6)
> + return -EINVAL;
> + if (p_h264_sps->log2_max_frame_num_minus4 > 12)
> + return -EINVAL;
> + if (p_h264_sps->pic_order_cnt_type > 2)
> + return -EINVAL;
> + if (p_h264_sps->log2_max_pic_order_cnt_lsb_minus4 > 12)
> + return -EINVAL;
After a round of testing and some discussions with Jernej
on IRC, this patch needs some more discussion.
For instance, syntax element log2_max_pic_order_cnt_lsb_minus4
is only present if pic_order_cnt_type==0. It's easy to set it
to 0 in that case (although the spec doesn't specify any value).
Similarly, chroma_format_idc, bit_depth_luma_minus8,
bit_depth_chroma_minus8 elements are not present for some profiles.
The spec defines what are the values to be inferred in this case.
> + if (p_h264_sps->max_num_ref_frames > V4L2_H264_REF_LIST_LEN)
> + return -EINVAL;
> + break;
> +
> case V4L2_CTRL_TYPE_H264_PPS:
> + p_h264_pps = p;
> +
[snip]
>
> case V4L2_CTRL_TYPE_H264_SLICE_PARAMS:
> p_h264_slice_params = p;
>
> + if (p_h264_slice_params->colour_plane_id > 2)
> + return -EINVAL;
> + if (p_h264_slice_params->cabac_init_idc > 2)
> + return -EINVAL;
There are other cases which are more complex to solve. For instance,
cabac_init_idc which is specified if PPS element
entropy_coding_mode_flag is passed.
I believe applications (most of them will have to be adapted
anyway for the new API), will have to ensure cabac_init_idc is sane
before passing it to the kernel.
> + if (p_h264_slice_params->disable_deblocking_filter_idc > 2)
> + return -EINVAL;
> + if (p_h264_slice_params->slice_alpha_c0_offset_div2 < -6 ||
> + p_h264_slice_params->slice_alpha_c0_offset_div2 > 6)
> + return -EINVAL;
> + if (p_h264_slice_params->slice_beta_offset_div2 < -6 ||
> + p_h264_slice_params->slice_beta_offset_div2 > 6)
Same here, these depends on PPS element deblocking_filter_control_present_flag.
I guess we can handle the simple ones, but those that depend
on elements from other NALUs might have to remain as-is.
Thanks,
Ezequiel
next prev parent reply other threads:[~2020-11-19 12:09 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-18 18:46 [PATCH v3 00/13] Stateless H.264 de-staging Ezequiel Garcia
2020-11-18 18:46 ` [PATCH v3 01/13] media: ctrls: Add validate failure debug message Ezequiel Garcia
2020-11-18 18:46 ` [PATCH v3 02/13] media: rkvdec: h264: Support profile and level controls Ezequiel Garcia
2020-11-18 18:46 ` [PATCH v3 03/13] media: cedrus: h264: Support profile controls Ezequiel Garcia
2020-11-18 18:46 ` [PATCH v3 04/13] media: Rename stateful codec control macros Ezequiel Garcia
2020-11-20 9:20 ` Hans Verkuil
2020-11-18 18:46 ` [PATCH v3 05/13] media: Clean stateless control includes Ezequiel Garcia
2020-11-18 18:46 ` [PATCH v3 06/13] media: uapi: h264: Add profile_idc macros Ezequiel Garcia
2020-11-18 18:46 ` [PATCH v3 07/13] media: controls: Validate H264 stateless controls Ezequiel Garcia
2020-11-19 12:09 ` Ezequiel Garcia [this message]
2020-11-20 9:30 ` Hans Verkuil
2020-11-22 0:48 ` Ezequiel Garcia
2020-11-18 18:46 ` [PATCH v3 08/13] media: controls: Add the stateless codec control class Ezequiel Garcia
2020-11-20 9:33 ` Hans Verkuil
2020-11-18 18:46 ` [PATCH v3 09/13] media: uapi: Move parsed H264 pixel format out of staging Ezequiel Garcia
2020-11-18 18:46 ` [PATCH v3 10/13] media: uapi: Move the H264 stateless control types " Ezequiel Garcia
2020-11-18 18:46 ` [PATCH v3 11/13] media: controls: Log H264 stateless controls in .std_log Ezequiel Garcia
2020-11-18 18:46 ` [PATCH v3 12/13] media: uapi: move H264 stateless controls out of staging Ezequiel Garcia
2020-11-19 15:17 ` Ezequiel Garcia
2020-11-18 18:47 ` [PATCH v3 13/13] media: docs: Move the H264 stateless codec uAPI Ezequiel Garcia
2020-11-20 8:45 ` [PATCH v3 00/13] Stateless H.264 de-staging Hans Verkuil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8cc657c5d41c8794fb62d854dfb6380f1553dc21.camel@collabora.com \
--to=ezequiel@collabora.com \
--cc=hverkuil@xs4all.nl \
--cc=jernej.skrabec@siol.net \
--cc=jonas@kwiboo.se \
--cc=kernel@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mripard@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=p.zabel@pengutronix.de \
--cc=paul.kocialkowski@bootlin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).