diff mbox series

[1/2] rkvdec: h264: Refuse to decode unsupported bitstream

Message ID 20200626171130.27346-2-ezequiel@collabora.com (mailing list archive)
State New, archived
Headers show
Series media: hantro/rkvdec handle unsupported H.264 bitstreams | expand

Commit Message

Ezequiel Garcia June 26, 2020, 5:11 p.m. UTC
The hardware only supports 4:2:2, 4:2:0 or 4:0:0 (monochrome),
8-bit or 10-bit depth content.

Verify that the PPS refers to a supported bitstream, and refuse
unsupported bitstreams by failing at TRY_EXT_CTRLS time.

The driver is currently broken on 10-bit and 4:2:2
so disallow those as well.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
---
 drivers/staging/media/rkvdec/rkvdec.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

Comments

Jonas Karlman July 6, 2020, 9:45 a.m. UTC | #1
On 2020-06-26 19:11, Ezequiel Garcia wrote:
> The hardware only supports 4:2:2, 4:2:0 or 4:0:0 (monochrome),
> 8-bit or 10-bit depth content.
> 
> Verify that the PPS refers to a supported bitstream, and refuse

This should be SPS not PPS, same for hantro patch.

> unsupported bitstreams by failing at TRY_EXT_CTRLS time.
> 
> The driver is currently broken on 10-bit and 4:2:2
> so disallow those as well.
> 
> Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
> ---
>  drivers/staging/media/rkvdec/rkvdec.c | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 
> diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
> index 225eeca73356..0f81b47792f6 100644
> --- a/drivers/staging/media/rkvdec/rkvdec.c
> +++ b/drivers/staging/media/rkvdec/rkvdec.c
> @@ -27,6 +27,32 @@
>  #include "rkvdec.h"
>  #include "rkvdec-regs.h"
>  
> +static int rkvdec_try_ctrl(struct v4l2_ctrl *ctrl)
> +{
> +	if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_SPS) {
> +		const struct v4l2_ctrl_h264_sps *sps = ctrl->p_cur.p;

This should be p_new and not p_cur to validate the new ctrl value, same for hantro patch.

With both fixed this and the hantro patch is,

Reviewed-by: Jonas Karlman <jonas@kwiboo.se>

Regards,
Jonas

> +		/*
> +		 * TODO: The hardware supports 10-bit and 4:2:2 profiles,
> +		 * but it's currently broken in the driver.
> +		 * Reject them for now, until it's fixed.
> +		 */
> +		if (sps->chroma_format_idc > 1)
> +			/* Only 4:0:0 and 4:2:0 are supported */
> +			return -EINVAL;
> +		if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8)
> +			/* Luma and chroma bit depth mismatch */
> +			return -EINVAL;
> +		if (sps->bit_depth_luma_minus8 != 0)
> +			/* Only 8-bit is supported */
> +			return -EINVAL;
> +	}
> +	return 0;
> +}
> +
> +static const struct v4l2_ctrl_ops rkvdec_ctrl_ops = {
> +	.try_ctrl = rkvdec_try_ctrl,
> +};
> +
>  static const struct rkvdec_ctrl_desc rkvdec_h264_ctrl_descs[] = {
>  	{
>  		.per_request = true,
> @@ -42,6 +68,7 @@ static const struct rkvdec_ctrl_desc rkvdec_h264_ctrl_descs[] = {
>  		.per_request = true,
>  		.mandatory = true,
>  		.cfg.id = V4L2_CID_MPEG_VIDEO_H264_SPS,
> +		.cfg.ops = &rkvdec_ctrl_ops,
>  	},
>  	{
>  		.per_request = true,
>
Ezequiel Garcia July 6, 2020, 7:19 p.m. UTC | #2
On Mon, 2020-07-06 at 09:45 +0000, Jonas Karlman wrote:
> On 2020-06-26 19:11, Ezequiel Garcia wrote:
> > The hardware only supports 4:2:2, 4:2:0 or 4:0:0 (monochrome),
> > 8-bit or 10-bit depth content.
> > 
> > Verify that the PPS refers to a supported bitstream, and refuse
> 
> This should be SPS not PPS, same for hantro patch.
> 

Yup.

> > unsupported bitstreams by failing at TRY_EXT_CTRLS time.
> > 
> > The driver is currently broken on 10-bit and 4:2:2
> > so disallow those as well.
> > 
> > Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
> > ---
> >  drivers/staging/media/rkvdec/rkvdec.c | 27 +++++++++++++++++++++++++++
> >  1 file changed, 27 insertions(+)
> > 
> > diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
> > index 225eeca73356..0f81b47792f6 100644
> > --- a/drivers/staging/media/rkvdec/rkvdec.c
> > +++ b/drivers/staging/media/rkvdec/rkvdec.c
> > @@ -27,6 +27,32 @@
> >  #include "rkvdec.h"
> >  #include "rkvdec-regs.h"
> >  
> > +static int rkvdec_try_ctrl(struct v4l2_ctrl *ctrl)
> > +{
> > +	if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_SPS) {
> > +		const struct v4l2_ctrl_h264_sps *sps = ctrl->p_cur.p;
> 
> This should be p_new and not p_cur to validate the new ctrl value, same for hantro patch.
> 
> With both fixed this and the hantro patch is,
> 
> Reviewed-by: Jonas Karlman <jonas@kwiboo.se>
> 

Ah, nice catch. Will fix.

Thanks,
Ezequiel

> Regards,
> Jonas
> 
> > +		/*
> > +		 * TODO: The hardware supports 10-bit and 4:2:2 profiles,
> > +		 * but it's currently broken in the driver.
> > +		 * Reject them for now, until it's fixed.
> > +		 */
> > +		if (sps->chroma_format_idc > 1)
> > +			/* Only 4:0:0 and 4:2:0 are supported */
> > +			return -EINVAL;
> > +		if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8)
> > +			/* Luma and chroma bit depth mismatch */
> > +			return -EINVAL;
> > +		if (sps->bit_depth_luma_minus8 != 0)
> > +			/* Only 8-bit is supported */
> > +			return -EINVAL;
> > +	}
> > +	return 0;
> > +}
> > +
> > +static const struct v4l2_ctrl_ops rkvdec_ctrl_ops = {
> > +	.try_ctrl = rkvdec_try_ctrl,
> > +};
> > +
> >  static const struct rkvdec_ctrl_desc rkvdec_h264_ctrl_descs[] = {
> >  	{
> >  		.per_request = true,
> > @@ -42,6 +68,7 @@ static const struct rkvdec_ctrl_desc rkvdec_h264_ctrl_descs[] = {
> >  		.per_request = true,
> >  		.mandatory = true,
> >  		.cfg.id = V4L2_CID_MPEG_VIDEO_H264_SPS,
> > +		.cfg.ops = &rkvdec_ctrl_ops,
> >  	},
> >  	{
> >  		.per_request = true,
> >
diff mbox series

Patch

diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
index 225eeca73356..0f81b47792f6 100644
--- a/drivers/staging/media/rkvdec/rkvdec.c
+++ b/drivers/staging/media/rkvdec/rkvdec.c
@@ -27,6 +27,32 @@ 
 #include "rkvdec.h"
 #include "rkvdec-regs.h"
 
+static int rkvdec_try_ctrl(struct v4l2_ctrl *ctrl)
+{
+	if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_SPS) {
+		const struct v4l2_ctrl_h264_sps *sps = ctrl->p_cur.p;
+		/*
+		 * TODO: The hardware supports 10-bit and 4:2:2 profiles,
+		 * but it's currently broken in the driver.
+		 * Reject them for now, until it's fixed.
+		 */
+		if (sps->chroma_format_idc > 1)
+			/* Only 4:0:0 and 4:2:0 are supported */
+			return -EINVAL;
+		if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8)
+			/* Luma and chroma bit depth mismatch */
+			return -EINVAL;
+		if (sps->bit_depth_luma_minus8 != 0)
+			/* Only 8-bit is supported */
+			return -EINVAL;
+	}
+	return 0;
+}
+
+static const struct v4l2_ctrl_ops rkvdec_ctrl_ops = {
+	.try_ctrl = rkvdec_try_ctrl,
+};
+
 static const struct rkvdec_ctrl_desc rkvdec_h264_ctrl_descs[] = {
 	{
 		.per_request = true,
@@ -42,6 +68,7 @@  static const struct rkvdec_ctrl_desc rkvdec_h264_ctrl_descs[] = {
 		.per_request = true,
 		.mandatory = true,
 		.cfg.id = V4L2_CID_MPEG_VIDEO_H264_SPS,
+		.cfg.ops = &rkvdec_ctrl_ops,
 	},
 	{
 		.per_request = true,