Commit ba0b00e7 authored by Dafna Hirschfeld's avatar Dafna Hirschfeld Committed by Mauro Carvalho Chehab
Browse files

media: mtk-vcodec: replace func vidioc_try_fmt with two funcs for out/cap



The function vidioc_try_fmt has a big 'if-else' for
the capture and output cases. There is hardly any code
outside of that condition. It is therefore better to split
that functions into two different functions, one for each case.

Signed-off-by: default avatarDafna Hirschfeld <dafna.hirschfeld@collabora.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 71c78976
Loading
Loading
Loading
Loading
+72 −77
Original line number Diff line number Diff line
@@ -264,23 +264,26 @@ static struct mtk_q_data *mtk_venc_get_q_data(struct mtk_vcodec_ctx *ctx,
	return &ctx->q_data[MTK_Q_DATA_DST];
}

static void vidioc_try_fmt_cap(struct v4l2_format *f)
{
	f->fmt.pix_mp.field = V4L2_FIELD_NONE;
	f->fmt.pix_mp.num_planes = 1;
	f->fmt.pix_mp.plane_fmt[0].bytesperline = 0;
	f->fmt.pix_mp.flags = 0;
}

/* V4L2 specification suggests the driver corrects the format struct if any of
 * the dimensions is unsupported
 */
static int vidioc_try_fmt(struct mtk_vcodec_ctx *ctx, struct v4l2_format *f,
static int vidioc_try_fmt_out(struct mtk_vcodec_ctx *ctx, struct v4l2_format *f,
			      const struct mtk_video_fmt *fmt)
{
	struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp;

	pix_fmt_mp->field = V4L2_FIELD_NONE;

	if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
		pix_fmt_mp->num_planes = 1;
		pix_fmt_mp->plane_fmt[0].bytesperline = 0;
	} else if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
	int tmp_w, tmp_h;
	unsigned int max_width, max_height;

	pix_fmt_mp->field = V4L2_FIELD_NONE;

	if (ctx->dev->enc_capability & MTK_VENC_4K_CAPABILITY_ENABLE) {
		max_width = MTK_VENC_4K_MAX_W;
		max_height = MTK_VENC_4K_MAX_H;
@@ -289,12 +292,8 @@ static int vidioc_try_fmt(struct mtk_vcodec_ctx *ctx, struct v4l2_format *f,
		max_height = MTK_VENC_HD_MAX_H;
	}

		pix_fmt_mp->height = clamp(pix_fmt_mp->height,
					MTK_VENC_MIN_H,
					max_height);
		pix_fmt_mp->width = clamp(pix_fmt_mp->width,
					MTK_VENC_MIN_W,
					max_width);
	pix_fmt_mp->height = clamp(pix_fmt_mp->height, MTK_VENC_MIN_H, max_height);
	pix_fmt_mp->width = clamp(pix_fmt_mp->width, MTK_VENC_MIN_W, max_width);

	/* find next closer width align 16, heign align 32, size align
	 * 64 rectangle
@@ -308,15 +307,12 @@ static int vidioc_try_fmt(struct mtk_vcodec_ctx *ctx, struct v4l2_format *f,
			      MTK_VENC_MIN_H,
			      max_height, 5, 6);

		if (pix_fmt_mp->width < tmp_w &&
			(pix_fmt_mp->width + 16) <= max_width)
	if (pix_fmt_mp->width < tmp_w && (pix_fmt_mp->width + 16) <= max_width)
		pix_fmt_mp->width += 16;
		if (pix_fmt_mp->height < tmp_h &&
			(pix_fmt_mp->height + 32) <= max_height)
	if (pix_fmt_mp->height < tmp_h && (pix_fmt_mp->height + 32) <= max_height)
		pix_fmt_mp->height += 32;

		mtk_v4l2_debug(0,
			"before resize width=%d, height=%d, after resize width=%d, height=%d, sizeimage=%d %d",
	mtk_v4l2_debug(0, "before resize w=%d, h=%d, after resize w=%d, h=%d, sizeimage=%d %d",
		       tmp_w, tmp_h, pix_fmt_mp->width,
		       pix_fmt_mp->height,
		       pix_fmt_mp->plane_fmt[0].sizeimage,
@@ -345,7 +341,6 @@ static int vidioc_try_fmt(struct mtk_vcodec_ctx *ctx, struct v4l2_format *f,
			pix_fmt_mp->plane_fmt[2].bytesperline =
			pix_fmt_mp->width / 2;
	}
	}

	pix_fmt_mp->flags = 0;

@@ -433,9 +428,7 @@ static int vidioc_venc_s_fmt_cap(struct file *file, void *priv,
	}

	q_data->fmt = fmt;
	ret = vidioc_try_fmt(ctx, f, q_data->fmt);
	if (ret)
		return ret;
	vidioc_try_fmt_cap(f);

	q_data->coded_width = f->fmt.pix_mp.width;
	q_data->coded_height = f->fmt.pix_mp.height;
@@ -495,7 +488,7 @@ static int vidioc_venc_s_fmt_out(struct file *file, void *priv,
		f->fmt.pix.pixelformat = fmt->fourcc;
	}

	ret = vidioc_try_fmt(ctx, f, fmt);
	ret = vidioc_try_fmt_out(ctx, f, fmt);
	if (ret)
		return ret;

@@ -573,7 +566,9 @@ static int vidioc_try_fmt_vid_cap_mplane(struct file *file, void *priv,
	f->fmt.pix_mp.quantization = ctx->quantization;
	f->fmt.pix_mp.xfer_func = ctx->xfer_func;

	return vidioc_try_fmt(ctx, f, fmt);
	vidioc_try_fmt_cap(f);

	return 0;
}

static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
@@ -595,7 +590,7 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
		f->fmt.pix_mp.xfer_func = V4L2_XFER_FUNC_DEFAULT;
	}

	return vidioc_try_fmt(ctx, f, fmt);
	return vidioc_try_fmt_out(ctx, f, fmt);
}

static int vidioc_venc_g_selection(struct file *file, void *priv,