linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Linux Media Mailing List <linux-media@vger.kernel.org>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Hans de Goede <hdegoede@redhat.com>
Subject: [PATCH 06/10] uvcvideo: Refactor uvc_ctrl_get and query
Date: Sun, 25 Mar 2012 13:56:46 +0200	[thread overview]
Message-ID: <1332676610-14953-7-git-send-email-hdegoede@redhat.com> (raw)
In-Reply-To: <1332676610-14953-1-git-send-email-hdegoede@redhat.com>

This is a preparation patch for adding ctrl event support.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/media/video/uvc/uvc_ctrl.c |   69 ++++++++++++++++++++++++------------
 1 file changed, 46 insertions(+), 23 deletions(-)

diff --git a/drivers/media/video/uvc/uvc_ctrl.c b/drivers/media/video/uvc/uvc_ctrl.c
index 0efd3b1..4002b5b 100644
--- a/drivers/media/video/uvc/uvc_ctrl.c
+++ b/drivers/media/video/uvc/uvc_ctrl.c
@@ -899,24 +899,14 @@ static int uvc_ctrl_populate_cache(struct uvc_video_chain *chain,
 	return 0;
 }
 
-int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
+static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
+	struct uvc_control *ctrl,
+	struct uvc_control_mapping *mapping,
 	struct v4l2_queryctrl *v4l2_ctrl)
 {
-	struct uvc_control *ctrl;
-	struct uvc_control_mapping *mapping;
 	struct uvc_menu_info *menu;
 	unsigned int i;
-	int ret;
-
-	ret = mutex_lock_interruptible(&chain->ctrl_mutex);
-	if (ret < 0)
-		return -ERESTARTSYS;
-
-	ctrl = uvc_find_control(chain, v4l2_ctrl->id, &mapping);
-	if (ctrl == NULL) {
-		ret = -EINVAL;
-		goto done;
-	}
+	int ret = 0;
 
 	memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl);
 	v4l2_ctrl->id = mapping->id;
@@ -985,6 +975,28 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
 				  uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));
 
 done:
+	return ret;
+}
+
+int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
+	struct v4l2_queryctrl *v4l2_ctrl)
+{
+	struct uvc_control *ctrl;
+	struct uvc_control_mapping *mapping;
+	int ret;
+
+	ret = mutex_lock_interruptible(&chain->ctrl_mutex);
+	if (ret < 0)
+		return -ERESTARTSYS;
+
+	ctrl = uvc_find_control(chain, v4l2_ctrl->id, &mapping);
+	if (ctrl == NULL) {
+		ret = -EINVAL;
+		goto done;
+	}
+
+	ret = __uvc_query_v4l2_ctrl(chain, ctrl, mapping, v4l2_ctrl);
+done:
 	mutex_unlock(&chain->ctrl_mutex);
 	return ret;
 }
@@ -1148,17 +1160,15 @@ done:
 	return ret;
 }
 
-int uvc_ctrl_get(struct uvc_video_chain *chain,
-	struct v4l2_ext_control *xctrl)
+static int __uvc_ctrl_get(struct uvc_video_chain *chain,
+	struct uvc_control *ctrl, struct uvc_control_mapping *mapping,
+	s32 *value)
 {
-	struct uvc_control *ctrl;
-	struct uvc_control_mapping *mapping;
 	struct uvc_menu_info *menu;
 	unsigned int i;
 	int ret;
 
-	ctrl = uvc_find_control(chain, xctrl->id, &mapping);
-	if (ctrl == NULL || (ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0)
+	if ((ctrl->info.flags & UVC_CTRL_FLAG_GET_CUR) == 0)
 		return -EINVAL;
 
 	if (!ctrl->loaded) {
@@ -1172,14 +1182,14 @@ int uvc_ctrl_get(struct uvc_video_chain *chain,
 		ctrl->loaded = 1;
 	}
 
-	xctrl->value = mapping->get(mapping, UVC_GET_CUR,
+	*value = mapping->get(mapping, UVC_GET_CUR,
 		uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT));
 
 	if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) {
 		menu = mapping->menu_info;
 		for (i = 0; i < mapping->menu_count; ++i, ++menu) {
-			if (menu->value == xctrl->value) {
-				xctrl->value = i;
+			if (menu->value == *value) {
+				*value = i;
 				break;
 			}
 		}
@@ -1188,6 +1198,19 @@ int uvc_ctrl_get(struct uvc_video_chain *chain,
 	return 0;
 }
 
+int uvc_ctrl_get(struct uvc_video_chain *chain,
+	struct v4l2_ext_control *xctrl)
+{
+	struct uvc_control *ctrl;
+	struct uvc_control_mapping *mapping;
+
+	ctrl = uvc_find_control(chain, xctrl->id, &mapping);
+	if (ctrl == NULL)
+		return -EINVAL;
+
+	return __uvc_ctrl_get(chain, ctrl, mapping, &xctrl->value);
+}
+
 int uvc_ctrl_set(struct uvc_video_chain *chain,
 	struct v4l2_ext_control *xctrl)
 {
-- 
1.7.9.3


  parent reply	other threads:[~2012-03-25 11:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-25 11:56 uvc & pwc: Add support for control events (v2) Hans de Goede
2012-03-25 11:56 ` [PATCH 01/10] pwc: Add support for control events Hans de Goede
2012-03-25 11:56 ` [PATCH 02/10] media/radio: use v4l2_ctrl_subscribe_event where possible Hans de Goede
2012-03-25 11:56 ` [PATCH 03/10] v4l2-event: Add v4l2_subscribed_event_ops Hans de Goede
2012-03-25 11:56 ` [PATCH 04/10] v4l2-ctrls: Use v4l2_subscribed_event_ops Hans de Goede
2012-03-25 11:56 ` [PATCH 05/10] uvcvideo: Fix a "ignoring return value of ‘__clear_user’" warning Hans de Goede
2012-03-27 15:48   ` Laurent Pinchart
2012-03-25 11:56 ` Hans de Goede [this message]
2012-03-28  9:26   ` [PATCH 06/10] uvcvideo: Refactor uvc_ctrl_get and query Laurent Pinchart
2012-03-25 11:56 ` [PATCH 07/10] uvcvideo: Move __uvc_ctrl_get() up Hans de Goede
2012-03-28  8:59   ` Laurent Pinchart
2012-03-25 11:56 ` [PATCH 08/10] uvcvideo: Add support for control events Hans de Goede
2012-03-28  9:25   ` Laurent Pinchart
2012-03-25 11:56 ` [PATCH 09/10] uvcvideo: Properly report the inactive flag for inactive controls Hans de Goede
2012-03-28  9:12   ` Laurent Pinchart
2012-03-28 14:09     ` Hans de Goede
2012-04-08 15:19     ` Hans de Goede
2012-03-25 11:56 ` [PATCH 10/10] uvcvideo: Send control change events for slave ctrls when the master changes Hans de Goede
2012-03-28  9:34   ` Laurent Pinchart
2012-03-28 14:11     ` Hans de Goede

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=1332676610-14953-7-git-send-email-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).