From patchwork Fri Apr 30 11:26:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12233071 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=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 F3BD6C433B4 for ; Fri, 30 Apr 2021 11:26:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD0366145D for ; Fri, 30 Apr 2021 11:26:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231795AbhD3L1L (ORCPT ); Fri, 30 Apr 2021 07:27:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229543AbhD3L1K (ORCPT ); Fri, 30 Apr 2021 07:27:10 -0400 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 BE1B6C06138B for ; Fri, 30 Apr 2021 04:26:21 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id t21so5324851plo.2 for ; Fri, 30 Apr 2021 04:26:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ylnHk+JNuqq5ZmDFacYDEfwOgLykql+ZShEQSvQwkpU=; b=I5CJcszoEnVMCJRX73o9D+zV2auj6LWS7feT05oebev/wKacdLL+3prEoQ9oDl4iht obAOaZ5+Zk2EoVnfTavi/QcQSb3W1/0nC67S4kgZT5HTp2MapwiLvlkSlKrm0TJM8WxR MyALGWO4qZkltcqkR2v9T9XRH86bhxsvF5K7s= 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=ylnHk+JNuqq5ZmDFacYDEfwOgLykql+ZShEQSvQwkpU=; b=tlYXNL6axr5JXU0F5NbUMMrYJcCOUZlZD0DWheLXkgJQ+N/5ifxDstROCopaFW/eTF UroS5qKGekewPjf1xaRBxApqzEq2XE8kp6Umm01T3QPKcE5H+enw2xg8G9l9rvOoCOwU SdwaqFsXTHRiI7oorl3DFlACMO6kTetj6pwGofUZEUYcv5byDUugFqFOSFvlFGM/5cHr 8EZzCR472I1lLy/zZ/TCBfhGbWi4BbSZc+i40IK4xkdepy/f2QqbDLg9YG1deVFphdLa 9oPf+Fz1ANEDOOTIuFlCgiWaFgfN2wOwio37vhZtZElntN3DEUHZMxs+aep45/dvLaHJ /AHg== X-Gm-Message-State: AOAM531gat2/dr+msUBWia2hDP+EiAvZzTp87FKoza5xq6iapRkk9Dz5 xlma2B87YjK+0Qox7eOoFryZmQ== X-Google-Smtp-Source: ABdhPJwU/FF0411SpORuI8rQAjETnXq+LFVWG/DnEHH5trDF7L30y1kMn1g6schCj5R5BHbBqvV1Vg== X-Received: by 2002:a17:902:7081:b029:ec:c083:878a with SMTP id z1-20020a1709027081b02900ecc083878amr4689125plk.76.1619781981314; Fri, 30 Apr 2021 04:26:21 -0700 (PDT) Received: from senozhatsky.flets-east.jp ([2409:10:2e40:5100:2c33:77c9:7bef:267e]) by smtp.gmail.com with ESMTPSA id l10sm1809457pjy.42.2021.04.30.04.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 04:26:20 -0700 (PDT) From: Sergey Senozhatsky To: Laurent Pinchart , Ricardo Ribalda Cc: Tomasz Figa , Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 1/5] media: v4l UAPI: add ROI selection targets Date: Fri, 30 Apr 2021 20:26:07 +0900 Message-Id: <20210430112611.475039-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.31.1.527.g47e6f16901-goog In-Reply-To: <20210430112611.475039-1-senozhatsky@chromium.org> References: <20210430112611.475039-1-senozhatsky@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org UVC 1.5 requires Region Of Interest control to implement GET_CUR, GET_DEF, GET_MIN and GET_MAX requests. This patch adds new V4L2 selection API targets that will implement those ROI requests. Signed-off-by: Sergey Senozhatsky --- include/uapi/linux/v4l2-common.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/uapi/linux/v4l2-common.h b/include/uapi/linux/v4l2-common.h index 7d21c1634b4d..3651ebb8cb23 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 0x0200 +/* Default Region of Interest area */ +#define V4L2_SEL_TGT_ROI_DEFAULT 0x0201 +/* Region of Interest minimum values */ +#define V4L2_SEL_TGT_ROI_BOUNDS_MIN 0x0202 +/* Region of Interest maximum values */ +#define V4L2_SEL_TGT_ROI_BOUNDS_MAX 0x0203 /* Selection flags */ #define V4L2_SEL_FLAG_GE (1 << 0) From patchwork Fri Apr 30 11:26:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12233073 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=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 68032C433B4 for ; Fri, 30 Apr 2021 11:26:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 482CD61462 for ; Fri, 30 Apr 2021 11:26:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231828AbhD3L1N (ORCPT ); Fri, 30 Apr 2021 07:27:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231768AbhD3L1M (ORCPT ); Fri, 30 Apr 2021 07:27:12 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08AB1C06138B for ; Fri, 30 Apr 2021 04:26:25 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id y2so2168249plr.5 for ; Fri, 30 Apr 2021 04:26:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oQxgXbJ1dnrWy/sF8jzljIADGkpBbS6PQOX1pY2bYYo=; b=iYTw7vYNZNTWKG7DfbdMobkzjPLLA9GAeYv7zVKA8puTwjtcaviVdyAoicLJ/gIGgn bxxtmNMNeglWc33KXJmuYTZv1jcFejl4mZ0eY9bQRsy2iILzLT8bjfuLRLsqrzG5ae7H 0kSMi5+WJoAfbneFpflZRfGaWg7qwhKPxNC2k= 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=oQxgXbJ1dnrWy/sF8jzljIADGkpBbS6PQOX1pY2bYYo=; b=uaJPUjqNR98c7/u6gf8AD7bnQz1uFI+LNTys/RzVlWYqhoC/zjIlFVu7GbjIMkE+Oi Pw4+qZaYoK2008cFRVCT68TVNbfwbKImvN5MPZox49L8r5h1Hv2KIfs2SlQdWTlyY2Un Vm0Gm5HI5QDWjQ7rpeawI493CE7govKEqjiLClWj3j6FjhN5HoC7wmLx1AUWXWlOwE+n VF2c9hrpoHGKvJ+e0DfEM9Pzhjgul3uNCBk+LpXMiBLdTu434niISh+XiIIp96F/uYnP cLv5aLN1aXzoT5WMwgtbYKKNsF8SJjKI/r1wwVNzU5hFB7h+pU0sLcau9dlSAztD1m1s azhA== X-Gm-Message-State: AOAM531jEkQMxlPzVczB5+f8crIkvUuqfv7vzHlqgYkrbRZ2tDy+gaLk Ifc12yKSFmh6niQev4cbT1SZ0MKyZ1oyhA== X-Google-Smtp-Source: ABdhPJwwKQho18uUhAw5OZLqgHJd7mzc60EGSP+sSw3HjJg7ERV7iGeMDPM9Fi/5vRDMtKMoC9pkag== X-Received: by 2002:a17:90a:af91:: with SMTP id w17mr14763407pjq.205.1619781984614; Fri, 30 Apr 2021 04:26:24 -0700 (PDT) Received: from senozhatsky.flets-east.jp ([2409:10:2e40:5100:2c33:77c9:7bef:267e]) by smtp.gmail.com with ESMTPSA id l10sm1809457pjy.42.2021.04.30.04.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 04:26:24 -0700 (PDT) From: Sergey Senozhatsky To: Laurent Pinchart , Ricardo Ribalda Cc: Tomasz Figa , Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 2/5] media: v4l UAPI: document ROI selection targets Date: Fri, 30 Apr 2021 20:26:08 +0900 Message-Id: <20210430112611.475039-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.31.1.527.g47e6f16901-goog In-Reply-To: <20210430112611.475039-1-senozhatsky@chromium.org> References: <20210430112611.475039-1-senozhatsky@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Document V4L2 selection targets that will be used to ROI implementation. Signed-off-by: Sergey Senozhatsky --- .../media/v4l/selection-api-configuration.rst | 22 +++++++++++++++ .../media/v4l/selection-api-examples.rst | 27 +++++++++++++++++++ .../media/v4l/v4l2-selection-targets.rst | 24 +++++++++++++++++ 3 files changed, 73 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..b5fdd765e2db 100644 --- a/Documentation/userspace-api/media/v4l/selection-api-configuration.rst +++ b/Documentation/userspace-api/media/v4l/selection-api-configuration.rst @@ -135,3 +135,25 @@ 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 auto-controls values and 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_MIN`` and ``V4L2_SEL_TGT_ROI_BOUNDS_MAX`` +targets. It is recommended for the driver developers to put the top/left +corner at position ``(0,0)``. + +The top left corner, width and height of the Region of Interest area +and auto-controls currently being employed by the device are given by +the ``V4L2_SEL_TGT_ROI`` target. It uses the same coordinate system +as ``V4L2_SEL_TGT_ROI_BOUNDS_MIN`` and ``V4L2_SEL_TGT_ROI_BOUNDS_MAX``. + +In order to change active ROI top left, width and height coordinates +and ROI auto-controls use ``V4L2_SEL_TGT_ROI`` target. + +Each capture device has a default ROI rectangle and auto-controls +value 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/selection-api-examples.rst b/Documentation/userspace-api/media/v4l/selection-api-examples.rst index 5f8e8a1f59d7..39aba98d55f1 100644 --- a/Documentation/userspace-api/media/v4l/selection-api-examples.rst +++ b/Documentation/userspace-api/media/v4l/selection-api-examples.rst @@ -82,3 +82,30 @@ Example: Querying for scaling factors /* computing scaling factors */ hscale = (double)compose.r.width / crop.r.width; vscale = (double)compose.r.height / crop.r.height; + +Setting Region Of Interest area to half of the default value + +Example: Simple ROI +=========================== + +.. code-block:: c + + struct v4l2_selection roi = { + .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, + .target = V4L2_SEL_TGT_ROI_DEFAULT, + }; + struct v4l2_rect r; + + ret = ioctl(fd, VIDIOC_G_SELECTION, &roi); + if (ret) + exit(-1); + /* setting smaller ROI rectangle */ + r.width = roi.r.width / 2; + r.height = roi.r.height / 2; + r.left = roi.r.width / 4; + r.top = roi.r.height / 4; + roi.r = r; + roi.target = V4L2_SEL_TGT_ROI; + ret = ioctl(fd, VIDIOC_S_SELECTION, &roi); + if (ret) + exit(-1); diff --git a/Documentation/userspace-api/media/v4l/v4l2-selection-targets.rst b/Documentation/userspace-api/media/v4l/v4l2-selection-targets.rst index b46bae984f35..d1dc9c50eb05 100644 --- a/Documentation/userspace-api/media/v4l/v4l2-selection-targets.rst +++ b/Documentation/userspace-api/media/v4l/v4l2-selection-targets.rst @@ -75,6 +75,30 @@ of the two interfaces they are used. modified by hardware. - Yes - No + * - ``V4L2_SEL_TGT_ROI`` + - 0x0200 + - Current Region of Interest rectangle and auto-controls value. + - Yes + - No + * - ``V4L2_SEL_TGT_ROI_DEFAULT`` + - 0x0201 + - Suggested Region of Interest rectangle and auto-controls value. + - Yes + - No + * - ``V4L2_SEL_TGT_ROI_BOUNDS_MIN`` + - 0x0202 + - Minimum bounds of the Region of Interest rectangle and minimum + auto-controls value. All valid ROI rectangles and auto-controls + should be within minimum-maximum range. + - Yes + - No + * - ``V4L2_SEL_TGT_ROI_BOUNDS_MAX`` + - 0x0203 + - Maximum bounds of the Region of Interest rectangle and maximum + auto-controls value. All valid ROI rectangles and auto-controls + should be within minimum-maximum range. + - Yes + - No .. raw:: latex From patchwork Fri Apr 30 11:26:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12233075 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=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 ECE8CC433ED for ; Fri, 30 Apr 2021 11:26:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BAB6B6105A for ; Fri, 30 Apr 2021 11:26:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231904AbhD3L1U (ORCPT ); Fri, 30 Apr 2021 07:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231847AbhD3L1Q (ORCPT ); Fri, 30 Apr 2021 07:27:16 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A23AFC06138B for ; Fri, 30 Apr 2021 04:26:28 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id y1so20774133plg.11 for ; Fri, 30 Apr 2021 04:26:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zIeGfPeG7mxLyeWqTVf7wfaZkEDi44BCzuBGF1X/M+U=; b=BFhXsWdbAorG6W7X28knlmwSQAvDMHREHZpapfF789zkPTpt6YHSKtcq+a57hzTDAH rHN57as60d478lbaWrzks+TyxoDSOjHM631QWi/qornlL6nga34sm2tlVqA+Wb5tNS3D iRtKFH2yEnSEVHZwQI+ZLNyN7+3ju/rEMbdd0= 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=zIeGfPeG7mxLyeWqTVf7wfaZkEDi44BCzuBGF1X/M+U=; b=mFYHxPwujnP4BV4D3w08wHwLL9Y7hOQxb1J6cGwQm+gBdgGCzxcd8BiTINmb+LB4Qt ub0vYanJfBI82M2FRM09GdVIVcwXcSDsVfI5s7gqUkczucpUKCAZpzj07OTkrZ3tG43k v806l2UqXKqAiIxHNmcd3x8xUsZLg9nQ289h6osllrwxq893q5SQJDjeD5A4R9oGEVXf 1slV4mN7q/xtb71xrSDxHEkzdbia18frQMCj/ZhPG1hik3TyDDLp1Ev503qfEC3ej62Y NlF6Wx4p2uSkwhCArucITGINY/cErr78068TmY/3zrCI6SwMdneoKnIxCJK3+eWzcCur Vo0w== X-Gm-Message-State: AOAM530iT73tnOt6f9WvHS55XHJZ4BK39EOBFgCD6dg3yTWvhjm6QWjF BAl7BGancD3i61ASU8ARo2qUIA== X-Google-Smtp-Source: ABdhPJx0JvQpszhYbbOBoZIy/feVD/3KCckrdiUITnwS+Elady3xpX1f8F7JsXN7SWe3R261c3NtCA== X-Received: by 2002:a17:90a:3e44:: with SMTP id t4mr4902617pjm.201.1619781988226; Fri, 30 Apr 2021 04:26:28 -0700 (PDT) Received: from senozhatsky.flets-east.jp ([2409:10:2e40:5100:2c33:77c9:7bef:267e]) by smtp.gmail.com with ESMTPSA id l10sm1809457pjy.42.2021.04.30.04.26.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 04:26:27 -0700 (PDT) From: Sergey Senozhatsky To: Laurent Pinchart , Ricardo Ribalda Cc: Tomasz Figa , Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 3/5] media: uvcvideo: add ROI auto controls Date: Fri, 30 Apr 2021 20:26:09 +0900 Message-Id: <20210430112611.475039-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.31.1.527.g47e6f16901-goog In-Reply-To: <20210430112611.475039-1-senozhatsky@chromium.org> References: <20210430112611.475039-1-senozhatsky@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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_BITMASK b) ROI rectangle (SET_CUR, GET_CUR, GET_DEF, etc.) handling is implemented separately, by the means of selection API. Signed-off-by: Sergey Senozhatsky --- drivers/media/usb/uvc/uvc_ctrl.c | 19 +++++++++++++++++++ include/uapi/linux/usb/video.h | 1 + include/uapi/linux/v4l2-controls.h | 9 +++++++++ 3 files changed, 29 insertions(+) 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 bfdae12cdacf..9076a444758a 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 d43bec5f1afd..34bdaf484a8b 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -985,6 +985,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 Fri Apr 30 11:26:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12233077 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=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 99468C43460 for ; Fri, 30 Apr 2021 11:26:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6523D6143B for ; Fri, 30 Apr 2021 11:26:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231847AbhD3L1W (ORCPT ); Fri, 30 Apr 2021 07:27:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231909AbhD3L1U (ORCPT ); Fri, 30 Apr 2021 07:27:20 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10C45C06138F for ; Fri, 30 Apr 2021 04:26:32 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id k3-20020a17090ad083b0290155b934a295so1564273pju.2 for ; Fri, 30 Apr 2021 04:26:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8PgAXsMUjjBGPRGp9xcOay+JzomkodD/BbZ1Wc3R58Q=; b=Oz5xbfHqolQ4qkzkrw0OZwnPcDpv2J11ep1PWMTH6smS9/7RjPD6HiO25i03bMDv3f pjIB/AjNQINf0U92m1pozzfj1lsg18QwC1NztJ68FLWrdtVeUNsnfCU0V0IIWHe1lXIZ +1l4aZ0FOZACFaoXzSqdCHmolD1S4wTjRsO48= 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=8PgAXsMUjjBGPRGp9xcOay+JzomkodD/BbZ1Wc3R58Q=; b=apYSC4zlI+MEfFJmk4X6GY3fG1+Z9ZMSeeJRpMjK50dasR7yi+Y8HENSeJAevFxeIm rKfui9EKxs5auhztJZa34wQajuEuv6cefAdUdDkdNdqs40t0M++aZnWSshml+a4V3elS cHiPkEDBQ4vjWdjPyZDBZhJJYVwLkZjWRieNuIMjMf8cis38RPJi1spIiN74/gkjgeUB 2APp+ffNVegQwM57a4Q/vCDTTQIU9KF2W45OK0rpdHii45ujMxw3TVGqc30e1F4Fwi70 Mko4wUhepS3QNvqcXvVmeQ0n2f7098qiCpFwI50BIOwCijB1kEdQ/1ajhwHpbd5NesOP v7og== X-Gm-Message-State: AOAM533+sG4fNzU9TSdgmlW2gF5L0A6vOLoKxWk0wID8Yp5OAgCNBCOV EUE34KnV02lJGpgGAY8mB3nSdddoGfp7yg== X-Google-Smtp-Source: ABdhPJxi+PS12sWqFpA9ygfTTwgTQO966ZUsdgGOH8dQByLrvZxvrqvr1CIyZVamW25GKBaB/tuonA== X-Received: by 2002:a17:902:aa04:b029:ec:f779:3a2b with SMTP id be4-20020a170902aa04b02900ecf7793a2bmr4718095plb.44.1619781991688; Fri, 30 Apr 2021 04:26:31 -0700 (PDT) Received: from senozhatsky.flets-east.jp ([2409:10:2e40:5100:2c33:77c9:7bef:267e]) by smtp.gmail.com with ESMTPSA id l10sm1809457pjy.42.2021.04.30.04.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 04:26:31 -0700 (PDT) From: Sergey Senozhatsky To: Laurent Pinchart , Ricardo Ribalda Cc: Tomasz Figa , Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 4/5] media: v4l UAPI: document ROI auto_controls Date: Fri, 30 Apr 2021 20:26:10 +0900 Message-Id: <20210430112611.475039-5-senozhatsky@chromium.org> X-Mailer: git-send-email 2.31.1.527.g47e6f16901-goog In-Reply-To: <20210430112611.475039-1-senozhatsky@chromium.org> References: <20210430112611.475039-1-senozhatsky@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org UVC 1.5 defines the following Region of Interest auto_controls |D0: Auto Exposure |D1: Auto Iris |D2: Auto White Balance |D3: Auto Focus |D4: Auto Face Detect |D5: Auto Detect and Track |D6: Image Stabilization |D7: Higher Quality |D8 – D15: Reserved, set to zero Signed-off-by: Sergey Senozhatsky --- .../media/v4l/ext-ctrls-camera.rst | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst b/Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst index 4c5061aa9cd4..ab24930848b6 100644 --- a/Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst +++ b/Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst @@ -217,7 +217,30 @@ enum v4l2_auto_focus_range - * - ``V4L2_AUTO_FOCUS_RANGE_INFINITY`` - The lens is set to focus on an object at infinite distance. +``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. ``V4L2_CID_ZOOM_ABSOLUTE (integer)`` Specify the objective lens focal length as an absolute value. The From patchwork Fri Apr 30 11:26:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12233079 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=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 46D48C433B4 for ; Fri, 30 Apr 2021 11:26:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1446C6105A for ; Fri, 30 Apr 2021 11:26:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231935AbhD3L1Z (ORCPT ); Fri, 30 Apr 2021 07:27:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231877AbhD3L1X (ORCPT ); Fri, 30 Apr 2021 07:27:23 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FA98C06138B for ; Fri, 30 Apr 2021 04:26:35 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id p4so758071pfo.3 for ; Fri, 30 Apr 2021 04:26:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tWbnebzY/SCalv5CLDUzsq2VSK849EXYk/c3zQI/mpY=; b=SUkqYNMflQ276DJ4ik+rnlG2BUrmkiNNxiv3+bdrpXQLiHhAHDrCIAb/guz6qe+m1h KLDt3E9xFYG1FGlOIW7hmuIk69/X+pv3FZh2gdPsCjZsTFhsRsWQnCpBiMIXb5zV2gz7 pwpM671vRQ4OrZHM901/l+lKVm/4ziPjnnpak= 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=tWbnebzY/SCalv5CLDUzsq2VSK849EXYk/c3zQI/mpY=; b=XtkFrSPv1uLlnU8r2WRUY1m6KXY6oro1RV+woLfRur88iRfo5uhnbxJUMgy0WiDKQ4 BX3ap85bAnItMyjHIQhrFAiQ0O/JY/3qark9BnFs3AOPaHKYn9eFfQa5zSW44sz9X74e rzpifvfKKHcTNBt/bZOPgQnuqZztJMPpmvEuDExu3LP9niE26eWcl+xd+DeXO1HOovfG bgoM57TQ99aZKwnmIPTlQxhAGJ9ELvLa+h3Cod6XTnMntVQkoDfkcpaVWiPr9bP7YkUq 5L7CSsNcs2Kjkh+HbeExBwzbJVCpqwjiD5z7Rzr/Biuih1ZZvXfbVe/IW8ZpNqBcIwjl 54dQ== X-Gm-Message-State: AOAM5320KhJqQFX59+vebq6c0k2vJk2cvyR2/WuSZSHMcp8wgIarwsL9 rrUJK2ieuHQdnRLU6XJ3z90UAQ== X-Google-Smtp-Source: ABdhPJwiW+KMFAzt34715myGZwmix+KKr58KHtttwGkYaM7iqy4nz6R6dJaSGzOx7Riwt7eoFSHOpA== X-Received: by 2002:a05:6a00:16c5:b029:280:4678:5c94 with SMTP id l5-20020a056a0016c5b029028046785c94mr4509105pfc.18.1619781994916; Fri, 30 Apr 2021 04:26:34 -0700 (PDT) Received: from senozhatsky.flets-east.jp ([2409:10:2e40:5100:2c33:77c9:7bef:267e]) by smtp.gmail.com with ESMTPSA id l10sm1809457pjy.42.2021.04.30.04.26.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 04:26:34 -0700 (PDT) From: Sergey Senozhatsky To: Laurent Pinchart , Ricardo Ribalda Cc: Tomasz Figa , Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 5/5] media: uvcvideo: add UVC 1.5 ROI control Date: Fri, 30 Apr 2021 20:26:11 +0900 Message-Id: <20210430112611.475039-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.31.1.527.g47e6f16901-goog In-Reply-To: <20210430112611.475039-1-senozhatsky@chromium.org> References: <20210430112611.475039-1-senozhatsky@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This patch implements UVC 1.5 Region of Interest (ROI) control. Note that, UVC 1.5 defines CT_DIGITAL_WINDOW_CONTROL controls and mentions that 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). It's is not entirely clear if we need to implement WINDOW_CONTROL. ROI is naturally limited by GET_MIN and GET_MAX rectangles. Another thing to note is that ROI support is implemented as V4L2 selection target: selection rectangle represents ROI rectangle. Signed-off-by: Sergey Senozhatsky --- drivers/media/usb/uvc/uvc_v4l2.c | 185 ++++++++++++++++++++++++++++++- 1 file changed, 182 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 252136cc885c..eb4e306d7a38 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1139,14 +1139,73 @@ 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; + __u16 auto_controls; +} __packed; + +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_video_chain *chain = handle->chain; + struct uvc_roi_rect *roi; + u8 query; + int ret; - if (sel->type != stream->type) + switch (sel->target) { + case V4L2_SEL_TGT_ROI: + query = UVC_GET_CUR; + break; + case V4L2_SEL_TGT_ROI_DEFAULT: + query = UVC_GET_DEF; + break; + case V4L2_SEL_TGT_ROI_BOUNDS_MIN: + query = UVC_GET_MAX; + break; + case V4L2_SEL_TGT_ROI_BOUNDS_MAX: + query = UVC_GET_MAX; + break; + default: return -EINVAL; + } + + roi = kzalloc(sizeof(struct uvc_roi_rect), GFP_KERNEL); + if (!roi) + return -ENOMEM; + + /* + * Synchronize with uvc_ioctl_query_ext_ctrl() that can set + * ROI auto_controls concurrently. + */ + mutex_lock(&chain->ctrl_mutex); + + 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) { + /* ROI left, top, right, bottom are global coordinates. */ + sel->r.left = roi->left; + sel->r.top = roi->top; + sel->r.width = roi->right - roi->left + 1; + sel->r.height = roi->bottom - roi->top + 1; + } + + mutex_unlock(&chain->ctrl_mutex); + 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 +1232,125 @@ 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: + case V4L2_SEL_TGT_ROI_DEFAULT: + case V4L2_SEL_TGT_ROI_BOUNDS_MIN: + case V4L2_SEL_TGT_ROI_BOUNDS_MAX: + return uvc_ioctl_g_roi_target(file, fh, sel); + } + + return -EINVAL; +} + +static void validate_roi_bounds(struct uvc_streaming *stream, + struct v4l2_selection *sel) +{ + if (sel->r.left > USHRT_MAX) + sel->r.left = 0; + + if (sel->r.top > USHRT_MAX) + sel->r.top = 0; + + if (sel->r.width + sel->r.left > USHRT_MAX || !sel->r.width) { + sel->r.left = 0; + sel->r.width = stream->cur_frame->wWidth; + } + + if (sel->r.height + sel->r.top > USHRT_MAX || !sel->r.height) { + sel->r.top = 0; + sel->r.height = stream->cur_frame->wHeight; + } +} + +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_video_chain *chain = handle->chain; + struct uvc_roi_rect *roi; + int ret; + + roi = kzalloc(sizeof(struct uvc_roi_rect), GFP_KERNEL); + if (!roi) + return -ENOMEM; + + /* + * Synchronize with uvc_ioctl_query_ext_ctrl() that can set + * ROI auto_controls concurrently. + */ + mutex_lock(&chain->ctrl_mutex); + + /* + * Get current ROI configuration. We are especially interested in + * ->auto_controls, because we will use GET_CUR ->auto_controls + * value for SET_CUR. Some firmwares require sizeof(uvc_roi_rect) + * to be 5 * sizeof(__u16) so we need to set correct rectangle + * dimensions and correct auto_controls value. + */ + ret = uvc_query_ctrl(stream->dev, UVC_GET_CUR, 1, stream->dev->intfnum, + UVC_CT_REGION_OF_INTEREST_CONTROL, roi, + sizeof(struct uvc_roi_rect)); + if (ret) + goto out; + + mutex_lock(&stream->mutex); + + validate_roi_bounds(stream, sel); + + /* + * ROI left, top, right, bottom are global coordinates. + * Note that we use ->auto_controls value which we read earlier. + */ + roi->left = sel->r.left; + roi->top = sel->r.top; + roi->right = sel->r.width + sel->r.left - 1; + roi->bottom = sel->r.height + sel->r.top - 1; + + 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)); + + mutex_unlock(&stream->mutex); + +out: + mutex_unlock(&chain->ctrl_mutex); + 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 +1711,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,