Skip to contentSkip to conversation

media: uvcvideo: UVC minimum relative pan/tilt/zoom speed fix

PATCH New Gergo Koteles 1 participant 2 messages Jun 19, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover media: uvcvideo: UVC minimum relative pan/tilt/zoom speed fix

Hello,

I applied Ricardo's suggestion.
And I found a few ways to improve the style.

I've also added Ricardo's reviewed-by tag as these are just style changes.

---
Changes in v4:
- Based on Ricardo's suggestion, only query the min value in uvc_ctrl_set if necessary
- Rename is_relative_ptz_ctrl function to uvc_ctrl_is_relative_ptz for consistency
- Rename 'relative speed implementation' to 'relative PTZ controls' in comments
- Fix indentation of comments
- Reduce the length of the new lines to 80
- Link to v3: https://lore.kernel.org/all/[email protected]/

Changes in v3:
- Based on Ricardo's suggestion, I squashed the two patches.
- Link to v2: https://lore.kernel.org/all/20240405-uvc-fix-relative-ptz-speed-v1-0-c32cdb2a899d@securitylive.com/

Changes in v2:
- Made recommended changes, moved control check to helper function and removed dead code.
- Link to v1: https://lore.kernel.org/all/20240326-uvc-relative-ptz-speed-fix-v1-1-453fd5ccfd37@securitylive.com/
---
John Bauer (1):
media: uvcvideo: UVC minimum relative pan/tilt/zoom speed fix.

 drivers/media/usb/uvc/uvc_ctrl.c | 42 ++++++++++++++++++++++++++------
 1 file changed, 35 insertions(+), 7 deletions(-)
Signature · 4 lines
2.45.2

Best regards,
Gergo Koteles
#1 lore raw

PATCH v4 1/1 media: uvcvideo: UVC minimum relative pan/tilt/zoom speed fix.

From: John Bauer <[email protected]>

The minimum UVC control value for the relative pan/tilt/zoom speeds cannot be probed as the implementation condenses the pan and tilt direction and speed into two 16 bit values. The minimum cannot be set at probe time because it is probed first and the maximum is not yet known. With this fix if a relative speed control is queried or set the minimum is set and checked based on the additive inverse of the maximum at that time.

---
 drivers/media/usb/uvc/uvc_ctrl.c | 42 ++++++++++++++++++++++++++------
 1 file changed, 35 insertions(+), 7 deletions(-)
drivers/media/usb/uvc/uvc_ctrl.c +35 -7
index 4b685f883e4d..14080eafedf5 100644
@@ -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 uvc_ctrl_is_relative_ptz(__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,
@@ -1322,14 +1332,23 @@ static int __uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
 		break;
 	}
 
-	if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN)
-		v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN,
-				     uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN));
-
 	if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MAX)
 		v4l2_ctrl->maximum = mapping->get(mapping, UVC_GET_MAX,
 				     uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX));
 
+	if (ctrl->info.flags & UVC_CTRL_FLAG_GET_MIN) {
+		/*
+		 * For the relative PTZ controls the minimum value cannot be
+		 * probed so it becomes the additive inverse of maximum.
+		 */
+		if (uvc_ctrl_is_relative_ptz(v4l2_ctrl->id))
+			v4l2_ctrl->minimum = -v4l2_ctrl->maximum;
+		else
+			v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN,
+					     uvc_ctrl_data(ctrl,
+							   UVC_CTRL_DATA_MIN));
+	}
+
 	if (ctrl->info.flags & UVC_CTRL_FLAG_GET_RES)
 		v4l2_ctrl->step = mapping->get(mapping, UVC_GET_RES,
 				  uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));
@@ -1912,10 +1931,19 @@ int uvc_ctrl_set(struct uvc_fh *handle,
 				return ret;
 		}
 
-		min = mapping->get(mapping, UVC_GET_MIN,
-				   uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN));
 		max = mapping->get(mapping, UVC_GET_MAX,
 				   uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX));
+
+		/*
+		 * For the relative PTZ controls the minimum value cannot be
+		 * probed so it becomes the additive inverse of maximum.
+		 */
+		if (uvc_ctrl_is_relative_ptz(xctrl->id))
+			min = -max;
+		else
+			min = mapping->get(mapping, UVC_GET_MIN,
+			      uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN));
+
 		step = mapping->get(mapping, UVC_GET_RES,
 				    uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));
 		if (step == 0)
Signature · 1 line
2.45.2