From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-media@vger.kernel.org
Cc: laurent.pinchart@ideasonboard.com, hverkuil@xs4all.nl,
mchehab@osg.samsung.com,
Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Subject: [RFC 10/22] v4l: Support the request API in format operations
Date: Fri, 6 May 2016 13:53:19 +0300 [thread overview]
Message-ID: <1462532011-15527-11-git-send-email-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <1462532011-15527-1-git-send-email-sakari.ailus@linux.intel.com>
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Store the formats in per-entity request data. The get and set format
operations are completely handled by the V4L2 core with help of the try
format driver operation.
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
drivers/media/v4l2-core/v4l2-ioctl.c | 121 +++++++++++++++++++++++++++++++++++
include/media/v4l2-dev.h | 13 ++++
2 files changed, 134 insertions(+)
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index bf15580..533fac6 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1355,6 +1355,119 @@ static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops,
return ret;
}
+#if defined(CONFIG_MEDIA_CONTROLLER)
+static void vdev_request_data_release(struct media_entity_request_data *data)
+{
+ struct video_device_request_data *vdata =
+ to_video_device_request_data(data);
+
+ kfree(vdata);
+}
+
+static int vdev_request_format(struct video_device *vdev, unsigned int req_id,
+ struct media_device_request **_req,
+ struct v4l2_pix_format_mplane **_fmt)
+{
+ struct media_entity_request_data *data;
+ struct video_device_request_data *vdata;
+ struct media_device_request *req;
+
+ if (!vdev->v4l2_dev || !vdev->v4l2_dev->mdev)
+ return -EINVAL;
+
+ req = media_device_request_find(vdev->v4l2_dev->mdev, req_id);
+ if (!req)
+ return -EINVAL;
+
+ *_req = req;
+
+ data = media_device_request_get_entity_data(req, &vdev->entity);
+ if (data) {
+ vdata = to_video_device_request_data(data);
+ *_fmt = &vdata->format;
+ return 0;
+ }
+
+ vdata = kzalloc(sizeof(*vdata), GFP_KERNEL);
+ if (!vdata) {
+ media_device_request_put(req);
+ return -ENOMEM;
+ }
+
+ vdata->data.release = vdev_request_data_release;
+
+ media_device_request_set_entity_data(req, &vdev->entity, &vdata->data);
+
+ *_fmt = &vdata->format;
+ return 0;
+}
+
+static int v4l_g_req_mplane_fmt(const struct v4l2_ioctl_ops *ops,
+ struct file *file, void *fh,
+ struct v4l2_format *fmt)
+{
+ struct video_device *vdev = video_devdata(file);
+ struct v4l2_pix_format_mplane *format;
+ struct media_device_request *req;
+ int ret;
+
+ ret = vdev_request_format(vdev, fmt->fmt.pix_mp.request,
+ &req, &format);
+ if (ret < 0)
+ return ret;
+
+ fmt->fmt.pix_mp = *format;
+ media_device_request_put(req);
+ return 0;
+}
+
+static int v4l_s_req_mplane_fmt(const struct v4l2_ioctl_ops *ops,
+ struct file *file, void *fh,
+ struct v4l2_format *fmt)
+{
+ int (*try_op)(struct file *file, void *fh, struct v4l2_format *fmt);
+ struct video_device *vdev = video_devdata(file);
+ struct v4l2_pix_format_mplane *format;
+ struct media_device_request *req;
+ int ret;
+
+ if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
+ try_op = ops->vidioc_try_fmt_vid_cap_mplane;
+ else
+ try_op = ops->vidioc_try_fmt_vid_out_mplane;
+
+ if (unlikely(!try_op))
+ return -ENOSYS;
+
+ ret = try_op(file, fh, fmt);
+ if (ret < 0)
+ return ret;
+
+ ret = vdev_request_format(vdev, fmt->fmt.pix_mp.request,
+ &req, &format);
+ if (ret < 0)
+ return ret;
+
+ *format = fmt->fmt.pix_mp;
+ media_device_request_put(req);
+ return 0;
+}
+#else
+static int v4l_g_req_mplane_fmt(const struct v4l2_ioctl_ops *ops,
+ struct file *file, void *fh,
+ struct v4l2_format *fmt)
+{
+ return -ENOSYS;
+}
+
+static int v4l_s_req_mplane_fmt(const struct v4l2_ioctl_ops *ops,
+ struct file *file, void *fh,
+ struct v4l2_format *fmt)
+{
+ return -ENOSYS;
+}
+#endif
+
static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops,
struct file *file, void *fh, void *arg)
{
@@ -1402,6 +1515,8 @@ static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops,
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
if (unlikely(!is_rx || !is_vid || !ops->vidioc_g_fmt_vid_cap_mplane))
break;
+ if (p->fmt.pix_mp.request)
+ return v4l_g_req_mplane_fmt(ops, file, fh, p);
return ops->vidioc_g_fmt_vid_cap_mplane(file, fh, arg);
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
if (unlikely(!is_rx || !is_vid || !ops->vidioc_g_fmt_vid_overlay))
@@ -1426,6 +1541,8 @@ static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops,
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
if (unlikely(!is_tx || !is_vid || !ops->vidioc_g_fmt_vid_out_mplane))
break;
+ if (p->fmt.pix_mp.request)
+ return v4l_g_req_mplane_fmt(ops, file, fh, p);
return ops->vidioc_g_fmt_vid_out_mplane(file, fh, arg);
case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
if (unlikely(!is_tx || !is_vid || !ops->vidioc_g_fmt_vid_out_overlay))
@@ -1480,6 +1597,8 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops,
if (unlikely(!is_rx || !is_vid || !ops->vidioc_s_fmt_vid_cap_mplane))
break;
CLEAR_AFTER_FIELD(p, fmt.pix_mp);
+ if (p->fmt.pix_mp.request)
+ return v4l_s_req_mplane_fmt(ops, file, fh, p);
return ops->vidioc_s_fmt_vid_cap_mplane(file, fh, arg);
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
if (unlikely(!is_rx || !is_vid || !ops->vidioc_s_fmt_vid_overlay))
@@ -1508,6 +1627,8 @@ static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops,
if (unlikely(!is_tx || !is_vid || !ops->vidioc_s_fmt_vid_out_mplane))
break;
CLEAR_AFTER_FIELD(p, fmt.pix_mp);
+ if (p->fmt.pix_mp.request)
+ return v4l_s_req_mplane_fmt(ops, file, fh, p);
return ops->vidioc_s_fmt_vid_out_mplane(file, fh, arg);
case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
if (unlikely(!is_tx || !is_vid || !ops->vidioc_s_fmt_vid_out_overlay))
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 25a3190..19c7702 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -238,4 +238,17 @@ static inline int video_is_registered(struct video_device *vdev)
return test_bit(V4L2_FL_REGISTERED, &vdev->flags);
}
+#if defined(CONFIG_MEDIA_CONTROLLER)
+struct video_device_request_data {
+ struct media_entity_request_data data;
+ struct v4l2_pix_format_mplane format;
+};
+
+static inline struct video_device_request_data *
+to_video_device_request_data(struct media_entity_request_data *data)
+{
+ return container_of(data, struct video_device_request_data, data);
+}
+#endif
+
#endif /* _V4L2_DEV_H */
--
1.9.1
next prev parent reply other threads:[~2016-05-06 10:56 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-06 10:53 [RFC 00/22] Media request API Sakari Ailus
2016-05-06 10:53 ` [RFC 01/22] media: Add " Sakari Ailus
2016-05-06 10:53 ` [RFC 02/22] media: Add media device request state Sakari Ailus
2016-05-06 10:53 ` [RFC 03/22] media: Prevent queueing queued requests Sakari Ailus
2016-05-06 10:53 ` [RFC 04/22] media: Only requests in IDLE state may be deleted Sakari Ailus
2016-05-06 10:53 ` [RFC 05/22] media: Add media_device_request_complete() to mark requests complete Sakari Ailus
2016-05-06 10:53 ` [RFC 06/22] media: Add per-entity request data support Sakari Ailus
2016-05-06 10:53 ` [RFC 07/22] videodev2.h: Add request field to v4l2_buffer Sakari Ailus
2016-05-06 10:53 ` [RFC 08/22] videodev2.h: Add request field to v4l2_pix_format_mplane Sakari Ailus
2016-05-06 16:33 ` Nicolas Dufresne
2016-05-06 21:48 ` Sakari Ailus
2016-05-06 10:53 ` [RFC 09/22] v4l2-subdev.h: Add request field to format and selection structures Sakari Ailus
2016-05-06 10:53 ` Sakari Ailus [this message]
2016-05-06 10:53 ` [RFC 11/22] v4l: subdev: Support the request API in format and selection operations Sakari Ailus
2016-05-06 10:53 ` [RFC 12/22] vb2: Add allow_requests flag Sakari Ailus
2016-05-06 10:53 ` [RFC 13/22] vb2: Add helper function to check for request buffers Sakari Ailus
2016-05-06 10:53 ` [RFC 14/22] media: Add MEDIA_IOC_DQEVENT Sakari Ailus
2016-05-06 10:53 ` [RFC 15/22] media: Make events on request completion optional, disabled by default Sakari Ailus
2016-05-06 11:05 ` Sakari Ailus
2016-05-06 10:53 ` [RFC 16/22] media: Add poll support Sakari Ailus
2016-05-06 10:53 ` [RFC 17/22] DocBook: media: Document the media request API Sakari Ailus
2016-05-06 10:53 ` [RFC 18/22] DocBook: media: Document the V4L2 " Sakari Ailus
2016-05-06 10:53 ` [RFC 19/22] DocBook: media: Document the subdev selection API Sakari Ailus
2016-05-06 10:53 ` [RFC 20/22] DocBook: media: Document the V4L2 subdev request API Sakari Ailus
2016-05-06 10:53 ` [RFC 21/22] DocBook: media: Document media events (MEDIA_IOC_DQEVENT IOCTL) Sakari Ailus
2016-05-06 10:53 ` [RFC 22/22] DocBook: media: Document request flags Sakari Ailus
2016-05-06 15:25 ` [RFC 00/22] Media request API Sakari Ailus
2016-05-17 8:05 ` Sakari Ailus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1462532011-15527-11-git-send-email-sakari.ailus@linux.intel.com \
--to=sakari.ailus@linux.intel.com \
--cc=hverkuil@xs4all.nl \
--cc=laurent.pinchart+renesas@ideasonboard.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@osg.samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.