b4-sent.feeds.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Bauer <johnebgood@securitylive.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	 Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linh.tp.vu@gmail.com, ribalda@chromium.org, soyer@irl.hu,
	 John Bauer <johnebgood@securitylive.com>
Subject: [PATCH 3/3] media: uvcvideo: Moved control checks to helper function
Date: Wed, 03 Apr 2024 14:58:09 -0500	[thread overview]
Message-ID: <20240403-uvc-fix-relative-ptz-speed-v1-3-624c9267f745@securitylive.com> (raw)
In-Reply-To: <20240403-uvc-fix-relative-ptz-speed-v1-0-624c9267f745@securitylive.com>

Made additional recommended changes from Ricardo. Relative
controls are now checked with helper function is_relative_ptz_ctrl().

Signed-off-by: John Bauer <johnebgood@securitylive.com>
---
 drivers/media/usb/uvc/uvc_ctrl.c | 40 +++++++++++++++++++---------------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index 04300a782c81..34a9a29b0754 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -441,7 +441,6 @@ static s32 uvc_ctrl_get_rel_speed(struct uvc_control_mapping *mapping,
 		return (rel == 0) ? 0 : (rel > 0 ? data[first+1]
 						 : -data[first+1]);
 	case UVC_GET_MIN:
-		return -data[first+1];
 	case UVC_GET_MAX:
 	case UVC_GET_RES:
 	case UVC_GET_DEF:
@@ -1233,6 +1232,17 @@ static u32 uvc_get_ctrl_bitmap(struct uvc_control *ctrl,
 	return ~0;
 }
 
+static bool is_relative_ptz_ctrl(__u32 ctrl_id)
+{
+	switch (ctrl_id) {
+	case V4L2_CID_ZOOM_CONTINUOUS:
+	case V4L2_CID_PAN_SPEED:
+	case V4L2_CID_TILT_SPEED:
+		return true;
+	}
+	return false;
+}
+
 static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
 	struct uvc_control *ctrl,
 	struct uvc_control_mapping *mapping,
@@ -1327,22 +1337,16 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
 				     uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX));
 
 	if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) {
-		switch (v4l2_ctrl->id) {
-		case V4L2_CID_ZOOM_CONTINUOUS:
-		case V4L2_CID_PAN_SPEED:
-		case V4L2_CID_TILT_SPEED:
-			/*
-			 * For the relative speed implementation the minimum
-			 * value cannot be probed so it becomes the additive
-			 * inverse of maximum.
-			 */
+		/*
+		 * For the relative speed implementation the minimum
+		 * value cannot be probed so it becomes the additive
+		 * inverse of maximum.
+		 */
+		if (is_relative_ptz_ctrl(v4l2_ctrl->id))
 			v4l2_ctrl->minimum = -v4l2_ctrl->maximum;
-			break;
-		default:
+		else
 			v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN,
 						uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN));
-			break;
-		}
 	}
 
 	if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES)
@@ -1935,14 +1939,8 @@ int uvc_ctrl_set(struct uvc_fh *handle,
 		 * value cannot be probed so it becomes the additive
 		 * inverse of maximum.
 		 */
-		switch (xctrl->id) {
-		case V4L2_CID_ZOOM_CONTINUOUS:
-		case V4L2_CID_PAN_SPEED:
-		case V4L2_CID_TILT_SPEED:
+		if (is_relative_ptz_ctrl(xctrl->id))
 			min = -max;
-		default:
-			break;
-		}
 
 		step = mapping->get(mapping, UVC_GET_RES,
 				    uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));

-- 
2.34.1


      parent reply	other threads:[~2024-04-03 19:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03 19:58 [PATCH 0/3] media: uvcvideo: UVC minimum relative pan/tilt/zoom speed fix John Bauer
2024-04-03 19:58 ` [PATCH 1/3] " John Bauer
2024-04-03 19:58 ` [PATCH 2/3] " John Bauer
2024-04-03 19:58 ` John Bauer [this message]

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=20240403-uvc-fix-relative-ptz-speed-v1-3-624c9267f745@securitylive.com \
    --to=johnebgood@securitylive.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linh.tp.vu@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=ribalda@chromium.org \
    --cc=soyer@irl.hu \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).