From patchwork Mon Feb 8 05:17:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12073891 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DF67C433DB for ; Mon, 8 Feb 2021 05:20:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BCF164E6C for ; Mon, 8 Feb 2021 05:20:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229654AbhBHFTw (ORCPT ); Mon, 8 Feb 2021 00:19:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbhBHFTu (ORCPT ); Mon, 8 Feb 2021 00:19:50 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7684DC061786; Sun, 7 Feb 2021 21:19:10 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id e12so7195223pls.4; Sun, 07 Feb 2021 21:19:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tqO60tUqU9nr/XMWsc6/Nywy5Se8rNTmCzmhTijHWqw=; b=EyjSoTUlvvCBWWcYTD5qORfML23WNYrePGcDk9Skk4+7Mt9Eucactnh8SBiixe6crI h4AZp5VpxHyYxHJ99oYxrvagzkVTCPN90jOrFGBSMgoDuYFiNhO5K+Abz+u4OVvt7Sh8 mSCdh5iG6OwEDP+N92CjnhmLhQ6W4hNTVX5mWXbHQMXzLetHk3pVJvVhbGOpnQAzeEXE rp39Q+kLjazS0YEwb9K18FUzWgh1I5yW/XFsI9UD1e2d4B5aVlWZpKqxfTmWQ8O6V713 Z7caLQtAQSH2KekybAU1meulj2X9ZJgBpINBfo/yzJvcKpB2mykiScbKNJMQoJZ/G6iz TV3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tqO60tUqU9nr/XMWsc6/Nywy5Se8rNTmCzmhTijHWqw=; b=NlzTUrGH3pMkVb1Vk9YPEftJGV6/qNZN5lTqWHz9wfYcn11AQXQsTifpQ+//BY6mmH +8i5WF0SDCke8cBdaVKGk+Sstv42HCgtnr4mlvCzSBrq0Y+koGGtYlsweULNrK5/Zygf 1ybLApf5e50JZpXNE576zZOTm/NnFBhipRhJBZ2MdZSNF6ewmCwZ5DbLO5pYoKFFVDTF ij7zm8B9z4KT5YoH5ra9v5cBV6j8O0zWaxnVoOY00cUIwb07VI+V9fsjEOQZ4PuLCnnm AfezI6b76TIJHPkdWJq3g+0+HWPSkrjNN2MlbZH2waY13uaXvv8r3yzUD1JuGvSaTaya kEsA== X-Gm-Message-State: AOAM533qth50goL5n0i+KkZnCl6JjKtDoOONuR9ebfM8QvgYgPQSEY4M RM2loUlmeMxDGNwhl8ZrIeY= X-Google-Smtp-Source: ABdhPJyZEbLLoLgU1W8k6pSQYnLWWjWewiSfuvEx0NMO4jvbGSkY/ErOBSlqFP2PvKWKRqYJ9fgUmw== X-Received: by 2002:a17:90a:4548:: with SMTP id r8mr15489260pjm.16.1612761549914; Sun, 07 Feb 2021 21:19:09 -0800 (PST) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id 1sm14644458pjk.34.2021.02.07.21.19.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Feb 2021 21:19:09 -0800 (PST) From: Sergey Senozhatsky To: Laurent Pinchart Cc: Tomasz Figa , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, sergey.senozhatsky@gmail.com, Sergey Senozhatsky Subject: [PATCHv2 1/3] media: v4l UAPI docs: document ROI selection targets Date: Mon, 8 Feb 2021 14:17:47 +0900 Message-Id: <20210208051749.1785246-2-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208051749.1785246-1-sergey.senozhatsky@gmail.com> References: <20210208051749.1785246-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky Document new v4l2-selection target which will be used for the Region of Interest v4l2 control. Signed-off-by: Sergey Senozhatsky --- .../media/v4l/selection-api-configuration.rst | 23 +++++++++++++++++++ .../media/v4l/v4l2-selection-targets.rst | 21 +++++++++++++++++ include/uapi/linux/v4l2-common.h | 8 +++++++ 3 files changed, 52 insertions(+) diff --git a/Documentation/userspace-api/media/v4l/selection-api-configuration.rst b/Documentation/userspace-api/media/v4l/selection-api-configuration.rst index fee49bf1a1c0..9f69d71803f6 100644 --- a/Documentation/userspace-api/media/v4l/selection-api-configuration.rst +++ b/Documentation/userspace-api/media/v4l/selection-api-configuration.rst @@ -135,3 +135,26 @@ and the height of rectangles obtained using ``V4L2_SEL_TGT_CROP`` and ``V4L2_SEL_TGT_COMPOSE`` targets. If these are not equal then the scaling is applied. The application can compute the scaling ratios using these values. + +Configuration of Region of Interest (ROI) +========================================= + +The range of coordinates of the top left corner, width and height of +areas that can be ROI is given by the ``V4L2_SEL_TGT_ROI_BOUNDS`` target. +It is recommended for the driver developers to put the top/left corner +at position ``(0,0)``. The rectangle's coordinates are in global sensor +coordinates. The units are in pixels and independent of the field of view. +They are not impacted by any cropping or scaling that is currently being +used. + +The top left corner, width and height of the Region of Interest area +currently being employed by the device is given by the +``V4L2_SEL_TGT_ROI_CURRENT`` target. It uses the same coordinate system +as ``V4L2_SEL_TGT_ROI_BOUNDS``. + +In order to change active ROI top left, width and height coordinates +use ``V4L2_SEL_TGT_ROI`` target. + +Each capture device has a default ROI rectangle, given by the +``V4L2_SEL_TGT_ROI_DEFAULT`` target. Drivers shall set the ROI rectangle +to the default when the driver is first loaded, but not later. diff --git a/Documentation/userspace-api/media/v4l/v4l2-selection-targets.rst b/Documentation/userspace-api/media/v4l/v4l2-selection-targets.rst index e877ebbdb32e..cb3809418fa6 100644 --- a/Documentation/userspace-api/media/v4l/v4l2-selection-targets.rst +++ b/Documentation/userspace-api/media/v4l/v4l2-selection-targets.rst @@ -69,3 +69,24 @@ of the two interfaces they are used. modified by hardware. - Yes - No + * - ``V4L2_SEL_TGT_ROI_CURRENT`` + - 0x0200 + - Current Region of Interest rectangle. + - Yes + - No + * - ``V4L2_SEL_TGT_ROI_DEFAULT`` + - 0x0201 + - Suggested Region of Interest rectangle. + - Yes + - No + * - ``V4L2_SEL_TGT_ROI_BOUNDS`` + - 0x0202 + - Bounds of the Region of Interest rectangle. All valid ROI rectangles fit + inside the ROI bounds rectangle. + - Yes + - No + * - ``V4L2_SEL_TGT_ROI`` + - 0x0203 + - Sets the new Region of Interest rectangle. + - Yes + - No diff --git a/include/uapi/linux/v4l2-common.h b/include/uapi/linux/v4l2-common.h index 7d21c1634b4d..d0c108fba638 100644 --- a/include/uapi/linux/v4l2-common.h +++ b/include/uapi/linux/v4l2-common.h @@ -78,6 +78,14 @@ #define V4L2_SEL_TGT_COMPOSE_BOUNDS 0x0102 /* Current composing area plus all padding pixels */ #define V4L2_SEL_TGT_COMPOSE_PADDED 0x0103 +/* Current Region of Interest area */ +#define V4L2_SEL_TGT_ROI_CURRENT 0x0200 +/* Default Region of Interest area */ +#define V4L2_SEL_TGT_ROI_DEFAULT 0x0201 +/* Region of Interest bounds */ +#define V4L2_SEL_TGT_ROI_BOUNDS 0x0202 +/* Set Region of Interest area */ +#define V4L2_SEL_TGT_ROI 0x0203 /* Selection flags */ #define V4L2_SEL_FLAG_GE (1 << 0) From patchwork Mon Feb 8 05:17:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12073893 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6BF6C43381 for ; Mon, 8 Feb 2021 05:20:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 97E3C64E6B for ; Mon, 8 Feb 2021 05:20:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229705AbhBHFT4 (ORCPT ); Mon, 8 Feb 2021 00:19:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbhBHFTy (ORCPT ); Mon, 8 Feb 2021 00:19:54 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15919C061788; Sun, 7 Feb 2021 21:19:14 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id z9so8113603pjl.5; Sun, 07 Feb 2021 21:19:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R/cys4fKGzGYJ+TE5kF+dhLs7puKNz2YuqBkYhaB6Lc=; b=gNyMr6ocMASJX/9vzRW0FISKHYAR7frYmmvHqoZbdrJjlkhGihKWeI8smzu27GUF0y fYMydjl5IQqlwHUEU0pG1+NMCOMZZwX9NaSr0cYWY/HPmql2ixYwOIqhhGf+ysfhZ8pL m/KkxJKvYeWrxljoCM0iOx/213UUjPmVn3qvhcQq1df8WRjoo3B2szmHCrmR/fPLFyvb XJ/liTt3qvtItNEkQAO4YL/Mi4K0oMJv2YuoB7AL2GMq6tHT1FXfzj/JmBHzpFrvEwlC zhUk2khsZMWQbMXEdx8P8umn/SFFAAXIXyJ4TkBonev3t7XMYVl2q7OhZsxU1V5cLj8M N8ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R/cys4fKGzGYJ+TE5kF+dhLs7puKNz2YuqBkYhaB6Lc=; b=DDF7zATocu49EE/T/E/wlRvjPjWwgs0d4n/c/h47D2IsHNtjCZFoZ0l8ScZzCNUDeu f7fllTWFey3ilbuzPFP2wICAzSMQXNixFv21P6NlidI/Tr7Fy2vv3RlpsZqse3NvYNQ7 5jpgswfblkYrYpW2QRK9XZSKHR+np8Q23yKKk38cZh17UeziFE8Cuby3HbCJ/fZ8lnje V8kcanvUBmd5hez6MDhlx0o+BSS9vrVZij+4gPfiUY8lJnbZQn+8ECR9Gu28m0pyWgyc ckIlWO5JdHsUVkdQqomHJC22pHegR2p6v7JQ6SOGoCq/pNGtvuriosw9mGI7mmbRsdLq DP/A== X-Gm-Message-State: AOAM532GBXMPos09cgQ/w4aQFRz1JiG9O1KZlXEnlC4Q+KFoOYllzADh pcD9DZJelmj8f/0peV3GlIk= X-Google-Smtp-Source: ABdhPJzRYuvnZ+/Y2XiRdFxX6bQQybPGTtOwKxZf2rdf6Ugk5JalSjfAVzeSW7/PBUSL+GOMvjF6Fw== X-Received: by 2002:a17:902:778e:b029:de:b475:c430 with SMTP id o14-20020a170902778eb02900deb475c430mr14697382pll.53.1612761553582; Sun, 07 Feb 2021 21:19:13 -0800 (PST) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id 1sm14644458pjk.34.2021.02.07.21.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Feb 2021 21:19:12 -0800 (PST) From: Sergey Senozhatsky To: Laurent Pinchart Cc: Tomasz Figa , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, sergey.senozhatsky@gmail.com, Sergey Senozhatsky Subject: [PATCHv2 2/3] media: uvcvideo: add ROI auto controls Date: Mon, 8 Feb 2021 14:17:48 +0900 Message-Id: <20210208051749.1785246-3-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208051749.1785246-1-sergey.senozhatsky@gmail.com> References: <20210208051749.1785246-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky This patch adds support for Region of Interest bmAutoControls. ROI control is a compound data type: Control Selector CT_REGION_OF_INTEREST_CONTROL Mandatory Requests SET_CUR, GET_CUR, GET_MIN, GET_MAX, GET_DEF wLength 10 Offset Field Size 0 wROI_Top 2 2 wROI_Left 2 4 wROI_Bottom 2 6 wROI_Right 2 8 bmAutoControls 2 (Bitmap) uvc_control_mapping, however, can handle only s32 data type at the moment: ->get() returns s32 value, ->set() accepts s32 value; while v4l2_ctrl maximum/minimum/default_value can hold only s64 values. Hence ROI control handling is split into two patches: a) bmAutoControls is handled via uvc_control_mapping as V4L2_CTRL_TYPE_MENU b) ROI rectangle (SET_CUR, GET_CUR, GET_DEF) handling is implemented separately, by the means of selection API. Signed-off-by: Sergey Senozhatsky --- .../media/v4l/ext-ctrls-camera.rst | 25 +++++++++++++++++++ drivers/media/usb/uvc/uvc_ctrl.c | 19 ++++++++++++++ include/uapi/linux/usb/video.h | 1 + include/uapi/linux/v4l2-controls.h | 9 +++++++ 4 files changed, 54 insertions(+) diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst b/Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst index c05a2d2c675d..1593c999c8e2 100644 --- a/Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +++ b/Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst @@ -653,6 +653,31 @@ enum v4l2_scene_mode - | | +--------------------+ +``V4L2_CID_REGION_OF_INTEREST_AUTO (bitmask)`` + This determines which, if any, on board features should track to the + Region of Interest. + +.. flat-table:: + :header-rows: 0 + :stub-columns: 0 + + * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_EXPOSURE`` + - Auto Exposure. + * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_IRIS`` + - Auto Iris. + * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_WHITE_BALANCE`` + - Auto White Balance. + * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_FOCUS`` + - Auto Focus. + * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_FACE_DETECT`` + - Auto Face Detect. + * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK`` + - Auto Detect and Track. + * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_IMAGE_STABILIXATION`` + - Image Stabilization. + * - ``V4L2_CID_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY`` + - Higher Quality. + .. [#f1] This control may be changed to a menu control in the future, if more diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index b3dde98499f4..5502fe540519 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -355,6 +355,15 @@ static const struct uvc_control_info uvc_ctrls[] = { .flags = UVC_CTRL_FLAG_GET_CUR | UVC_CTRL_FLAG_AUTO_UPDATE, }, + { + .entity = UVC_GUID_UVC_CAMERA, + .selector = UVC_CT_REGION_OF_INTEREST_CONTROL, + .index = 21, + .size = 10, + .flags = UVC_CTRL_FLAG_SET_CUR | UVC_CTRL_FLAG_GET_CUR + | UVC_CTRL_FLAG_GET_MIN | UVC_CTRL_FLAG_GET_MAX + | UVC_CTRL_FLAG_GET_DEF + }, }; static const struct uvc_menu_info power_line_frequency_controls[] = { @@ -753,6 +762,16 @@ static const struct uvc_control_mapping uvc_ctrl_mappings[] = { .v4l2_type = V4L2_CTRL_TYPE_BOOLEAN, .data_type = UVC_CTRL_DATA_TYPE_BOOLEAN, }, + { + .id = V4L2_CID_REGION_OF_INTEREST_AUTO, + .name = "Region of Interest (auto)", + .entity = UVC_GUID_UVC_CAMERA, + .selector = UVC_CT_REGION_OF_INTEREST_CONTROL, + .size = 16, + .offset = 64, + .v4l2_type = V4L2_CTRL_TYPE_BITMASK, + .data_type = UVC_CTRL_DATA_TYPE_BITMASK, + }, }; /* ------------------------------------------------------------------------ diff --git a/include/uapi/linux/usb/video.h b/include/uapi/linux/usb/video.h index d854cb19c42c..c87624962896 100644 --- a/include/uapi/linux/usb/video.h +++ b/include/uapi/linux/usb/video.h @@ -104,6 +104,7 @@ #define UVC_CT_ROLL_ABSOLUTE_CONTROL 0x0f #define UVC_CT_ROLL_RELATIVE_CONTROL 0x10 #define UVC_CT_PRIVACY_CONTROL 0x11 +#define UVC_CT_REGION_OF_INTEREST_CONTROL 0x14 /* A.9.5. Processing Unit Control Selectors */ #define UVC_PU_CONTROL_UNDEFINED 0x00 diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h index 039c0d7add1b..6a3dac481cb4 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -976,6 +976,15 @@ enum v4l2_auto_focus_range { #define V4L2_CID_PAN_SPEED (V4L2_CID_CAMERA_CLASS_BASE+32) #define V4L2_CID_TILT_SPEED (V4L2_CID_CAMERA_CLASS_BASE+33) +#define V4L2_CID_REGION_OF_INTEREST_AUTO (V4L2_CID_CAMERA_CLASS_BASE+34) +#define V4L2_CID_REGION_OF_INTEREST_AUTO_EXPOSURE (1 << 0) +#define V4L2_CID_REGION_OF_INTEREST_AUTO_IRIS (1 << 1) +#define V4L2_CID_REGION_OF_INTEREST_AUTO_WHITE_BALANCE (1 << 2) +#define V4L2_CID_REGION_OF_INTEREST_AUTO_FOCUS (1 << 3) +#define V4L2_CID_REGION_OF_INTEREST_AUTO_FACE_DETECT (1 << 4) +#define V4L2_CID_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK (1 << 5) +#define V4L2_CID_REGION_OF_INTEREST_AUTO_IMAGE_STABILIXATION (1 << 6) +#define V4L2_CID_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY (1 << 7) #define V4L2_CID_CAMERA_ORIENTATION (V4L2_CID_CAMERA_CLASS_BASE+34) #define V4L2_CAMERA_ORIENTATION_FRONT 0 From patchwork Mon Feb 8 05:17:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12073895 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62199C433DB for ; Mon, 8 Feb 2021 05:20:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21E2E64E6A for ; Mon, 8 Feb 2021 05:20:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbhBHFT7 (ORCPT ); Mon, 8 Feb 2021 00:19:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229715AbhBHFT5 (ORCPT ); Mon, 8 Feb 2021 00:19:57 -0500 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5221C06178A; Sun, 7 Feb 2021 21:19:17 -0800 (PST) Received: by mail-pl1-x632.google.com with SMTP id y10so7188163plk.7; Sun, 07 Feb 2021 21:19:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=It5Ch/nqC0qJ8EYUTBnD11LjDHOdhSlQ+XoGvBTRd6s=; b=jnySY9sJVNoFTy9SF3Y9LamrcgJ/Awy9JA5iyjA4UynBbnaEm+zJEzzZeZKmQ5XhzS rmqoU6bT7qlDXlTcxNZ/0JCXgUohaZ+9g9B8ofkDeBgJAFlXelIN+bGsoFXMS3/7N2C/ kTW/oD0zHtazk8m4QdCksTwPpOkanEsqqCtAWzcbqaFuPrzhzI+tRmfGAwBp9zXeKOyL Arh4+1bOx55UEkKqG3WYd2ASN0vaCnRdoRqT95w2t7T8Hk4GTWf7AxrGYJc6pfEhD+PA js6HPLJMB3uYiFRjOkcDy64jSMjMDqvTqzLafPDL5AR5Ei31+qg6zx9vt+AuKQHMJDeB 78UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=It5Ch/nqC0qJ8EYUTBnD11LjDHOdhSlQ+XoGvBTRd6s=; b=PG/lm25KOCWOM4T+wIb1z47UYqVTZ2bFEguqg6eQ8erfbF1j7h15eACUHP2iTBoQnz QUjMHGcDX9usx/BgOmeUOMHJsnaqntASCRUjls9t1MC9trxamB1uOU2UPQL+eM14Owhn MTLTg6uc6V2+8WbpcbMWjwY5YIKIddoEaSkxh0mIu2/3xvANMPSZ3KSjorbdArm8Qly2 mcOladzlOV5YIxHpAF4dVHiUut+P47PXLjYbwqLTfCo3qDs8bTKD5msHzlrPtAqU2K9K Of8HGPTMPUNngMRMkCIYQRnsK+dOqVIrijOmx0m+pj8KR1PNpXwS51ae/UGPjP0wFH6N fYUA== X-Gm-Message-State: AOAM531tmeaDzeovKZ4XaTY+vY2CsvBUjLvGJTMFpl4sQAMOiq+z/5/m mMvpivPOmTSRqa9mAzQ5/Pq8cFwElxhQNg== X-Google-Smtp-Source: ABdhPJxc8wbfBYAODw/Hgw93VnAwvCNxjuSxrM1PqhrrwfPBUbOyszjqeP1KhzYrECTIrFR0N//fcQ== X-Received: by 2002:a17:902:c9d2:b029:e2:ad28:65e8 with SMTP id q18-20020a170902c9d2b02900e2ad2865e8mr14810308pld.85.1612761557176; Sun, 07 Feb 2021 21:19:17 -0800 (PST) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id 1sm14644458pjk.34.2021.02.07.21.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Feb 2021 21:19:16 -0800 (PST) From: Sergey Senozhatsky To: Laurent Pinchart Cc: Tomasz Figa , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, sergey.senozhatsky@gmail.com, Sergey Senozhatsky Subject: [PATCHv2 3/3] media: uvcvideo: add UVC 1.5 ROI control Date: Mon, 8 Feb 2021 14:17:49 +0900 Message-Id: <20210208051749.1785246-4-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208051749.1785246-1-sergey.senozhatsky@gmail.com> References: <20210208051749.1785246-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky This patch implements parts of UVC 1.5 Region of Interest (ROI) control, using the uvcvideo selection API. There are several things to mention here. First, UVC 1.5 defines CT_DIGITAL_WINDOW_CONTROL; and ROI rectangle coordinates "must be within the current Digital Window as specified by the CT_WINDOW control." (4.2.2.1.20 Digital Region of Interest (ROI) Control.) This is not entirely clear if we need to implement CT_DIGITAL_WINDOW_CONTROL. ROI is naturally limited by: ROI GET_MIN and GET_MAX rectangles. Besides, the H/W that I'm playing with implements ROI, but doesn't implement CT_DIGITAL_WINDOW_CONTROL, so WINDOW_CONTROL is probably optional. Second, the patch doesn't implement all of the ROI requests. Namely, SEL_TGT_BOUNDS for ROI implements GET_MAX (that is maximal ROI rectangle area). GET_MIN is not implemented (as of now) since it's not very clear if user space would need such information. Signed-off-by: Sergey Senozhatsky --- drivers/media/usb/uvc/uvc_v4l2.c | 143 ++++++++++++++++++++++++++++++- 1 file changed, 140 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 252136cc885c..71b4577196e5 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1139,14 +1139,60 @@ static int uvc_ioctl_querymenu(struct file *file, void *fh, return uvc_query_v4l2_menu(chain, qm); } -static int uvc_ioctl_g_selection(struct file *file, void *fh, - struct v4l2_selection *sel) +/* UVC 1.5 ROI rectangle is half the size of v4l2_rect */ +struct uvc_roi_rect { + __u16 top; + __u16 left; + __u16 bottom; + __u16 right; +}; + +static int uvc_ioctl_g_roi_target(struct file *file, void *fh, + struct v4l2_selection *sel) { struct uvc_fh *handle = fh; struct uvc_streaming *stream = handle->stream; + struct uvc_roi_rect *roi; + u8 query; + int ret; - if (sel->type != stream->type) + switch (sel->target) { + case V4L2_SEL_TGT_ROI_DEFAULT: + query = UVC_GET_DEF; + break; + case V4L2_SEL_TGT_ROI_CURRENT: + query = UVC_GET_CUR; + break; + case V4L2_SEL_TGT_ROI_BOUNDS: + query = UVC_GET_MAX; + break; + default: return -EINVAL; + } + + roi = kzalloc(sizeof(struct uvc_roi_rect), GFP_KERNEL); + if (!roi) + return -ENOMEM; + + ret = uvc_query_ctrl(stream->dev, query, 1, stream->dev->intfnum, + UVC_CT_REGION_OF_INTEREST_CONTROL, roi, + sizeof(struct uvc_roi_rect)); + if (!ret) { + sel->r.left = roi->left; + sel->r.top = roi->top; + sel->r.width = roi->right; + sel->r.height = roi->bottom; + } + + kfree(roi); + return ret; +} + +static int uvc_ioctl_g_sel_target(struct file *file, void *fh, + struct v4l2_selection *sel) +{ + struct uvc_fh *handle = fh; + struct uvc_streaming *stream = handle->stream; switch (sel->target) { case V4L2_SEL_TGT_CROP_DEFAULT: @@ -1173,6 +1219,96 @@ static int uvc_ioctl_g_selection(struct file *file, void *fh, return 0; } +static int uvc_ioctl_g_selection(struct file *file, void *fh, + struct v4l2_selection *sel) +{ + struct uvc_fh *handle = fh; + struct uvc_streaming *stream = handle->stream; + + if (sel->type != stream->type) + return -EINVAL; + + switch (sel->target) { + case V4L2_SEL_TGT_CROP_DEFAULT: + case V4L2_SEL_TGT_CROP_BOUNDS: + case V4L2_SEL_TGT_COMPOSE_DEFAULT: + case V4L2_SEL_TGT_COMPOSE_BOUNDS: + return uvc_ioctl_g_sel_target(file, fh, sel); + case V4L2_SEL_TGT_ROI_CURRENT: + case V4L2_SEL_TGT_ROI_DEFAULT: + case V4L2_SEL_TGT_ROI_BOUNDS: + return uvc_ioctl_g_roi_target(file, fh, sel); + } + + return -EINVAL; +} + +static bool validate_roi_bounds(struct uvc_streaming *stream, + struct v4l2_selection *sel) +{ + bool ok = true; + + if (sel->r.left > USHRT_MAX || sel->r.top > USHRT_MAX || + sel->r.width > USHRT_MAX || sel->r.height > USHRT_MAX) + return false; + + /* perhaps also can test against ROI GET_MAX */ + + mutex_lock(&stream->mutex); + if ((u16)sel->r.width > stream->cur_frame->wWidth) + ok = false; + if ((u16)sel->r.height > stream->cur_frame->wHeight) + ok = false; + mutex_unlock(&stream->mutex); + + return ok; +} + +static int uvc_ioctl_s_roi(struct file *file, void *fh, + struct v4l2_selection *sel) +{ + struct uvc_fh *handle = fh; + struct uvc_streaming *stream = handle->stream; + struct uvc_roi_rect *roi; + int ret; + + if (!validate_roi_bounds(stream, sel)) + return -E2BIG; + + roi = kzalloc(sizeof(struct uvc_roi_rect), GFP_KERNEL); + if (!roi) + return -ENOMEM; + + roi->left = sel->r.left; + roi->top = sel->r.top; + roi->right = sel->r.width; + roi->bottom = sel->r.height; + + ret = uvc_query_ctrl(stream->dev, UVC_SET_CUR, 1, stream->dev->intfnum, + UVC_CT_REGION_OF_INTEREST_CONTROL, roi, + sizeof(struct uvc_roi_rect)); + + kfree(roi); + return ret; +} + +static int uvc_ioctl_s_selection(struct file *file, void *fh, + struct v4l2_selection *sel) +{ + struct uvc_fh *handle = fh; + struct uvc_streaming *stream = handle->stream; + + if (sel->type != stream->type) + return -EINVAL; + + switch (sel->target) { + case V4L2_SEL_TGT_ROI: + return uvc_ioctl_s_roi(file, fh, sel); + } + + return -EINVAL; +} + static int uvc_ioctl_g_parm(struct file *file, void *fh, struct v4l2_streamparm *parm) { @@ -1533,6 +1669,7 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops = { .vidioc_try_ext_ctrls = uvc_ioctl_try_ext_ctrls, .vidioc_querymenu = uvc_ioctl_querymenu, .vidioc_g_selection = uvc_ioctl_g_selection, + .vidioc_s_selection = uvc_ioctl_s_selection, .vidioc_g_parm = uvc_ioctl_g_parm, .vidioc_s_parm = uvc_ioctl_s_parm, .vidioc_enum_framesizes = uvc_ioctl_enum_framesizes,