From c097c475f4f216ebf6468c3d46972ec1a5ad5c0d Mon Sep 17 00:00:00 2001 From: Tomasz Figa Date: Mon, 27 Jul 2015 16:07:30 +0900 Subject: [PATCH] CHROMIUM: [media] rk3288-vpu: Add helper for encode plane sizes calculation Currently plane sizes calculation on encoder side is happening only in vidioc_s_fmt() function, howerver as a prerequisite for further patch adding further code which needs this operation, this patch adds a common helper function, which performs this operation. BUG=chrome-os-partner:41585 TEST=AppRTC loopback Signed-off-by: Tomasz Figa Reviewed-on: https://chromium-review.googlesource.com/289047 Reviewed-by: Pawel Osciak Change-Id: I6e5769667ae40b3fb5758ce9471b4ddd6866183f Signed-off-by: Jeffy Chen Signed-off-by: Yakir Yang --- .../platform/rk3288-vpu/rk3288_vpu_enc.c | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/media/platform/rk3288-vpu/rk3288_vpu_enc.c b/drivers/media/platform/rk3288-vpu/rk3288_vpu_enc.c index c3234ddfb452..9a0a6ac9e5fc 100644 --- a/drivers/media/platform/rk3288-vpu/rk3288_vpu_enc.c +++ b/drivers/media/platform/rk3288-vpu/rk3288_vpu_enc.c @@ -536,6 +536,25 @@ static int vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f) return 0; } +static void calculate_plane_sizes(struct rk3288_vpu_fmt *fmt, + unsigned int w, unsigned int h, + struct v4l2_pix_format_mplane *pix_fmt_mp) +{ + int i; + + for (i = 0; i < fmt->num_planes; ++i) { + pix_fmt_mp->plane_fmt[i].bytesperline = w * fmt->depth[i] / 8; + pix_fmt_mp->plane_fmt[i].sizeimage = h * + pix_fmt_mp->plane_fmt[i].bytesperline; + /* + * All of multiplanar formats we support have chroma + * planes subsampled by 2 vertically. + */ + if (i != 0) + pix_fmt_mp->plane_fmt[i].sizeimage /= 2; + } +} + static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) { struct v4l2_pix_format_mplane *pix_fmt_mp = &f->fmt.pix_mp; @@ -543,7 +562,6 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) unsigned int mb_width, mb_height; struct rk3288_vpu_fmt *fmt; int ret = 0; - int i; vpu_debug_enter(); @@ -599,19 +617,8 @@ static int vidioc_s_fmt(struct file *file, void *priv, struct v4l2_format *f) pix_fmt_mp->width, pix_fmt_mp->height, mb_width, mb_height); - for (i = 0; i < fmt->num_planes; ++i) { - pix_fmt_mp->plane_fmt[i].bytesperline = - mb_width * MB_DIM * fmt->depth[i] / 8; - pix_fmt_mp->plane_fmt[i].sizeimage = - pix_fmt_mp->plane_fmt[i].bytesperline - * mb_height * MB_DIM; - /* - * All of multiplanar formats we support have chroma - * planes subsampled by 2. - */ - if (i != 0) - pix_fmt_mp->plane_fmt[i].sizeimage /= 2; - } + calculate_plane_sizes(fmt, mb_width * MB_DIM, + mb_height * MB_DIM, pix_fmt_mp); /* Reset crop rectangle. */ ctx->src_crop.width = pix_fmt_mp->width; -- 2.34.1