[media] vcodec: mediatek: Add g/s_selection support for V4L2 Encoder
authorTiffany Lin <tiffany.lin@mediatek.com>
Mon, 15 Aug 2016 02:15:33 +0000 (23:15 -0300)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Tue, 6 Sep 2016 19:21:58 +0000 (16:21 -0300)
This patch add g/s_selection for MT8173 V4L2 Encoder.
Only output queue support g/s_selection to configure crop.
The top/left of active rectangle should always be (0,0)

Signed-off-by: Tiffany Lin <tiffany.lin@mediatek.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c

index 3ed3f2d31df507018b7cbdafb2ab924309f0f5c6..b1f0acbae50b282aea72fae56e1c9a1580fd91d6 100644 (file)
@@ -631,6 +631,69 @@ static int vidioc_try_fmt_vid_out_mplane(struct file *file, void *priv,
        return vidioc_try_fmt(f, fmt);
 }
 
+static int vidioc_venc_g_selection(struct file *file, void *priv,
+                                    struct v4l2_selection *s)
+{
+       struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+       struct mtk_q_data *q_data;
+
+       if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
+               return -EINVAL;
+
+       q_data = mtk_venc_get_q_data(ctx, s->type);
+       if (!q_data)
+               return -EINVAL;
+
+       switch (s->target) {
+       case V4L2_SEL_TGT_CROP_DEFAULT:
+       case V4L2_SEL_TGT_CROP_BOUNDS:
+               s->r.top = 0;
+               s->r.left = 0;
+               s->r.width = q_data->coded_width;
+               s->r.height = q_data->coded_height;
+               break;
+       case V4L2_SEL_TGT_CROP:
+               s->r.top = 0;
+               s->r.left = 0;
+               s->r.width = q_data->visible_width;
+               s->r.height = q_data->visible_height;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int vidioc_venc_s_selection(struct file *file, void *priv,
+                                    struct v4l2_selection *s)
+{
+       struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+       struct mtk_q_data *q_data;
+
+       if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
+               return -EINVAL;
+
+       q_data = mtk_venc_get_q_data(ctx, s->type);
+       if (!q_data)
+               return -EINVAL;
+
+       switch (s->target) {
+       case V4L2_SEL_TGT_CROP:
+               /* Only support crop from (0,0) */
+               s->r.top = 0;
+               s->r.left = 0;
+               s->r.width = min(s->r.width, q_data->coded_width);
+               s->r.height = min(s->r.height, q_data->coded_height);
+               q_data->visible_width = s->r.width;
+               q_data->visible_height = s->r.height;
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
 static int vidioc_venc_qbuf(struct file *file, void *priv,
                            struct v4l2_buffer *buf)
 {
@@ -689,6 +752,9 @@ const struct v4l2_ioctl_ops mtk_venc_ioctl_ops = {
 
        .vidioc_create_bufs             = v4l2_m2m_ioctl_create_bufs,
        .vidioc_prepare_buf             = v4l2_m2m_ioctl_prepare_buf,
+
+       .vidioc_g_selection             = vidioc_venc_g_selection,
+       .vidioc_s_selection             = vidioc_venc_s_selection,
 };
 
 static int vb2ops_venc_queue_setup(struct vb2_queue *vq,