media: verisilicon: Store reference frames pixels format
A message that is not in the archive (sent off-list or not yet received): [email protected]
Benjamin Gaignard
maintainerPATCH 1/2 media: verisilicon: Store reference frames pixels format
Hantro decoder always produce tiled pixels formats but when the post-processor is used the destination pixels format is a non tiled pixels format. This led to compute wrong reference frame size and offsets.
Getting and saving the correct tiled pixels format for 8 and 10 bit stream solve the computation issues.
Fluster VP9 score increase to 166/305 (vs 145/305). HEVC score is still 141/147.
--- drivers/media/platform/verisilicon/hantro.h | 2 ++ .../media/platform/verisilicon/hantro_g2.c | 2 +- .../platform/verisilicon/hantro_postproc.c | 28 ++++++------------- .../media/platform/verisilicon/hantro_v4l2.c | 21 ++++++++++++++ 4 files changed, 33 insertions(+), 20 deletions(-)
drivers/media/platform/verisilicon/hantro.h +2 -0
@@ -227,6 +227,7 @@ struct hantro_dev {* @src_fmt: V4L2 pixel format of active source format. * @vpu_dst_fmt: Descriptor of active destination format. * @dst_fmt: V4L2 pixel format of active destination format. +* @ref_fmt: V4L2 pixel format of the reference frames format. * * @ctrl_handler: Control handler used to register controls. * @jpeg_quality: User-specified JPEG compression quality.
@@ -255,6 +256,7 @@ struct hantro_ctx {struct v4l2_pix_format_mplane src_fmt;const struct hantro_fmt *vpu_dst_fmt;struct v4l2_pix_format_mplane dst_fmt; +struct v4l2_pix_format_mplane ref_fmt;struct v4l2_ctrl_handler ctrl_handler;int jpeg_quality;
drivers/media/platform/verisilicon/hantro_g2.c +1 -1
@@ -47,7 +47,7 @@ irqreturn_t hantro_g2_irq(int irq, void *dev_id)size_t hantro_g2_chroma_offset (struct hantro_ctx *ctx) { -return ctx->dst_fmt.width * ctx->dst_fmt.height * ctx->bit_depth /8 ; +return ctx->ref_fmt.plane_fmt[0 ].bytesperline * ctx->ref_fmt.height; }size_t hantro_g2_motion_vectors_offset (struct hantro_ctx *ctx)
drivers/media/platform/verisilicon/hantro_postproc.c +9 -19
@@ -194,31 +194,21 @@ void hantro_postproc_free(struct hantro_ctx *ctx)static unsigned int hantro_postproc_buffer_size (struct hantro_ctx *ctx) { -struct v4l2_pix_format_mplane pix_mp; -const struct hantro_fmt *fmt;unsigned int buf_size; -/* this should always pick native format */ - fmt =hantro_get_default_fmt (ctx, false, ctx->bit_depth,HANTRO_AUTO_POSTPROC ); -if (!fmt) -return 0 ; - -v4l2_fill_pixfmt_mp (&pix_mp, fmt->fourcc, ctx->src_fmt.width, - ctx->src_fmt.height); - - buf_size = pix_mp.plane_fmt[0 ].sizeimage; + buf_size = ctx->ref_fmt.plane_fmt[0 ].sizeimage;if (ctx->vpu_src_fmt->fourcc ==V4L2_PIX_FMT_H264_SLICE ) - buf_size +=hantro_h264_mv_size (pix_mp.width, - pix_mp.height); + buf_size +=hantro_h264_mv_size (ctx->ref_fmt.width, + ctx->ref_fmt.height);else if (ctx->vpu_src_fmt->fourcc ==V4L2_PIX_FMT_VP9_FRAME ) - buf_size +=hantro_vp9_mv_size (pix_mp.width, - pix_mp.height); + buf_size +=hantro_vp9_mv_size (ctx->ref_fmt.width, + ctx->ref_fmt.height);else if (ctx->vpu_src_fmt->fourcc ==V4L2_PIX_FMT_HEVC_SLICE ) - buf_size +=hantro_hevc_mv_size (pix_mp.width, - pix_mp.height); + buf_size +=hantro_hevc_mv_size (ctx->ref_fmt.width, + ctx->ref_fmt.height);else if (ctx->vpu_src_fmt->fourcc ==V4L2_PIX_FMT_AV1_FRAME ) - buf_size +=hantro_av1_mv_size (pix_mp.width, - pix_mp.height); + buf_size +=hantro_av1_mv_size (ctx->ref_fmt.width, + ctx->ref_fmt.height);return buf_size; }
drivers/media/platform/verisilicon/hantro_v4l2.c +21 -0
@@ -126,6 +126,24 @@ hantro_find_format(const struct hantro_ctx *ctx, u32 fourcc)return NULL ; } +static int +hantro_set_reference_frames_format (struct hantro_ctx *ctx) +{ +const struct hantro_fmt *fmt; +int dst_bit_depth =hantro_get_format_depth (ctx->vpu_dst_fmt->fourcc); + + fmt =hantro_get_default_fmt (ctx, false, dst_bit_depth,HANTRO_AUTO_POSTPROC ); +if (!fmt) +return -EINVAL ; + + ctx->ref_fmt.width = ctx->src_fmt.width; + ctx->ref_fmt.height = ctx->src_fmt.height; + +v4l2_apply_frmsize_constraints (&ctx->ref_fmt.width, &ctx->ref_fmt.height, &fmt->frmsize); +return v4l2_fill_pixfmt_mp (&ctx->ref_fmt, fmt->fourcc, + ctx->ref_fmt.width, ctx->ref_fmt.height); +} +const struct hantro_fmt *hantro_get_default_fmt (const struct hantro_ctx *ctx,bool bitstream,int bit_depth,bool need_postproc)
@@ -591,6 +609,9 @@ static int hantro_set_fmt_cap(struct hantro_ctx *ctx, ctx->vpu_dst_fmt =hantro_find_format (ctx, pix_mp->pixelformat); ctx->dst_fmt = *pix_mp; + ret =hantro_set_reference_frames_format (ctx); +if (ret) +return ret;/* * Current raw format might have become invalid with newly
Signature · 1 line
2.43.0
Le lundi 04 novembre 2024 à 17:36 +0000, Benjamin Gaignard a écrit :
Quoted 7 lines
Hantro decoder always produce tiled pixels formats but when the post-processor is used the destination pixels format is a non tiled pixels format. This led to compute wrong reference frame size and offsets.
Getting and saving the correct tiled pixels format for 8 and 10 bit stream solve the computation issues.
Quoted 5 lines
Fluster VP9 score increase to 166/305 (vs 145/305). HEVC score is still 141/147.
Signed-off-by Benjamin Gaignard <[email protected]>
Quoted 124 lines
--- drivers/media/platform/verisilicon/hantro.h | 2 ++ .../media/platform/verisilicon/hantro_g2.c | 2 +- .../platform/verisilicon/hantro_postproc.c | 28 ++++++------------- .../media/platform/verisilicon/hantro_v4l2.c | 21 ++++++++++++++ 4 files changed, 33 insertions(+), 20 deletions(-)drivers/media/platform/verisilicon/hantro.h +2
-0@@ -227,6 +227,7 @@ struct hantro_dev {* @src_fmt: V4L2 pixel format of active source format. * @vpu_dst_fmt: Descriptor of active destination format. * @dst_fmt: V4L2 pixel format of active destination format. +* @ref_fmt: V4L2 pixel format of the reference frames format. * * @ctrl_handler: Control handler used to register controls. * @jpeg_quality: User-specified JPEG compression quality. @@ -255,6 +256,7 @@ struct hantro_ctx {struct v4l2_pix_format_mplane src_fmt;const struct hantro_fmt *vpu_dst_fmt;struct v4l2_pix_format_mplane dst_fmt; +struct v4l2_pix_format_mplane ref_fmt;struct v4l2_ctrl_handler ctrl_handler;int jpeg_quality;drivers/media/platform/verisilicon/hantro_g2.c +1
-1@@ -47,7 +47,7 @@ irqreturn_t hantro_g2_irq(int irq, void *dev_id)size_t hantro_g2_chroma_offset (struct hantro_ctx *ctx) { -return ctx->dst_fmt.width * ctx->dst_fmt.height * ctx->bit_depth /8 ; +return ctx->ref_fmt.plane_fmt[0 ].bytesperline * ctx->ref_fmt.height; }size_t hantro_g2_motion_vectors_offset (struct hantro_ctx *ctx)drivers/media/platform/verisilicon/hantro_postproc.c +9
-19@@ -194,31 +194,21 @@ void hantro_postproc_free(struct hantro_ctx *ctx)static unsigned int hantro_postproc_buffer_size (struct hantro_ctx *ctx) { -struct v4l2_pix_format_mplane pix_mp; -const struct hantro_fmt *fmt;unsigned int buf_size; -/* this should always pick native format */ - fmt =hantro_get_default_fmt (ctx, false, ctx->bit_depth,HANTRO_AUTO_POSTPROC ); -if (!fmt) -return 0 ; - -v4l2_fill_pixfmt_mp (&pix_mp, fmt->fourcc, ctx->src_fmt.width, - ctx->src_fmt.height); - - buf_size = pix_mp.plane_fmt[0 ].sizeimage; + buf_size = ctx->ref_fmt.plane_fmt[0 ].sizeimage;if (ctx->vpu_src_fmt->fourcc ==V4L2_PIX_FMT_H264_SLICE ) - buf_size +=hantro_h264_mv_size (pix_mp.width, - pix_mp.height); + buf_size +=hantro_h264_mv_size (ctx->ref_fmt.width, + ctx->ref_fmt.height);else if (ctx->vpu_src_fmt->fourcc ==V4L2_PIX_FMT_VP9_FRAME ) - buf_size +=hantro_vp9_mv_size (pix_mp.width, - pix_mp.height); + buf_size +=hantro_vp9_mv_size (ctx->ref_fmt.width, + ctx->ref_fmt.height);else if (ctx->vpu_src_fmt->fourcc ==V4L2_PIX_FMT_HEVC_SLICE ) - buf_size +=hantro_hevc_mv_size (pix_mp.width, - pix_mp.height); + buf_size +=hantro_hevc_mv_size (ctx->ref_fmt.width, + ctx->ref_fmt.height);else if (ctx->vpu_src_fmt->fourcc ==V4L2_PIX_FMT_AV1_FRAME ) - buf_size +=hantro_av1_mv_size (pix_mp.width, - pix_mp.height); + buf_size +=hantro_av1_mv_size (ctx->ref_fmt.width, + ctx->ref_fmt.height);return buf_size; }drivers/media/platform/verisilicon/hantro_v4l2.c +21
-0@@ -126,6 +126,24 @@ hantro_find_format(const struct hantro_ctx *ctx, u32 fourcc)return NULL ; } +static int +hantro_set_reference_frames_format (struct hantro_ctx *ctx) +{ +const struct hantro_fmt *fmt; +int dst_bit_depth =hantro_get_format_depth (ctx->vpu_dst_fmt->fourcc); + + fmt =hantro_get_default_fmt (ctx, false, dst_bit_depth,HANTRO_AUTO_POSTPROC ); +if (!fmt) +return -EINVAL ; + + ctx->ref_fmt.width = ctx->src_fmt.width; + ctx->ref_fmt.height = ctx->src_fmt.height; + +v4l2_apply_frmsize_constraints (&ctx->ref_fmt.width, &ctx->ref_fmt.height, &fmt->frmsize); +return v4l2_fill_pixfmt_mp (&ctx->ref_fmt, fmt->fourcc, + ctx->ref_fmt.width, ctx->ref_fmt.height); +} +const struct hantro_fmt *hantro_get_default_fmt (const struct hantro_ctx *ctx,bool bitstream,int bit_depth,bool need_postproc)@@ -591,6 +609,9 @@ static int hantro_set_fmt_cap(struct hantro_ctx *ctx, ctx->vpu_dst_fmt =hantro_find_format (ctx, pix_mp->pixelformat); ctx->dst_fmt = *pix_mp; + ret =hantro_set_reference_frames_format (ctx); +if (ret) +return ret;/* * Current raw format might have become invalid with newly
Benjamin Gaignard
maintainerPATCH 2/2 media: verisilicon: Fix IMX8 native pixels format steps values
In reply to a message not in the archiveHantro decoder non post-processed pixels formats steps are different from post-processed ones.
Fix the steps according to hardware limitation.
Since reference frame pixels format issue has been fix, it is possible to use V4L2_PIX_FMT_NV15_4L4 rather V4L2_PIX_FMT_P010_4L4 for 10bits streams.
Fluster VP9 score goes up to 207/305.
HEVC score is still 141/147.
--- drivers/media/platform/verisilicon/imx8m_vpu_hw.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +5 -5
@@ -187,23 +187,23 @@ static const struct hantro_fmt imx8m_vpu_g2_dec_fmts[] = { .frmsize = { .min_width = FMT_MIN_WIDTH, .max_width = FMT_UHD_WIDTH, - .step_width = TILE_MB_DIM, + .step_width = 8, .min_height = FMT_MIN_HEIGHT, .max_height = FMT_UHD_HEIGHT, - .step_height = TILE_MB_DIM, + .step_height = 32, }, }, { - .fourcc = V4L2_PIX_FMT_P010_4L4, + .fourcc = V4L2_PIX_FMT_NV15_4L4, .codec_mode = HANTRO_MODE_NONE, .match_depth = true, .frmsize = { .min_width = FMT_MIN_WIDTH, .max_width = FMT_UHD_WIDTH, - .step_width = TILE_MB_DIM, + .step_width = 8, .min_height = FMT_MIN_HEIGHT, .max_height = FMT_UHD_HEIGHT, - .step_height = TILE_MB_DIM, + .step_height = 32, }, }, {
Signature · 1 line
2.43.0
Re: [PATCH 2/2] media: verisilicon: Fix IMX8 native pixels format steps values
Le lundi 04 novembre 2024 à 17:36 +0000, Benjamin Gaignard a écrit :
Quoted 11 lines
Hantro decoder non post-processed pixels formats steps are different from post-processed ones.
Fix the steps according to hardware limitation.
Since reference frame pixels format issue has been fix, it is possible to useV4L2_PIX_FMT_NV15_4L4ratherV4L2_PIX_FMT_P010_4L4for 10bits streams.Fluster VP9 score goes up to 207/305.
HEVC score is still 141/147.Signed-off-by Benjamin Gaignard <[email protected]>
Quoted 37 lines
--- drivers/media/platform/verisilicon/imx8m_vpu_hw.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/media/platform/verisilicon/imx8m_vpu_hw.c +5
-5@@ -187,23 +187,23 @@ static const struct hantro_fmt imx8m_vpu_g2_dec_fmts[] = { .frmsize = { .min_width = FMT_MIN_WIDTH, .max_width = FMT_UHD_WIDTH, - .step_width = TILE_MB_DIM, + .step_width = 8, .min_height = FMT_MIN_HEIGHT, .max_height = FMT_UHD_HEIGHT, - .step_height = TILE_MB_DIM, + .step_height = 32, }, }, { - .fourcc = V4L2_PIX_FMT_P010_4L4, + .fourcc = V4L2_PIX_FMT_NV15_4L4, .codec_mode = HANTRO_MODE_NONE, .match_depth = true, .frmsize = { .min_width = FMT_MIN_WIDTH, .max_width = FMT_UHD_WIDTH, - .step_width = TILE_MB_DIM, + .step_width = 8, .min_height = FMT_MIN_HEIGHT, .max_height = FMT_UHD_HEIGHT, - .step_height = TILE_MB_DIM, + .step_height = 32, }, }, {