media: hantro: Set buffers' zeroth plane payload in .buf_prepare
authorEzequiel Garcia <ezequiel@collabora.com>
Wed, 25 Mar 2020 21:34:33 +0000 (22:34 +0100)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 14 Apr 2020 09:22:31 +0000 (11:22 +0200)
Buffers' zeroth plane payload size is calculated at format
negotiation time, and so it can be set in .buf_prepare.

Keep in mind that, to make this change easier, hantro_buf_prepare
is refactored, using the cedrus driver as reference. This results
in cleaner code as byproduct.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/staging/media/hantro/hantro_v4l2.c

index f4ae2ce..3142ab6 100644 (file)
@@ -608,7 +608,7 @@ hantro_queue_setup(struct vb2_queue *vq, unsigned int *num_buffers,
 }
 
 static int
-hantro_buf_plane_check(struct vb2_buffer *vb, const struct hantro_fmt *vpu_fmt,
+hantro_buf_plane_check(struct vb2_buffer *vb,
                       struct v4l2_pix_format_mplane *pixfmt)
 {
        unsigned int sz;
@@ -630,12 +630,18 @@ static int hantro_buf_prepare(struct vb2_buffer *vb)
 {
        struct vb2_queue *vq = vb->vb2_queue;
        struct hantro_ctx *ctx = vb2_get_drv_priv(vq);
+       struct v4l2_pix_format_mplane *pix_fmt;
+       int ret;
 
        if (V4L2_TYPE_IS_OUTPUT(vq->type))
-               return hantro_buf_plane_check(vb, ctx->vpu_src_fmt,
-                                                 &ctx->src_fmt);
-
-       return hantro_buf_plane_check(vb, ctx->vpu_dst_fmt, &ctx->dst_fmt);
+               pix_fmt = &ctx->src_fmt;
+       else
+               pix_fmt = &ctx->dst_fmt;
+       ret = hantro_buf_plane_check(vb, pix_fmt);
+       if (ret)
+               return ret;
+       vb2_set_plane_payload(vb, 0, pix_fmt->plane_fmt[0].sizeimage);
+       return 0;
 }
 
 static void hantro_buf_queue(struct vb2_buffer *vb)