Commit 0a4f091c authored by Boris Brezillon's avatar Boris Brezillon Committed by Mauro Carvalho Chehab

media: rockchip/vpu: Use v4l2_apply_frmsize_constraints() where appropriate

Use the v4l2_apply_frmsize_constraints() helper instead of open-coding
it.
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent 32cddf9c
...@@ -197,15 +197,9 @@ vidioc_try_fmt_cap_mplane(struct file *file, void *priv, struct v4l2_format *f) ...@@ -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->num_planes = 1;
pix_mp->field = V4L2_FIELD_NONE; pix_mp->field = V4L2_FIELD_NONE;
pix_mp->width = clamp(pix_mp->width,
fmt->frmsize.min_width, v4l2_apply_frmsize_constraints(&pix_mp->width, &pix_mp->height,
fmt->frmsize.max_width); &fmt->frmsize);
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);
/* /*
* For compressed formats the application can specify * 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) ...@@ -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 rockchip_vpu_ctx *ctx = fh_to_ctx(priv);
struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
const struct rockchip_vpu_fmt *fmt; const struct rockchip_vpu_fmt *fmt;
unsigned int width, height;
int i; int i;
vpu_debug(4, "%c%c%c%c\n", 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) ...@@ -242,18 +235,13 @@ vidioc_try_fmt_out_mplane(struct file *file, void *priv, struct v4l2_format *f)
} }
pix_mp->field = V4L2_FIELD_NONE; pix_mp->field = V4L2_FIELD_NONE;
width = clamp(pix_mp->width,
ctx->vpu_dst_fmt->frmsize.min_width, v4l2_apply_frmsize_constraints(&pix_mp->width, &pix_mp->height,
ctx->vpu_dst_fmt->frmsize.max_width); &ctx->vpu_dst_fmt->frmsize);
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);
/* Fill remaining fields */ /* 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++) { for (i = 0; i < pix_mp->num_planes; i++) {
memset(pix_mp->plane_fmt[i].reserved, 0, memset(pix_mp->plane_fmt[i].reserved, 0,
...@@ -272,10 +260,8 @@ void rockchip_vpu_enc_reset_dst_fmt(struct rockchip_vpu_dev *vpu, ...@@ -272,10 +260,8 @@ void rockchip_vpu_enc_reset_dst_fmt(struct rockchip_vpu_dev *vpu,
memset(fmt, 0, sizeof(*fmt)); memset(fmt, 0, sizeof(*fmt));
fmt->num_planes = 1; fmt->num_planes = 1;
fmt->width = clamp(fmt->width, ctx->vpu_dst_fmt->frmsize.min_width, v4l2_apply_frmsize_constraints(&fmt->width, &fmt->height,
ctx->vpu_dst_fmt->frmsize.max_width); &ctx->vpu_dst_fmt->frmsize);
fmt->height = clamp(fmt->height, ctx->vpu_dst_fmt->frmsize.min_height,
ctx->vpu_dst_fmt->frmsize.max_height);
fmt->pixelformat = ctx->vpu_dst_fmt->fourcc; fmt->pixelformat = ctx->vpu_dst_fmt->fourcc;
fmt->field = V4L2_FIELD_NONE; fmt->field = V4L2_FIELD_NONE;
fmt->colorspace = V4L2_COLORSPACE_JPEG, fmt->colorspace = V4L2_COLORSPACE_JPEG,
...@@ -291,23 +277,21 @@ void rockchip_vpu_enc_reset_src_fmt(struct rockchip_vpu_dev *vpu, ...@@ -291,23 +277,21 @@ void rockchip_vpu_enc_reset_src_fmt(struct rockchip_vpu_dev *vpu,
struct rockchip_vpu_ctx *ctx) struct rockchip_vpu_ctx *ctx)
{ {
struct v4l2_pix_format_mplane *fmt = &ctx->src_fmt; struct v4l2_pix_format_mplane *fmt = &ctx->src_fmt;
unsigned int width, height;
ctx->vpu_src_fmt = rockchip_vpu_get_default_fmt(ctx, false); ctx->vpu_src_fmt = rockchip_vpu_get_default_fmt(ctx, false);
memset(fmt, 0, sizeof(*fmt)); memset(fmt, 0, sizeof(*fmt));
width = clamp(fmt->width, ctx->vpu_dst_fmt->frmsize.min_width, v4l2_apply_frmsize_constraints(&fmt->width, &fmt->height,
ctx->vpu_dst_fmt->frmsize.max_width); &ctx->vpu_src_fmt->frmsize);
height = clamp(fmt->height, ctx->vpu_dst_fmt->frmsize.min_height,
ctx->vpu_dst_fmt->frmsize.max_height);
fmt->field = V4L2_FIELD_NONE; fmt->field = V4L2_FIELD_NONE;
fmt->colorspace = V4L2_COLORSPACE_JPEG, fmt->colorspace = V4L2_COLORSPACE_JPEG,
fmt->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; fmt->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
fmt->quantization = V4L2_QUANTIZATION_DEFAULT; fmt->quantization = V4L2_QUANTIZATION_DEFAULT;
fmt->xfer_func = V4L2_XFER_FUNC_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 static int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment