media: hantro: HEVC: Fix output frame chroma offset
authorBenjamin Gaignard <benjamin.gaignard@collabora.com>
Thu, 14 Apr 2022 15:50:59 +0000 (17:50 +0200)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 13 May 2022 09:02:22 +0000 (11:02 +0200)
Hantro decoder doesn't take care of the requested and aligned size
of the capture buffer.
Stop using the bitstream width/height and use capture frame size
stored in the context to get the correct values.

hantro_hevc_chroma_offset() and hantro_hevc_motion_vectors_offset()
are only used in hantro_g2_hevc_dec.c so take the opportunity
to move them here.

fluster HEVC score goes up from 77 to 85 successful tests (over 147)
with this patch.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/staging/media/hantro/hantro_g2_hevc_dec.c
drivers/staging/media/hantro/hantro_hevc.c
drivers/staging/media/hantro/hantro_hw.h

index c0645e3..3a9ee2d 100644 (file)
@@ -8,6 +8,20 @@
 #include "hantro_hw.h"
 #include "hantro_g2_regs.h"
 
+#define G2_ALIGN       16
+
+static size_t hantro_hevc_chroma_offset(struct hantro_ctx *ctx)
+{
+       return ctx->dst_fmt.width * ctx->dst_fmt.height;
+}
+
+static size_t hantro_hevc_motion_vectors_offset(struct hantro_ctx *ctx)
+{
+       size_t cr_offset = hantro_hevc_chroma_offset(ctx);
+
+       return ALIGN((cr_offset * 3) / 2, G2_ALIGN);
+}
+
 static void prepare_tile_info_buffer(struct hantro_ctx *ctx)
 {
        struct hantro_dev *vpu = ctx->dev;
@@ -335,7 +349,6 @@ static void set_ref_pic_list(struct hantro_ctx *ctx)
 static int set_ref(struct hantro_ctx *ctx)
 {
        const struct hantro_hevc_dec_ctrls *ctrls = &ctx->hevc_dec.ctrls;
-       const struct v4l2_ctrl_hevc_sps *sps = ctrls->sps;
        const struct v4l2_ctrl_hevc_pps *pps = ctrls->pps;
        const struct v4l2_ctrl_hevc_decode_params *decode_params = ctrls->decode_params;
        const struct v4l2_hevc_dpb_entry *dpb = decode_params->dpb;
@@ -343,8 +356,8 @@ static int set_ref(struct hantro_ctx *ctx)
        struct hantro_dev *vpu = ctx->dev;
        struct vb2_v4l2_buffer *vb2_dst;
        struct hantro_decoded_buffer *dst;
-       size_t cr_offset = hantro_hevc_chroma_offset(sps);
-       size_t mv_offset = hantro_hevc_motion_vectors_offset(sps);
+       size_t cr_offset = hantro_hevc_chroma_offset(ctx);
+       size_t mv_offset = hantro_hevc_motion_vectors_offset(ctx);
        u32 max_ref_frames;
        u16 dpb_longterm_e;
        static const struct hantro_reg cur_poc[] = {
index 9c351f7..b3a057b 100644 (file)
 
 #define UNUSED_REF     -1
 
-#define G2_ALIGN               16
-
-size_t hantro_hevc_chroma_offset(const struct v4l2_ctrl_hevc_sps *sps)
-{
-       int bytes_per_pixel = sps->bit_depth_luma_minus8 == 0 ? 1 : 2;
-
-       return sps->pic_width_in_luma_samples *
-              sps->pic_height_in_luma_samples * bytes_per_pixel;
-}
-
-size_t hantro_hevc_motion_vectors_offset(const struct v4l2_ctrl_hevc_sps *sps)
-{
-       size_t cr_offset = hantro_hevc_chroma_offset(sps);
-
-       return ALIGN((cr_offset * 3) / 2, G2_ALIGN);
-}
-
 static void hantro_hevc_ref_init(struct hantro_ctx *ctx)
 {
        struct hantro_hevc_dec_hw_ctx *hevc_dec = &ctx->hevc_dec;
index 0e5cafd..594f318 100644 (file)
@@ -345,8 +345,6 @@ int hantro_hevc_dec_prepare_run(struct hantro_ctx *ctx);
 dma_addr_t hantro_hevc_get_ref_buf(struct hantro_ctx *ctx, int poc);
 int hantro_hevc_add_ref_buf(struct hantro_ctx *ctx, int poc, dma_addr_t addr);
 void hantro_hevc_ref_remove_unused(struct hantro_ctx *ctx);
-size_t hantro_hevc_chroma_offset(const struct v4l2_ctrl_hevc_sps *sps);
-size_t hantro_hevc_motion_vectors_offset(const struct v4l2_ctrl_hevc_sps *sps);
 
 static inline unsigned short hantro_vp9_num_sbs(unsigned short dimension)
 {