media: hantro: postproc: Fix buffer size calculation
authorJernej Skrabec <jernej.skrabec@gmail.com>
Wed, 6 Jul 2022 18:28:57 +0000 (19:28 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Sun, 17 Jul 2022 10:00:05 +0000 (11:00 +0100)
When allocating aux buffers for postprocessing, it's assumed that base
buffer size is the same as that of output. Coincidentally, that's true
most of the time, but not always. 10-bit source also needs aux buffer
size which is appropriate for 10-bit native format, even if the output
format is 8-bit. Similarly, mv sizes and other extra buffer size also
depends on source width/height, not destination.

Reviewed-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Tested-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/staging/media/hantro/hantro_postproc.c
drivers/staging/media/hantro/hantro_v4l2.c
drivers/staging/media/hantro/hantro_v4l2.h

index ab168c1c0d28713349f11932044d629dce839448..b77cc55e43eaee973e26650f19d2b1bfb64b4f7e 100644 (file)
@@ -12,6 +12,7 @@
 #include "hantro_hw.h"
 #include "hantro_g1_regs.h"
 #include "hantro_g2_regs.h"
+#include "hantro_v4l2.h"
 
 #define HANTRO_PP_REG_WRITE(vpu, reg_name, val) \
 { \
@@ -174,18 +175,27 @@ int hantro_postproc_alloc(struct hantro_ctx *ctx)
        struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx;
        struct vb2_queue *cap_queue = &m2m_ctx->cap_q_ctx.q;
        unsigned int num_buffers = cap_queue->num_buffers;
+       struct v4l2_pix_format_mplane pix_mp;
+       const struct hantro_fmt *fmt;
        unsigned int i, buf_size;
 
-       buf_size = ctx->dst_fmt.plane_fmt[0].sizeimage;
+       /* this should always pick native format */
+       fmt = hantro_get_default_fmt(ctx, false);
+       if (!fmt)
+               return -EINVAL;
+       v4l2_fill_pixfmt_mp(&pix_mp, fmt->fourcc, ctx->src_fmt.width,
+                           ctx->src_fmt.height);
+
+       buf_size = pix_mp.plane_fmt[0].sizeimage;
        if (ctx->vpu_src_fmt->fourcc == V4L2_PIX_FMT_H264_SLICE)
-               buf_size += hantro_h264_mv_size(ctx->dst_fmt.width,
-                                               ctx->dst_fmt.height);
+               buf_size += hantro_h264_mv_size(pix_mp.width,
+                                               pix_mp.height);
        else if (ctx->vpu_src_fmt->fourcc == V4L2_PIX_FMT_VP9_FRAME)
-               buf_size += hantro_vp9_mv_size(ctx->dst_fmt.width,
-                                              ctx->dst_fmt.height);
+               buf_size += hantro_vp9_mv_size(pix_mp.width,
+                                              pix_mp.height);
        else if (ctx->vpu_src_fmt->fourcc == V4L2_PIX_FMT_HEVC_SLICE)
-               buf_size += hantro_hevc_mv_size(ctx->dst_fmt.width,
-                                               ctx->dst_fmt.height);
+               buf_size += hantro_hevc_mv_size(pix_mp.width,
+                                               pix_mp.height);
 
        for (i = 0; i < num_buffers; ++i) {
                struct hantro_aux_buf *priv = &ctx->postproc.dec_q[i];
index 334f18a4120dcee997e2e86ad710009190977bc7..2c7a805289e7b8030c4ff29de143605b360201b1 100644 (file)
@@ -118,7 +118,7 @@ hantro_find_format(const struct hantro_ctx *ctx, u32 fourcc)
        return NULL;
 }
 
-static const struct hantro_fmt *
+const struct hantro_fmt *
 hantro_get_default_fmt(const struct hantro_ctx *ctx, bool bitstream)
 {
        const struct hantro_fmt *formats;
index b17e84c82582ace796182be4766d22919225e33e..64f6f57e9d7a0397707e5bfcabca310e93f2e203 100644 (file)
@@ -23,5 +23,7 @@ extern const struct vb2_ops hantro_queue_ops;
 
 void hantro_reset_fmts(struct hantro_ctx *ctx);
 int hantro_get_format_depth(u32 fourcc);
+const struct hantro_fmt *
+hantro_get_default_fmt(const struct hantro_ctx *ctx, bool bitstream);
 
 #endif /* HANTRO_V4L2_H_ */