linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/1] media: uvcvideo: UVC minimum relative pan/tilt/zoom speed fix
@ 2024-06-18 16:32 Gergo Koteles
  2024-06-18 16:32 ` [PATCH v3 1/1] " Gergo Koteles
  0 siblings, 1 reply; 4+ messages in thread
From: Gergo Koteles @ 2024-06-18 16:32 UTC (permalink / raw)
  To: Laurent Pinchart, Mauro Carvalho Chehab, John Bauer, ribalda,
	linh.tp.vu
  Cc: linux-media, linux-kernel, Gergo Koteles

Hello,

I am picking up John's series.

---
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 | 38 +++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

-- 
2.45.2

Best regards,
Gergo Koteles

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 1/1] media: uvcvideo: UVC minimum relative pan/tilt/zoom speed fix.
  2024-06-18 16:32 [PATCH v3 0/1] media: uvcvideo: UVC minimum relative pan/tilt/zoom speed fix Gergo Koteles
@ 2024-06-18 16:32 ` Gergo Koteles
  2024-06-19  6:15   ` Ricardo Ribalda
  0 siblings, 1 reply; 4+ messages in thread
From: Gergo Koteles @ 2024-06-18 16:32 UTC (permalink / raw)
  To: Laurent Pinchart, Mauro Carvalho Chehab, John Bauer, ribalda,
	linh.tp.vu
  Cc: linux-media, linux-kernel, Gergo Koteles

From: John Bauer <johnebgood@securitylive.com>

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.

Signed-off-by: John Bauer <johnebgood@securitylive.com>
Signed-off-by: Gergo Koteles <soyer@irl.hu>
---
 drivers/media/usb/uvc/uvc_ctrl.c | 38 +++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index 4b685f883e4d..93ed2462e90b 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,
@@ -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 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;
+		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));
@@ -1916,6 +1935,15 @@ int uvc_ctrl_set(struct uvc_fh *handle,
 				   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 speed implementation the minimum
+		 * value cannot be probed so it becomes the additive
+		 * inverse of maximum.
+		 */
+		if (is_relative_ptz_ctrl(xctrl->id))
+			min = -max;
+
 		step = mapping->get(mapping, UVC_GET_RES,
 				    uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));
 		if (step == 0)
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 1/1] media: uvcvideo: UVC minimum relative pan/tilt/zoom speed fix.
  2024-06-18 16:32 ` [PATCH v3 1/1] " Gergo Koteles
@ 2024-06-19  6:15   ` Ricardo Ribalda
  2024-06-19 23:04     ` Gergo Koteles
  0 siblings, 1 reply; 4+ messages in thread
From: Ricardo Ribalda @ 2024-06-19  6:15 UTC (permalink / raw)
  To: Gergo Koteles
  Cc: Laurent Pinchart, Mauro Carvalho Chehab, John Bauer, linh.tp.vu,
	linux-media, linux-kernel

Hi Gergo

Thanks for your your patch.

On Tue, 18 Jun 2024 at 18:33, Gergo Koteles <soyer@irl.hu> wrote:
>
> From: John Bauer <johnebgood@securitylive.com>
>
> 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.
>
> Signed-off-by: John Bauer <johnebgood@securitylive.com>
> Signed-off-by: Gergo Koteles <soyer@irl.hu>

Reviewed-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
>  drivers/media/usb/uvc/uvc_ctrl.c | 38 +++++++++++++++++++++++++++-----
>  1 file changed, 33 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
> index 4b685f883e4d..93ed2462e90b 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,
> @@ -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 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;
> +               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));
> @@ -1916,6 +1935,15 @@ int uvc_ctrl_set(struct uvc_fh *handle,
>                                    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 speed implementation the minimum
> +                * value cannot be probed so it becomes the additive
> +                * inverse of maximum.
> +                */
> +               if (is_relative_ptz_ctrl(xctrl->id))
> +                       min = -max;
> +

nit: The following would probably be more correct but less clear:

if  (is_relative_ptz_ctrl(xctrl->id))
    min = -max;
else
    min = mapping->get(mapping, UVC_GET_MIN,...)

So up to you what do you/Laurent what is better ;)

>                 step = mapping->get(mapping, UVC_GET_RES,
>                                     uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));
>                 if (step == 0)
> --
> 2.45.2
>


-- 
Ricardo Ribalda

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 1/1] media: uvcvideo: UVC minimum relative pan/tilt/zoom speed fix.
  2024-06-19  6:15   ` Ricardo Ribalda
@ 2024-06-19 23:04     ` Gergo Koteles
  0 siblings, 0 replies; 4+ messages in thread
From: Gergo Koteles @ 2024-06-19 23:04 UTC (permalink / raw)
  To: Ricardo Ribalda
  Cc: Laurent Pinchart, Mauro Carvalho Chehab, John Bauer, linh.tp.vu,
	linux-media, linux-kernel

Hi Ricardo,

Thanks for the review.

On Wed, 2024-06-19 at 08:15 +0200, Ricardo Ribalda wrote:
> 
> nit: The following would probably be more correct but less clear:
> 
> if  (is_relative_ptz_ctrl(xctrl->id))
>     min = -max;
> else
>     min = mapping->get(mapping, UVC_GET_MIN,...)
> 
> So up to you what do you/Laurent what is better ;)
> 

> 
I like this better. I'll send a v4.

Best regards,
Gergo Koteles


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-19 23:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-18 16:32 [PATCH v3 0/1] media: uvcvideo: UVC minimum relative pan/tilt/zoom speed fix Gergo Koteles
2024-06-18 16:32 ` [PATCH v3 1/1] " Gergo Koteles
2024-06-19  6:15   ` Ricardo Ribalda
2024-06-19 23:04     ` Gergo Koteles

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).