CHROMIUM: [media] rk3288-vpu: Add helper for encode plane sizes calculation
authorTomasz Figa <tfiga@chromium.org>
Mon, 27 Jul 2015 07:07:30 +0000 (16:07 +0900)
committerHuang, Tao <huangtao@rock-chips.com>
Thu, 30 Jun 2016 11:57:25 +0000 (19:57 +0800)
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 <tfiga@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/289047
Reviewed-by: Pawel Osciak <posciak@chromium.org>
Change-Id: I6e5769667ae40b3fb5758ce9471b4ddd6866183f
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
Signed-off-by: Yakir Yang <ykk@rock-chips.com>
drivers/media/platform/rk3288-vpu/rk3288_vpu_enc.c

index c3234ddfb452e4fb051976effca214a5bbe2acd0..9a0a6ac9e5fcd8875736f132de48f081a9d9e6a0 100644 (file)
@@ -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;