]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
media: rockchip/vpu: Use v4l2_apply_frmsize_constraints() where appropriate
authorBoris Brezillon <boris.brezillon@collabora.com>
Tue, 28 May 2019 17:02:20 +0000 (13:02 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Wed, 29 May 2019 14:49:41 +0000 (10:49 -0400)
Use the v4l2_apply_frmsize_constraints() helper instead of open-coding
it.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/staging/media/rockchip/vpu/rockchip_vpu_enc.c

index 7c7c20ab27331222e57c0301c28835a31fca2ac8..aa00df9a7ecbd8c84119fc9b537efda4103e8dd4 100644 (file)
@@ -197,15 +197,9 @@ vidioc_try_fmt_cap_mplane(struct file *file, void *priv, struct v4l2_format *f)
 
        pix_mp->num_planes = 1;
        pix_mp->field = V4L2_FIELD_NONE;
-       pix_mp->width = clamp(pix_mp->width,
-                             fmt->frmsize.min_width,
-                             fmt->frmsize.max_width);
-       pix_mp->height = clamp(pix_mp->height,
-                              fmt->frmsize.min_height,
-                              fmt->frmsize.max_height);
-       /* Round up to macroblocks. */
-       pix_mp->width = round_up(pix_mp->width, fmt->frmsize.step_width);
-       pix_mp->height = round_up(pix_mp->height, fmt->frmsize.step_height);
+
+       v4l2_apply_frmsize_constraints(&pix_mp->width, &pix_mp->height,
+                                      &fmt->frmsize);
 
        /*
         * For compressed formats the application can specify
@@ -226,7 +220,6 @@ vidioc_try_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f)
        struct rockchip_vpu_ctx *ctx = fh_to_ctx(priv);
        struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
        const struct rockchip_vpu_fmt *fmt;
-       unsigned int width, height;
        int i;
 
        vpu_debug(4, "%c%c%c%c\n",
@@ -242,18 +235,13 @@ vidioc_try_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f)
        }
 
        pix_mp->field = V4L2_FIELD_NONE;
-       width = clamp(pix_mp->width,
-                     ctx->vpu_dst_fmt->frmsize.min_width,
-                     ctx->vpu_dst_fmt->frmsize.max_width);
-       height = clamp(pix_mp->height,
-                      ctx->vpu_dst_fmt->frmsize.min_height,
-                      ctx->vpu_dst_fmt->frmsize.max_height);
-       /* Round up to macroblocks. */
-       width = round_up(width, ctx->vpu_dst_fmt->frmsize.step_width);
-       height = round_up(height, ctx->vpu_dst_fmt->frmsize.step_height);
+
+       v4l2_apply_frmsize_constraints(&pix_mp->width, &pix_mp->height,
+                                      &ctx->vpu_dst_fmt->frmsize);
 
        /* Fill remaining fields */
-       v4l2_fill_pixfmt_mp(pix_mp, fmt->fourcc, width, height);
+       v4l2_fill_pixfmt_mp(pix_mp, fmt->fourcc, pix_mp->width,
+                           pix_mp->height);
 
        for (i = 0; i < pix_mp->num_planes; i++) {
                memset(pix_mp->plane_fmt[i].reserved, 0,
@@ -272,10 +260,8 @@ void rockchip_vpu_enc_reset_dst_fmt(struct rockchip_vpu_dev *vpu,
        memset(fmt, 0, sizeof(*fmt));
 
        fmt->num_planes = 1;
-       fmt->width = clamp(fmt->width, ctx->vpu_dst_fmt->frmsize.min_width,
-                          ctx->vpu_dst_fmt->frmsize.max_width);
-       fmt->height = clamp(fmt->height, ctx->vpu_dst_fmt->frmsize.min_height,
-                           ctx->vpu_dst_fmt->frmsize.max_height);
+       v4l2_apply_frmsize_constraints(&fmt->width, &fmt->height,
+                                      &ctx->vpu_dst_fmt->frmsize);
        fmt->pixelformat = ctx->vpu_dst_fmt->fourcc;
        fmt->field = V4L2_FIELD_NONE;
        fmt->colorspace = V4L2_COLORSPACE_JPEG,
@@ -291,23 +277,21 @@ void rockchip_vpu_enc_reset_src_fmt(struct rockchip_vpu_dev *vpu,
                                    struct rockchip_vpu_ctx *ctx)
 {
        struct v4l2_pix_format_mplane *fmt = &ctx->src_fmt;
-       unsigned int width, height;
 
        ctx->vpu_src_fmt = rockchip_vpu_get_default_fmt(ctx, false);
 
        memset(fmt, 0, sizeof(*fmt));
 
-       width = clamp(fmt->width, ctx->vpu_dst_fmt->frmsize.min_width,
-                     ctx->vpu_dst_fmt->frmsize.max_width);
-       height = clamp(fmt->height, ctx->vpu_dst_fmt->frmsize.min_height,
-                      ctx->vpu_dst_fmt->frmsize.max_height);
+       v4l2_apply_frmsize_constraints(&fmt->width, &fmt->height,
+                                      &ctx->vpu_src_fmt->frmsize);
        fmt->field = V4L2_FIELD_NONE;
        fmt->colorspace = V4L2_COLORSPACE_JPEG,
        fmt->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
        fmt->quantization = V4L2_QUANTIZATION_DEFAULT;
        fmt->xfer_func = V4L2_XFER_FUNC_DEFAULT;
 
-       v4l2_fill_pixfmt_mp(fmt, ctx->vpu_src_fmt->fourcc, width, height);
+       v4l2_fill_pixfmt_mp(fmt, ctx->vpu_src_fmt->fourcc, fmt->width,
+                           fmt->height);
 }
 
 static int