media: cedrus: validate H264 and H265 SPS controls
Jernej Skrabec
maintainercover media: cedrus: validate H264 and H265 SPS controls
Since Cedrus core doesn't support decoding all possible H264 and H265 formats, it's good to add some validation, which would reject unsupported combinations.
Patch 1 adds H265 10-bit capability flag, currently supported only on H6.
Patch 2 adds H264/H265 SPS validation callback.
Please take a look.
Best regards,
Jernej
Jernej Skrabec (2):
media: cedrus: Add H265 10-bit capability flag
media: cedrus: add check for H264 and H265 limitations
drivers/staging/media/sunxi/cedrus/cedrus.c | 47 +++++++++++++++++++++ drivers/staging/media/sunxi/cedrus/cedrus.h | 1 + 2 files changed, 48 insertions(+)
Signature · 1 line
2.33.0
Jernej Skrabec
maintainerPATCH 1/2 media: cedrus: Add H265 10-bit capability flag
Currently only H6 variant supports decoding 10-bit H265 videos.
Add a capability flag, so driver could determine if 10-bit H265 slices should be allowed or not.
--- drivers/staging/media/sunxi/cedrus/cedrus.c | 1 + drivers/staging/media/sunxi/cedrus/cedrus.h | 1 + 2 files changed, 2 insertions(+)
drivers/staging/media/sunxi/cedrus/cedrus.c +1 -0
@@ -556,6 +556,7 @@ static const struct cedrus_variant sun50i_h6_cedrus_variant = {CEDRUS_CAPABILITY_MPEG2_DEC |CEDRUS_CAPABILITY_H264_DEC |CEDRUS_CAPABILITY_H265_DEC | +CEDRUS_CAPABILITY_H265_10_DEC | CEDRUS_CAPABILITY_VP8_DEC, .mod_rate = 600000000, };
drivers/staging/media/sunxi/cedrus/cedrus.h +1 -0
@@ -32,6 +32,7 @@#define CEDRUS_CAPABILITY_H264_DEC BIT(2)#define CEDRUS_CAPABILITY_MPEG2_DEC BIT(3)#define CEDRUS_CAPABILITY_VP8_DEC BIT(4) +#define CEDRUS_CAPABILITY_H265_10_DEC BIT(5)enum cedrus_codec {CEDRUS_CODEC_MPEG2 ,
Signature · 1 line
2.33.0
Jernej Skrabec
maintainerPATCH 2/2 media: cedrus: add check for H264 and H265 limitations
In reply to Jernej SkrabecCedrus supports only YUV420 H264/H265 content and mostly only 8-bit colours (except on H6, where 10-bit are also supported).
Add validation callback to SPS controls, which will reject unsupported combinations.
--- drivers/staging/media/sunxi/cedrus/cedrus.c | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+)
drivers/staging/media/sunxi/cedrus/cedrus.c +46 -0
@@ -28,6 +28,50 @@#include "cedrus_dec.h" #include "cedrus_hw.h" +static int cedrus_try_ctrl (struct v4l2_ctrl *ctrl) +{ +if (ctrl->id ==V4L2_CID_STATELESS_H264_SPS ) { +const struct v4l2_ctrl_h264_sps *sps = ctrl->p_new.p_h264_sps; + +if (sps->chroma_format_idc !=1 ) +/* Only 4:2:0 is 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 ; + }else if (ctrl->id ==V4L2_CID_MPEG_VIDEO_HEVC_SPS ) { +const struct v4l2_ctrl_hevc_sps *sps = ctrl->p_new.p_hevc_sps; + struct cedrus_ctx *ctx = container_of(ctrl->handler, struct cedrus_ctx, hdl); + +if (sps->chroma_format_idc !=1 ) +/* Only 4:2:0 is supported */ +return -EINVAL ; + +if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8) +/* Luma and chroma bit depth mismatch */ +return -EINVAL ; + +if (ctx->dev->capabilities &CEDRUS_CAPABILITY_H265_10_DEC ) { +if (sps->bit_depth_luma_minus8 !=0 && sps->bit_depth_luma_minus8 !=2 ) +/* Only 8-bit and 10-bit are supported */ +return -EINVAL ; + }else { +if (sps->bit_depth_luma_minus8 !=0 ) +/* Only 8-bit is supported */ +return -EINVAL ; + } + } + +return 0 ; +} + +static const struct v4l2_ctrl_ops cedrus_ctrl_ops = { + .try_ctrl = cedrus_try_ctrl, +}; +static const struct cedrus_control cedrus_controls[] = { { .cfg = {
@@ -62,6 +106,7 @@ static const struct cedrus_control cedrus_controls[] = { { .cfg = { .id = V4L2_CID_STATELESS_H264_SPS, + .ops = &cedrus_ctrl_ops, }, .codec = CEDRUS_CODEC_H264, },
@@ -120,6 +165,7 @@ static const struct cedrus_control cedrus_controls[] = { { .cfg = { .id = V4L2_CID_MPEG_VIDEO_HEVC_SPS, + .ops = &cedrus_ctrl_ops, }, .codec = CEDRUS_CODEC_H265, },
Signature · 1 line
2.33.0