media: s5p_mfc_dec.c: convert g_crop to g_selection
authorHans Verkuil <hans.verkuil@cisco.com>
Thu, 4 Oct 2018 20:02:42 +0000 (16:02 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Tue, 20 Nov 2018 18:47:46 +0000 (13:47 -0500)
The g_crop really implemented composition for the CAPTURE stream.

Replace g_crop by g_selection and set the V4L2_FL_QUIRK_INVERTED_CROP
flag since this is one of the old drivers that predates the selection
API. Those old drivers allowed g_crop when it really shouldn't have
since g_crop returns a compose rectangle instead of a crop rectangle.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Tested-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/platform/s5p-mfc/s5p_mfc.c
drivers/media/platform/s5p-mfc/s5p_mfc_dec.c

index 927a123..8a5ba3b 100644 (file)
@@ -1342,6 +1342,7 @@ static int s5p_mfc_probe(struct platform_device *pdev)
        vfd->lock       = &dev->mfc_mutex;
        vfd->v4l2_dev   = &dev->v4l2_dev;
        vfd->vfl_dir    = VFL_DIR_M2M;
+       set_bit(V4L2_FL_QUIRK_INVERTED_CROP, &vfd->flags);
        snprintf(vfd->name, sizeof(vfd->name), "%s", S5P_MFC_DEC_NAME);
        dev->vfd_dec    = vfd;
        video_set_drvdata(vfd, dev);
index ece59ce..f4c0e3a 100644 (file)
@@ -773,19 +773,23 @@ static const struct v4l2_ctrl_ops s5p_mfc_dec_ctrl_ops = {
        .g_volatile_ctrl = s5p_mfc_dec_g_v_ctrl,
 };
 
-/* Get cropping information */
-static int vidioc_g_crop(struct file *file, void *priv,
-               struct v4l2_crop *cr)
+/* Get compose information */
+static int vidioc_g_selection(struct file *file, void *priv,
+                             struct v4l2_selection *s)
 {
        struct s5p_mfc_ctx *ctx = fh_to_ctx(priv);
        struct s5p_mfc_dev *dev = ctx->dev;
        u32 left, right, top, bottom;
+       u32 width, height;
+
+       if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+               return -EINVAL;
 
        if (ctx->state != MFCINST_HEAD_PARSED &&
            ctx->state != MFCINST_RUNNING &&
            ctx->state != MFCINST_FINISHING &&
            ctx->state != MFCINST_FINISHED) {
-               mfc_err("Can not get crop information\n");
+               mfc_err("Can not get compose information\n");
                return -EINVAL;
        }
        if (ctx->src_fmt->fourcc == V4L2_PIX_FMT_H264) {
@@ -795,22 +799,33 @@ static int vidioc_g_crop(struct file *file, void *priv,
                top = s5p_mfc_hw_call(dev->mfc_ops, get_crop_info_v, ctx);
                bottom = top >> S5P_FIMV_SHARED_CROP_BOTTOM_SHIFT;
                top = top & S5P_FIMV_SHARED_CROP_TOP_MASK;
-               cr->c.left = left;
-               cr->c.top = top;
-               cr->c.width = ctx->img_width - left - right;
-               cr->c.height = ctx->img_height - top - bottom;
-               mfc_debug(2, "Cropping info [h264]: l=%d t=%d w=%d h=%d (r=%d b=%d fw=%d fh=%d\n",
-                         left, top, cr->c.width, cr->c.height, right, bottom,
+               width = ctx->img_width - left - right;
+               height = ctx->img_height - top - bottom;
+               mfc_debug(2, "Composing info [h264]: l=%d t=%d w=%d h=%d (r=%d b=%d fw=%d fh=%d\n",
+                         left, top, s->r.width, s->r.height, right, bottom,
                          ctx->buf_width, ctx->buf_height);
        } else {
-               cr->c.left = 0;
-               cr->c.top = 0;
-               cr->c.width = ctx->img_width;
-               cr->c.height = ctx->img_height;
-               mfc_debug(2, "Cropping info: w=%d h=%d fw=%d fh=%d\n",
-                         cr->c.width,  cr->c.height, ctx->buf_width,
+               left = 0;
+               top = 0;
+               width = ctx->img_width;
+               height = ctx->img_height;
+               mfc_debug(2, "Composing info: w=%d h=%d fw=%d fh=%d\n",
+                         s->r.width, s->r.height, ctx->buf_width,
                          ctx->buf_height);
        }
+
+       switch (s->target) {
+       case V4L2_SEL_TGT_COMPOSE:
+       case V4L2_SEL_TGT_COMPOSE_DEFAULT:
+       case V4L2_SEL_TGT_COMPOSE_BOUNDS:
+               s->r.left = left;
+               s->r.top = top;
+               s->r.width = width;
+               s->r.height = height;
+               break;
+       default:
+               return -EINVAL;
+       }
        return 0;
 }
 
@@ -887,7 +902,7 @@ static const struct v4l2_ioctl_ops s5p_mfc_dec_ioctl_ops = {
        .vidioc_expbuf = vidioc_expbuf,
        .vidioc_streamon = vidioc_streamon,
        .vidioc_streamoff = vidioc_streamoff,
-       .vidioc_g_crop = vidioc_g_crop,
+       .vidioc_g_selection = vidioc_g_selection,
        .vidioc_decoder_cmd = vidioc_decoder_cmd,
        .vidioc_subscribe_event = vidioc_subscribe_event,
        .vidioc_unsubscribe_event = v4l2_event_unsubscribe,