]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: verisilicon: Store reference frames pixels format
authorBenjamin Gaignard <benjamin.gaignard@collabora.com>
Thu, 12 Dec 2024 15:43:33 +0000 (15:43 +0000)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 13 Dec 2024 19:48:25 +0000 (19:48 +0000)
The Hantro decoder always produces tiled pixel-formats, but when the
post-processor is used, the destination pixel-format is a non-tiled
pixel-format. This causes an incorrect computation of the reference
frame size and offsets. Get and save the correct tiled pixel-format for
8 and 10 bit streams to solve these computation issues.

Fluster VP9 score increase to 166/305 (vs 145/305).
HEVC score is still 141/147.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Signed-off-by: Sebastian Fricke <sebastian.fricke@collabora.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/platform/verisilicon/hantro.h
drivers/media/platform/verisilicon/hantro_g2.c
drivers/media/platform/verisilicon/hantro_postproc.c
drivers/media/platform/verisilicon/hantro_v4l2.c

index 811260dc3c777a2df1a589e35d2074cc2ef125a2..14fc6a3e287819feb7efcbca7d960ff71ed4eaba 100644 (file)
@@ -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;
index 5c1d799d861840993166270ece8b24a6fcc136ca..aae0b562fabb1732b08bcd88b9007749a7849ba6 100644 (file)
@@ -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)
index 232c93eea7eea622bddcfb8b42aae67ebf3409fb..c435a393e0cb70de9ecea729758c81a7fd367c68 100644 (file)
@@ -194,35 +194,25 @@ 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);
                if (ctx->hevc_dec.use_compression)
-                       buf_size += hantro_hevc_compressed_size(pix_mp.width,
-                                                               pix_mp.height);
+                       buf_size += hantro_hevc_compressed_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;
 }
index 2513adfbd82595632d5e797a71501153d557c5d1..2bce940a58227c2bfef2bc3343992e4588ab36a4 100644 (file)
@@ -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)
@@ -595,6 +613,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