From patchwork Tue Oct 22 08:40:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 13845320 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011016.outbound.protection.outlook.com [52.101.70.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD98818859B; Tue, 22 Oct 2024 08:41:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.70.16 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729586477; cv=fail; b=W3VWwRNNCn9QJAZxT0RL0uxWMlvoPATkvjOWm0EsM77IlLPRLctx/8/2qrX04iCHH6AFFlnNmhFAlskFhCXr8xx/EMa5G5Q8lYMRuxPKjaEv5qri0Dd6fbFTE6rXok9p6zTzkcxY8REAjzw9LgXt39RQ7xCpoQhFASKFxTkoexE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729586477; c=relaxed/simple; bh=3J7HQukrMTz6WCskrPZNpBJysph2+T+IN+yd5cJXGsc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=VhOEuNADMxlqDCvWYW3Ohlcpn+ui+Vogk1OZf5ZXJWDBVFa9QQQShv7NJ5ZhGsima4isAyMafo1S2XntIhpByA7WmOYyIS9jVMmQewWPBOmQ8Kh4SA9dAntAT/LmSbvxtjE9BRNbIjuf/Kq+nXXowgBS3gmZxOXrpJ++Ac93O1k= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=j5Ds5R1U; arc=fail smtp.client-ip=52.101.70.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="j5Ds5R1U" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qvJpaYYNR+qPf7FMqEnRUq9xuWxLNwUBMhx7qFwBHF3wS/LQzjR8mXp09sPndWH4tq18oRNCKTw47dg/jFtL18U/ie6eZiJIpffWawKOzz47K6TJeS4msLg0PApNk6fB+sQHIEnj73/NwgEk6OFDI4/kk6qPL9A7S/+TdhD0vHknNGV4GKMqqK1omI9tpEV+DzmzxWolkyFgW1HkMryDjrCp38pI+Gs+gCexav+QnaNbxOWD7iAoanhjgnAmcpk8zJ1Zg5S4ivZuf3bcBcsgsy/0ZTYx6ZxtuQq4GP2gECw+sS0ls1i4djsErpnObq+i88bSlesLblJmEelVbK0PxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3co966d8lg7YhJGpW2PyDhINGAAkGT+8kwYcfIKNyhI=; b=JnvgCedhLOgs4DxtklTrS603Dh/XoIPe5yyE70Oxe36hx6Eyf3vTvIpLsdH7/2aLQUAk/OnGSS2MRNTRmB2S+SfMsnJgNuFL4117NReouhRl6oVGdtq19lPy8ZtCsbL3N+dipz3swHFAgzJilDL/0riVRX/xSAEWYwIHxvGuS22d4mL4pGAm8ugEBpse1/zO+PITIJ1UBqXa+RzlOFUesVeqm4PMNaIUgjedemMGFJHSF1pOFBSZZivVNdAJMztgeq2tmEQ1P3n/WHgB+rl7WmJ5/hRvNY5oJt6dUVNWWzDZTDUX6W4MNANOMhzPIjgA8JdJA9nqAX/XLjjHZPB3tg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3co966d8lg7YhJGpW2PyDhINGAAkGT+8kwYcfIKNyhI=; b=j5Ds5R1UpauzqyeRd9YcB3phbW9uers8ObQsJBHfQ+7LCwKQ6VMg6LwP4NqLb5Hp8hJ4T1LsPZB6Thb0/04/kJI07dhX54C0bLYfcdNxlo8ihp+G6Fv2z8wax8iVBU7w8Coii8rDYWnogIqKMGhTu/aobFl2Hohbhv+N7IKr8JhZxRh5bYQl45t1x4Mr8m0aHCOUw9Wv1zPyF9Y9deq7t41eIhGwZ5RD9cyfWe5eiaWZGor0L+evdAMApPbVRzUENVZVZ7uA/za/m9kJ85LLSeqFB3+hXZlPPrlG/g/21wQLSEjfsx4w3gAbh17cDyuBd2yV2iPqPmMgUnr4P8Ou4Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB8254.eurprd04.prod.outlook.com (2603:10a6:102:1cd::24) by AS8PR04MB7831.eurprd04.prod.outlook.com (2603:10a6:20b:2a8::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Tue, 22 Oct 2024 08:41:10 +0000 Received: from PAXPR04MB8254.eurprd04.prod.outlook.com ([fe80::2755:55ac:5d6f:4f87]) by PAXPR04MB8254.eurprd04.prod.outlook.com ([fe80::2755:55ac:5d6f:4f87%3]) with mapi id 15.20.8069.027; Tue, 22 Oct 2024 08:41:10 +0000 From: Ming Qian To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl Cc: yunkec@google.com, nicolas@ndufresne.ca, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, xiahong.bao@nxp.com, ming.zhou@nxp.com, eagle.zhou@nxp.com, tao.jiang_2@nxp.com, ming.qian@oss.nxp.com, imx@lists.linux.dev, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RFC v3 1/4] media: v4l2_ctrl: Add V4L2_CTRL_TYPE_RECT Date: Tue, 22 Oct 2024 17:40:37 +0900 Message-ID: <20241022084040.3390878-2-ming.qian@nxp.com> X-Mailer: git-send-email 2.43.0-rc1 In-Reply-To: <20241022084040.3390878-1-ming.qian@nxp.com> References: <20241022084040.3390878-1-ming.qian@nxp.com> X-ClientProxiedBy: SG2P153CA0007.APCP153.PROD.OUTLOOK.COM (2603:1096::17) To PAXPR04MB8254.eurprd04.prod.outlook.com (2603:10a6:102:1cd::24) Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8254:EE_|AS8PR04MB7831:EE_ X-MS-Office365-Filtering-Correlation-Id: 87d2e0a4-fe54-4d2e-f470-08dcf2754755 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|376014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: UYE8KXw2aw2fZW8M8wQ6FRtyh+cHFHZAVbD2aXiWp+WJZZ7y7wxwk5nlKVi4YbqBIFjZPhtlzm79byyxrmQm6YpyzwYZ8DtK0KnMAc6SOQ8/xNd72UEyP2+xPEurR+hC8e5EkudseSWw1wx2YBTwuUfvtE1rLjqD1A1Zih/zOVjjcwsq0TVjhheVSnSwPe3nWPTimou8C27nBG9fCMEIyhvhoiwUqY6V+3UT6nmljb+Zu6FvtfFDjEcT8Acp8Mz0RBA1WX0yqiq8Q81qHi1ZPfvAHBswmCCuBmK2NfbzBAIvnvqEr4dX7or2lFZZ2GugOs8OnDLmgP5NR61agOyvJUDhIQ3yrm6zo5Vj/sLlCQJNbtWXRr3YkjbmepeLhnT7wAcSbbbrJl9KLcZgd3kuTkKZaDKjdr2l3vrHlS7+xBqP8Nr7//dBc5QlgB7oXcuopuE8cMQNA44Iyk7dNsXiw9UQhnjcyYpzW1qRtQDABmdXZa2IMbBm4HHNrWfMdn5tUvHnfrvm517jXto21+XsPHPgKE3cvHm5yxTnEHOL/lBa3brVaWY64DmS7J8Az600wPMgMDQW9w7OPqDTH3qumkogv+8tuG/C1YVdLdAkwOmDLiC9vQeI+zwPBhmmpcVxUlclcZft8AKg/By0eOrVXCniz1D1yIqsX4DuBa0Nc6m883X64xQ6StL+qEEr5xa0q/ouCZyC1tLDi+/J0aaUwexKCBSWszfF9cc40FvqDN+3anEXIjd4FzNTObdt1ZqavkymCMLKuOBTOPXKystDTOKBJ0ts+CyGnb4yDVH09bJqB9wInZv2X5DRJRjPUCwG9dGvpsFHNGhCegHkteCxB7gKW3ixwjbuBAj7NGZoVYyGKpD/LddRhtb8CKxKwR4/vK/7sDmSG+eoiFAVS7unTxtFr0qMDxx8P6tBh0SsggkpPJV1H2tnLtTjUWUamsUtQykTadjv4nu0A7/k7mkg6YP/gv9hDyOtJDxykSfP9HrLvTvCXJ45U6jlAZKlkhml1rjL1mgr2b454QB5P+d8GYsuEDub36PXBgFEspP9e4QZiOoRDpsIy37WOSW1eArhNOpdQ14bTRjwuZ8QIcxQwLv8rRZg/qANXsGm4rGxauEDgRd0TQ1N17qvr0Lj6P2s1T1xkhPjxzfxSecG3hRcMlKlEiHvsFHGQ06nqwO6tymtoWf7lgHcvmqSr9LdumFcsJc+T6YESZiJ0MwkDyHBtPnVFXN+9Osz7vMgQjQKqvvYe+mWmO/Gvb5c+OGhrhlyv1uE5lMlUbG5TjyvJqri3tiRk2PUK0u+ngRZ/z7V3XBktNMeGBXFV0xhLWX7y5jOMre7V/0Hml6eBWxQ7tknBSFMPMiP/iaXiWfEvfXC+5w= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8254.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(7416014)(376014)(52116014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dD0DL/l9IteabI8952yCnh+CoS1r1L0+bm6TmkzzKIlErabI4x+UoY0myRb2ESXoheIT6sZehA9CWNfu0rs+hSf5odrRx9ovOk8AEKStD04TEhdmGjFJUmgqD7P+UlTDFjMmhTHg3n/OKQHMKDvUQwMNdWd3yla+c9mxIOFICVdjL7YlxaLitDIFeUanqjlu1MhOUSdcyBP132qGo3fr0athILRnkeReF6NCGhn7kD3wixrdXj4KlRs8Ao9e9/74NqNwyoIbfhI3ouH/VWL/oWZiu0BqrPhswHH11Yj8XamcDvs9xzc7gHJ77c7xFR8+AJfNjoh2idMJ5EzFbSqsANXjsoHuF+er7z1V/iA0nbadXdLHa+dNZI8s2kQUmstdc7LjHkkOaIBP/msX7ECUhaCS5q8G2aboQy4Uf/0uznZIXbd6T8ie1LNoJ0BshSocbcaNu7I3eO5IEcoh8/+RStqh8yBVwa4nLIaX7fNiBZj3x7+RfPsI2fc3FtvN3JKozvvPElP4x9bs2Kr3JdKskADscN9oOqErQ4rEkBxFIpYjwHLk26Vzfbtw71lkXEqdhhCJ0TWdF2uNjqpjGo4gxZhXQaoWaYQlUutW8obIy7cCBefqqe8fZDxgmlFilg68HpteegQbdrH0XQ85l/Uc5pVooDeRK17o2ob9t7LUoNGNGAg5yagOIpjf4OU0B7jIm/V8kLB+3orysy0D3wsEu5Q92x1SZ9ZW224mx3wY2GnAKZtVuaFKxwcCbUiZm+1MCrDz4fnd+7LhouX+WZ+d9EzqASGQ0BUWxbfYKKiqcWXxMze18nAKfNVfrJH2wmayok2HlAQUaAxcux+Ira9UazkfM9FkcxO17Q33Qv1TYUqTkg10BARi45fmp5dphr1QTLZiQsGMsaowcOpegZazq+QG7Jm8TujvI71H5mcjR220ZRtGG0lbbX2e+SEWoVmnZ2+QYekNGXzPRLqpViVNVtcYG4s3/AIyqJhG6sGuMZd2zd6Qz+t6NBmNwRY7Dcmv8yfJEBRqeIye+8Yt6xS2ts2y79mjyfZLcNW/1FBdrCjshizHk0XdutkX9lxPeUVbq7ohT1EBVGRoNzUBkkDVUQLkWWo5Hn67RpuXalgZIywnErk9etciMkdjGW9YPqvwsk08CQ83fXfIPYSNIj0F4v5E+0wi7zlpFdqD9N0cuLGELWjYItErFMT2WAmndFpLp83VFJEr8LydyHWvaPkEOWnBnLeBQGFKoTwhXYX3di+TEDwuLz7VX+q34sZlH05pnBa6qPtDIfjaLwCFrigxha42jrOW9Re0VLQV0zGVOI9RZV6zOeQ1HrNxc+4wcXXXLdPPnRPzJSvqr6ob3IjKyu+fQiz5DjS2z6/0B1X2hcu5z8y+SQ5wFV4GKCVsTBRNqFveFOKW0su2cKVLdJPT+zPaC7RqkN+ArkTc6EgNe8scOugbmen5SowVeiMp088dkeILs1k7DQMhrhYf1/+vVaq2Z3VMBZ4E7D7vYoOGlRaO0NXafjP1fpzqVXzNciDwV0oPQgThJYrr8ajiRYj/0TdmeDCaa8R8+ARkLdx65z7mndWF1/EX6Lqfe+PaduFA X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87d2e0a4-fe54-4d2e-f470-08dcf2754755 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8254.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 08:41:10.3702 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dgbvxXuKe0qi7zTRbpI2MaudruAjbSs0TTTFmwWgX7cj8voV5xXwWo59aHunUKp1aU6MKKy+Gru2PNIgckiHvQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7831 From: Yunke Cao Add p_rect to struct v4l2_ext_control with basic support in v4l2-ctrls. Reviewed-by: Laurent Pinchart Reviewed-by: Ricardo Ribalda Reviewed-by: Sergey Senozhatsky Reviewed-by: Daniel Scally Signed-off-by: Yunke Cao Reviewed-by: Hans Verkuil --- .../media/v4l/vidioc-g-ext-ctrls.rst | 4 ++++ .../userspace-api/media/v4l/vidioc-queryctrl.rst | 7 +++++++ .../media/videodev2.h.rst.exceptions | 1 + drivers/media/v4l2-core/v4l2-ctrls-core.c | 16 +++++++++++++++- include/media/v4l2-ctrls.h | 2 ++ include/uapi/linux/videodev2.h | 2 ++ 6 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst b/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst index 4d56c0528ad7..b74a74ac06fc 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst @@ -199,6 +199,10 @@ still cause this situation. - ``p_area`` - A pointer to a struct :c:type:`v4l2_area`. Valid if this control is of type ``V4L2_CTRL_TYPE_AREA``. + * - struct :c:type:`v4l2_rect` * + - ``p_rect`` + - A pointer to a struct :c:type:`v4l2_rect`. Valid if this control is + of type ``V4L2_CTRL_TYPE_RECT``. * - struct :c:type:`v4l2_ctrl_h264_sps` * - ``p_h264_sps`` - A pointer to a struct :c:type:`v4l2_ctrl_h264_sps`. Valid if this control is diff --git a/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst b/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst index 4d38acafe8e1..56d5c8b0b88b 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst @@ -441,6 +441,13 @@ See also the examples in :ref:`control`. - n/a - A struct :c:type:`v4l2_area`, containing the width and the height of a rectangular area. Units depend on the use case. + * - ``V4L2_CTRL_TYPE_RECT`` + - n/a + - n/a + - n/a + - A struct :c:type:`v4l2_rect`, containing a rectangle described by + the position of its top-left corner, the width and the height. Units + depend on the use case. * - ``V4L2_CTRL_TYPE_H264_SPS`` - n/a - n/a diff --git a/Documentation/userspace-api/media/videodev2.h.rst.exceptions b/Documentation/userspace-api/media/videodev2.h.rst.exceptions index 429b5cdf05c3..3cf1380b52b0 100644 --- a/Documentation/userspace-api/media/videodev2.h.rst.exceptions +++ b/Documentation/userspace-api/media/videodev2.h.rst.exceptions @@ -150,6 +150,7 @@ replace symbol V4L2_CTRL_TYPE_HEVC_SPS :c:type:`v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_HEVC_PPS :c:type:`v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS :c:type:`v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_AREA :c:type:`v4l2_ctrl_type` +replace symbol V4L2_CTRL_TYPE_RECT :c:type:`v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_FWHT_PARAMS :c:type:`v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_VP8_FRAME :c:type:`v4l2_ctrl_type` replace symbol V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR :c:type:`v4l2_ctrl_type` diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c index eeab6a5eb7ba..4c8744c8cd96 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-core.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c @@ -370,7 +370,11 @@ void v4l2_ctrl_type_op_log(const struct v4l2_ctrl *ctrl) case V4L2_CTRL_TYPE_AV1_FILM_GRAIN: pr_cont("AV1_FILM_GRAIN"); break; - + case V4L2_CTRL_TYPE_RECT: + pr_cont("%ux%u@%dx%d", + ptr.p_rect->width, ptr.p_rect->height, + ptr.p_rect->left, ptr.p_rect->top); + break; default: pr_cont("unknown type %d", ctrl->type); break; @@ -815,6 +819,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx, struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering; struct v4l2_ctrl_hevc_decode_params *p_hevc_decode_params; struct v4l2_area *area; + struct v4l2_rect *rect; void *p = ptr.p + idx * ctrl->elem_size; unsigned int i; @@ -1172,6 +1177,12 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx, return -EINVAL; break; + case V4L2_CTRL_TYPE_RECT: + rect = p; + if (!rect->width || !rect->height) + return -EINVAL; + break; + default: return -EINVAL; } @@ -1872,6 +1883,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, case V4L2_CTRL_TYPE_AREA: elem_size = sizeof(struct v4l2_area); break; + case V4L2_CTRL_TYPE_RECT: + elem_size = sizeof(struct v4l2_rect); + break; default: if (type < V4L2_CTRL_COMPOUND_TYPES) elem_size = sizeof(s32); diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index 59679a42b3e7..b0db167a3ac4 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -56,6 +56,7 @@ struct video_device; * @p_av1_tile_group_entry: Pointer to an AV1 tile group entry structure. * @p_av1_frame: Pointer to an AV1 frame structure. * @p_av1_film_grain: Pointer to an AV1 film grain structure. + * @p_rect: Pointer to a rectangle. * @p: Pointer to a compound value. * @p_const: Pointer to a constant compound value. */ @@ -89,6 +90,7 @@ union v4l2_ctrl_ptr { struct v4l2_ctrl_av1_tile_group_entry *p_av1_tile_group_entry; struct v4l2_ctrl_av1_frame *p_av1_frame; struct v4l2_ctrl_av1_film_grain *p_av1_film_grain; + struct v4l2_rect *p_rect; void *p; const void *p_const; }; diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index e7c4dce39007..c1c2ae150d30 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -1859,6 +1859,7 @@ struct v4l2_ext_control { __s32 __user *p_s32; __s64 __user *p_s64; struct v4l2_area __user *p_area; + struct v4l2_rect __user *p_rect; struct v4l2_ctrl_h264_sps __user *p_h264_sps; struct v4l2_ctrl_h264_pps __user *p_h264_pps; struct v4l2_ctrl_h264_scaling_matrix __user *p_h264_scaling_matrix; @@ -1929,6 +1930,7 @@ enum v4l2_ctrl_type { V4L2_CTRL_TYPE_U16 = 0x0101, V4L2_CTRL_TYPE_U32 = 0x0102, V4L2_CTRL_TYPE_AREA = 0x0106, + V4L2_CTRL_TYPE_RECT = 0x0107, V4L2_CTRL_TYPE_HDR10_CLL_INFO = 0x0110, V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY = 0x0111, From patchwork Tue Oct 22 08:40:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 13845321 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011016.outbound.protection.outlook.com [52.101.70.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F7D218BBA9; Tue, 22 Oct 2024 08:41:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.70.16 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729586479; cv=fail; b=BwWk+wKPlA91m5q0yKo1xQtVoJ2jQZd4ndTkU0Sf+GU4A7UR67h1L8zp24ihpdKCRijHvPRNOIKj6PEM+rOxAcHBv9mW2IY8LParCW9nz172GU02uMTGDnnvNCgYWTjIaWDLckn06dq9zy6w00+8EwlKGfoaytP5nXW4WRCq960= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729586479; c=relaxed/simple; bh=V9uQS5qYmiXssOXx3/jo+h9bUk3tmEJA4+u5KYczP+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=E/H46Ul1UrYYtO/ioJg2Ml0s3K6dE/G8ykBY7XDCRREq6pwxX7urp2EecHqhIUAfUevE9Q9kCfDYoa/oyZ+7GKfceCpYxTuk9DhAmgZxy5S1n9j8lXlJZXE7hpouKJlR6UdlpgjNEx9Oy4QUC03qJ56xm7YnyGmymzRCpwlQ1EE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=myPcoAjq; arc=fail smtp.client-ip=52.101.70.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="myPcoAjq" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rFm08aoultYe5Me/7HOCB67lvPUZOnhu6DZCpwL8rwchZ40Lp/fIClHiV7HxmawoazqX/P9BxhotA7IgyjBqa9wRS7WJnh/cZgbuUu+PThciE5J4O8BBP7L4qO1AEB5K0Nnms1+TPM8w121u+fTECO2/mTNaATZFNV8hg0R8t59/S8Sqbd2zDj/Tn0oIy1LM02vyXCbC1vGB+UgiQbXLuQDRjgce410Jca4JkbJJGSqMmzAYGHeOUWUsnVKGrZJxRMTg0PPBTcGCNz9Frn+B9VJslsierbOLCUGDvi8pgUt2GVrn2rntUHEdq+0Ahn7zk4iGu9WZ2hau8lNoWkNm8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=z3oKuxRFkA9yHb1hrfi99zYa7fO58IZs40h8sxAWj0U=; b=gwoS65LnGeCLSl4Ieeb30vsmaieLeNN8NnWsUzYAC3yJX9jz9g8n/nCnPZMafSQg0FIpSN0QLaFrneqO4wZW2uj33YdlrVzmutAFGAqhY3L0oJtr0HDPEXF9E69VS2I3W8CY6Z31cvA/cs0kcv0rSJvLCJy27HoLkg495f0jvK29/WQ1VJTqeROEBUzwqcGD6sJmTLMpS4nPcmJcjjjsXvkMWY6oTBIz4prVgbRY4A5Xiz2bZ4yRnBnlzNpzDlSMT0ULXMWXpbrvskXmYqxJzCjyIli1+4APMeDbsWKqPdyzo3pv7R49RCd62FKgug/0VZsh5YyYNHZeyoE3UWmIPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=z3oKuxRFkA9yHb1hrfi99zYa7fO58IZs40h8sxAWj0U=; b=myPcoAjql+9blBeXgyxhqoWnZR9LFek9o/P1LgUqk1bbG5XJ2fbIB+lR+CNCnnqSZRuk+nfdKRwAM5Qm2/SiZD5IqpEfwfun0KDoTGBm77RC4zhULHlQLdAR0+CHbkRWg+EQsF6mp56IgtFr7bS+BJsVz7pGrGnlKMy+aaOn4dXWM7l9SU8eiCaTd2R3JSk3XfVFApBnPVHlvwb5ADObgjIG13pLi6MrPH/tYGGOcUdjlpkQszNEw90tU52ZKu7+jsUiianjLPiyQJ8YbXBnL9gODUqfwXCKCyQEqHNiNick7ZGf2s4u6XY0p4l6yPUh9HoeFdI6B58sNAJW9UOZGw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB8254.eurprd04.prod.outlook.com (2603:10a6:102:1cd::24) by AS8PR04MB7831.eurprd04.prod.outlook.com (2603:10a6:20b:2a8::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Tue, 22 Oct 2024 08:41:15 +0000 Received: from PAXPR04MB8254.eurprd04.prod.outlook.com ([fe80::2755:55ac:5d6f:4f87]) by PAXPR04MB8254.eurprd04.prod.outlook.com ([fe80::2755:55ac:5d6f:4f87%3]) with mapi id 15.20.8069.027; Tue, 22 Oct 2024 08:41:15 +0000 From: Ming Qian To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl Cc: yunkec@google.com, nicolas@ndufresne.ca, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, xiahong.bao@nxp.com, ming.zhou@nxp.com, eagle.zhou@nxp.com, tao.jiang_2@nxp.com, ming.qian@oss.nxp.com, imx@lists.linux.dev, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RFC v3 2/4] media: vivid: Add an rectangle control Date: Tue, 22 Oct 2024 17:40:38 +0900 Message-ID: <20241022084040.3390878-3-ming.qian@nxp.com> X-Mailer: git-send-email 2.43.0-rc1 In-Reply-To: <20241022084040.3390878-1-ming.qian@nxp.com> References: <20241022084040.3390878-1-ming.qian@nxp.com> X-ClientProxiedBy: SG2P153CA0007.APCP153.PROD.OUTLOOK.COM (2603:1096::17) To PAXPR04MB8254.eurprd04.prod.outlook.com (2603:10a6:102:1cd::24) Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8254:EE_|AS8PR04MB7831:EE_ X-MS-Office365-Filtering-Correlation-Id: 0cefc7c7-1705-45e4-cfc3-08dcf2754a39 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|376014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: f57aSO1p4s8b+UvotILpSqMwQfAkr04tJhbGPEgWt+tw20SO5o8Rw2HPUffCf8IkC9HjswTkbgjLSs55xxvBAByhXZj43Erqzo92ZmNcYyW6kVQJGiIZuwZvIxh0qFaIWgNJzCYndVxtIvE5MyP9TI2uLGVqT6bYFzSmIGtw2GluQJl2vVvES0huqbv46zFJ273MsolfT/d0L4WhVtqfS9rIejVNvzihlHzF1i0iCdc788J3DAmzeu0ooAt5xThkc97ntd87ko01W8oXxBM+wswLg+PzlalmZYWDZVENy5/zbUy9lk998I4PPPznZ4fN6nRVMswhCcGxfebh+ojRlw6dJsgKKInd7fVnYzYhukPHeF+k1BhOtHOpllDN47WIi7/1HB9cHbyM3RoQM6aLowpSf2G/O5xexvC9MwLpJhbUUeUD5r5b/RH/Uch48rzQvXcHz5taDihetcmrPCM0028V5OkbHaPeRDLxbjBtq73OfEFI1MlMY0TeOkAE2+k9zDMqXol14WG5x/tCTJR21Srlk/ZjXQWBau4TjoDIGvZ43RXLqRSSkc7ebRUcK3R1K7ZMUJed+hGGrsrMDzFL5ik4j1yZY31K2tlL8bWEOzpk7Qx2evQABEjux3Vxla+0ptAe8c6u1CMa/ptx00VG/QJuBZaCoAk5y0shZW0ZRxOlVnGPNC8+6CQWon9FalfZOuX3G/7Nm4AneyiaiAie3FqhnTOtr0Bx0wQS1JN64Nh+ubF3/Bi+bQ0eKMUrgY9uwU1p8R0VfJ3nYJoUUyv9ewJXopDQOPL//YiW98nRBUt9Z3YNkkYIBDcguSlESrY0v6iyucg90rY6mH2GchQmpnk6qgBCkCv8765Pd+tYt6tGG7rEaCAmj9K+nbdwdzpQes3KO++9XzUHmt6C9no5AMP/6I02rbCR9myMNeBYHnNPi3BgqWQdXfyXfL4QcUCFWgVlTeKFwcmx4TlCydXFOHFjhcv89exOEOdSpPMHVtRnNWprzq9UJP7X8fzmEQYPSKHbRLLAn0opE+JYKuYUSN2blO+bd7Ig8eoa0y8192eplSJAYS4fK2AviaPtg4TUyxIiUrHkLcAzD2my+beb2T1bo3I05jtrV4mvbbj0V2QEasOJZzpVqbNKdZ+ypUAxtAD1zKqSYQp//Kjcjid66GjWeOQZm9BPW7fn7oC7z/X1gssPBOANvOuFjCEB0I3PK35KIJzTS+mISiNn41HP2Dv6xxW232bjE0qCdo7y2YIcH40tx7hXLPFeuXa8GxQMd106/tbWN+YCWuy4k89FYbUvaY0T4jZnFw3CaMoSk1cb/X0uuSIp38RzP2KzCWJDBWW0MY/fGPWKwQCTqxtBRcQvAFfhBmaVbdQtHVYEnDA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8254.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(7416014)(376014)(52116014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sHOAKYuL3ed3Sg8Q/NMPGCmqo1UuoBqOUWe+uHFXmHI6GsBSWSljjOrRX3TfLZCTXilFoQx/W/6PnInWeN3F5ycgrxIV+O+8fAdo8tsKWZCq8HDVX4xwfCY5vr3FcT6uOWNUfMJuVFN+XBccoHccfgyuSg8L8/Rp6bj8/6QKDE426D5LzSGvtaXiNAYg8VEXGzP14cDsXeDyuuJ7OMFd8YKndejh+y4rCJcQMKeLfe3lIkPTmQ5OndP9w9ZFxo6iD/ElOwnviHgMlVXucjlWFkUYT19Q1rz9BZd+ZzFjlm4QU2GmYm9BirUlMczpYj/cLJjXCouBxepPGdjjaGwBwLZKYv6NSITEWSJIgsqE42qrN1MJdl9NHpNKB5CORgCOphDIb5iLM4flQj5Pwi3IsGLFtmSv+cyPpBU+NrZCJMTNUVaEITV3v16NtZ4zDRFPrjFsiHsR/Bs8xQNEsZ25/1JX5ARqORb09ULiwHVnPO3c40aZt92u665vEXVFi0+uzbVzuWRu0zVoLMUtOQSSVXnp/fCE5JIIu/OQKpuuDNdouCCtpI01aM26IL3Al8i/NAugUAO2jzCHGNNfRDZgEsgRUSf1gxeoW84Ol+6eRXq2L+XcBrwAPjsOqQM5EEqmgy8OTKifVrElTKyDLvsH8mAcGpFPU14m2Tu6keY6K+uMdh6PJbO9JxhwY9cS7Nl7vMGWHfwB1r4d3mFStbH3rVDNOd3almoiUq+hwUHOIGvB9YZaU5peFr1R6tJzxNkziUECOgaALwicefNxZBam2yyNTpY1iz7cYN6FNR99gwtPdp7KSUkD0PatvJzLPGGNROb5o1DSDS9XkzHWfYKzZn71ghAbhWGpn6mcaJIQOxtCyhKx3HJY1VtKQFI5ZZ2QLHLz5skFOBQxyepG4MEOBrF2+5dTvwzx00SMNM1i8oWddQ/TQOht48Yz76vOXAfKDK5zocjpsMul2CDLEXwaLtp0CVI+tfiRnzOMX7to0VWXK48XSauYXWRVELfDVfDLXUC/0zl6FXaLXnEdyLWuWC00DjTIJBY8k8eTvdh+dLpSPr7kMNS2+yd4wAAqRbTPR81anrIWWBZdoAv/sQbSxPZsp4cY0Sh9zrKQLVzkI/0t1kNVubk8pX87VETiCNJyEZgMM7hEFmYObaqI/7UaMlxvYVcgpz7GUUmDjTiO+e/q7OXe55AHUwnNxaWJ0Mqh06DKB5wfDrmHOMJqfmXFG78SKwSS20bsJPT2cd4BhvX5dFM5CmlnFvoac0Wgpqn/C5hNWO11JydkmF6dRk9SH1qF+JhqOO+T+RSWhB/Uu72sZ3VoeuGkcFbW11iHz/fJuD6sBGpOepfunNeZUPSF9EjCZnONSq9sRCj+BF7HRpR4HFBUH+0OhF1nTp8Bqz4+dJjfLGeZo6FcwBDwpyaz+uxobn69XJmfUfCqoMker6426A8F99XMSu1bM3kqRsLD+xX8AHVa1UdhZvqZ+h0Stx0hN0TR7v8U7NiAUc2NCD8V/gT7s5Urc/CJklOd03plRTDkOZSJtfiFj7jCjXbg26vooqgO5fsWfWJ0Pb4Ss2ReseJpu+0jyvFVKfYg2OMs X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0cefc7c7-1705-45e4-cfc3-08dcf2754a39 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8254.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 08:41:15.2540 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lMBk2wwTiOqlAA3HZHUSjicFPVbAjsTke/qUVBUYtPQkzj1IMNkm8t4ckh3/wkRgAd0fg83oUIilhilUXjWJdQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7831 From: Yunke Cao This control represents a generic read/write rectangle. It supports V4L2_CTRL_WHICH_MIN/MAX_VAL. Signed-off-by: Yunke Cao Reviewed-by: Hans Verkuil --- .../media/test-drivers/vivid/vivid-ctrls.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/media/test-drivers/vivid/vivid-ctrls.c b/drivers/media/test-drivers/vivid/vivid-ctrls.c index 8bb38bc7b8cc..bed5f4fb0c69 100644 --- a/drivers/media/test-drivers/vivid/vivid-ctrls.c +++ b/drivers/media/test-drivers/vivid/vivid-ctrls.c @@ -37,6 +37,7 @@ #define VIVID_CID_U8_PIXEL_ARRAY (VIVID_CID_CUSTOM_BASE + 14) #define VIVID_CID_S32_ARRAY (VIVID_CID_CUSTOM_BASE + 15) #define VIVID_CID_S64_ARRAY (VIVID_CID_CUSTOM_BASE + 16) +#define VIVID_CID_RECT (VIVID_CID_CUSTOM_BASE + 17) #define VIVID_CID_VIVID_BASE (0x00f00000 | 0xf000) #define VIVID_CID_VIVID_CLASS (0x00f00000 | 1) @@ -360,6 +361,38 @@ static const struct v4l2_ctrl_config vivid_ctrl_ro_int32 = { .step = 1, }; +static const struct v4l2_rect rect_def = { + .top = 100, + .left = 200, + .width = 300, + .height = 400, +}; + +static const struct v4l2_rect rect_min = { + .top = 0, + .left = 0, + .width = 1, + .height = 1, +}; + +static const struct v4l2_rect rect_max = { + .top = 0, + .left = 0, + .width = 1000, + .height = 2000, +}; + +static const struct v4l2_ctrl_config vivid_ctrl_rect = { + .ops = &vivid_user_gen_ctrl_ops, + .id = VIVID_CID_RECT, + .name = "Rect", + .type = V4L2_CTRL_TYPE_RECT, + .flags = V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX, + .p_def.p_const = &rect_def, + .p_min.p_const = &rect_min, + .p_max.p_const = &rect_max, +}; + /* Framebuffer Controls */ static int vivid_fb_s_ctrl(struct v4l2_ctrl *ctrl) @@ -1685,6 +1718,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap, dev->int_menu = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_int_menu, NULL); dev->ro_int32 = v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_ro_int32, NULL); v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_area, NULL); + v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_rect, NULL); v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u32_array, NULL); v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u32_dyn_array, NULL); v4l2_ctrl_new_custom(hdl_user_gen, &vivid_ctrl_u16_matrix, NULL); From patchwork Tue Oct 22 08:40:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 13845322 Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010037.outbound.protection.outlook.com [52.101.69.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3771C1946A4; Tue, 22 Oct 2024 08:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.69.37 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729586487; cv=fail; b=iVaVJnnV0OLrX9fiWm3904GR8LT27d7ystU+sKPFs9cMTE98y/KfGSHlkbGve3ic4vHlvBZ546WwYKOgQy/MdWR6cJCnC5tgNk82YW3IvQdWOs1I+IwEjcsvTnpPxl4amGcpbROZyAW8fp0Iy0OJ/u4vh0kmGWnqxF7Jajygq/M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729586487; c=relaxed/simple; bh=Q249qcROMKLF1grc6bN9/23JwNByrYyjw+ixGk9KOPI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=WMVuVtV1fePryPaD5Y8AlQmKtGuDdYN8ANeqAK2bHSjq6lXQ2yCGark319DJIIJ7sM+HRYt6eUzvDF3AIza4HV57LT8Zw3UIzCo3ExYrhHWZ3svjLLyloVe4ieQ0TDhxWK7s+eBnuBEFQ/XYzUqFfnZF1sowMmhTPywq+uYQxwY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=kNBgdfqx; arc=fail smtp.client-ip=52.101.69.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="kNBgdfqx" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=b7DJn/0MVifXM7XzLyWHVUIQjLonUshUS7ctRdzsKfTLk0r2qwsEVV5RTy5LxrlEFbZG9MLRSWsZnB6vN45JEAg8zqFaswyAOojQUADb4RdmzUUNPNeHJ7CrQlBtjz/ednxIZKdBw3TrQ1z9TmEwktOee4hXWdnyyZoxv4SBD7esFljq5ELSOfCLDthMTlVYANicc6ym2aqXVdeWoYnZgsABwA73/61jHIqZXuzKRwkNtIT+RQCLTN0IIgVeCkKBNxG5eUdtTZawPtPAbYjuIoouRV6LGFXIJZxp4GMwr0Gb9N6MLMzYhEg1Dsfca4JNjHEZtnMhoGXxRxOmxVjeWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=wCbepeNg5bUGuvQ8pE2dwsEeKpIwNwNOTWxgIB3MnUw=; b=NFJT68cuc52LkHrO5JamBi28Cq3dtog98AM36Co0tlKqHAd47Tt8EUM/6SEJSlueHLq9p1nTxhEgsiIA5oGWCWBBGaQ676Lk4UkWWT+Yj2LTO3Gxzz1uuU/o0VrGysuY4nfb+WoXDc+DvtrPDYlzvzVZkPGusn5VN9lb0B4hBn1AsClov/wnRK49PJ8vaYBP4nA0dqQY2AQ6utv7Di0uwJE7BpGJyTCdR7/zaIleE2m9SnSjroxdIJlmMTBaddebRj1uK5tevLD6764/mHyO6uTmYsiIg4pHo6XdwSpyChOGnVnfDhZAGICvLoiv7Gd258sunhw3xXoopQT/3lJdYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wCbepeNg5bUGuvQ8pE2dwsEeKpIwNwNOTWxgIB3MnUw=; b=kNBgdfqxXsz7hLmMukdx0MM3QTDJ+evOe3oT7oJkho+9VLrdnvAyEwdWxdci0wId/LLl6il7sx8ymqD7oIlN6illQ0JKACfiMi2TsYeY6zk/7yaGfDJUVebt0Jo+H6Y9E/FzAOH9Ti9/+K8CXlQdrZDcypvL9hrj/MHTJbhUbPaCkH/6r8fQuD2gEQqO7m4ukykaL6BpdohI4idE5nUs2zHpsT2E7lPK3bcyxApdMZnosmkQQVxMC9wk8tUM+NXtHD8dJlDVxzyhKdv3EDmkp/aR+k3fS/sR/bD1pRrYwXLxiCJskYrShqLSbm4ZXpBdHEAmyRGl7Xlvqt6OlAK4FA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB8254.eurprd04.prod.outlook.com (2603:10a6:102:1cd::24) by AS8PR04MB7831.eurprd04.prod.outlook.com (2603:10a6:20b:2a8::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Tue, 22 Oct 2024 08:41:20 +0000 Received: from PAXPR04MB8254.eurprd04.prod.outlook.com ([fe80::2755:55ac:5d6f:4f87]) by PAXPR04MB8254.eurprd04.prod.outlook.com ([fe80::2755:55ac:5d6f:4f87%3]) with mapi id 15.20.8069.027; Tue, 22 Oct 2024 08:41:20 +0000 From: Ming Qian To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl Cc: yunkec@google.com, nicolas@ndufresne.ca, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, xiahong.bao@nxp.com, ming.zhou@nxp.com, eagle.zhou@nxp.com, tao.jiang_2@nxp.com, ming.qian@oss.nxp.com, imx@lists.linux.dev, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RFC v3 3/4] media: v4l2-ctrls: add support for V4L2_CTRL_WHICH_MIN/MAX_VAL Date: Tue, 22 Oct 2024 17:40:39 +0900 Message-ID: <20241022084040.3390878-4-ming.qian@nxp.com> X-Mailer: git-send-email 2.43.0-rc1 In-Reply-To: <20241022084040.3390878-1-ming.qian@nxp.com> References: <20241022084040.3390878-1-ming.qian@nxp.com> X-ClientProxiedBy: SG2P153CA0007.APCP153.PROD.OUTLOOK.COM (2603:1096::17) To PAXPR04MB8254.eurprd04.prod.outlook.com (2603:10a6:102:1cd::24) Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8254:EE_|AS8PR04MB7831:EE_ X-MS-Office365-Filtering-Correlation-Id: c8083c02-1d00-4d31-3320-08dcf2754d15 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|376014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: ubYsDon1wgebcd5rnkSTrTJhxbuOTL9TAfKxTmEfz7PL75/jJ9bIBPWp3MMMrx3DqtZmYKrvLt+ywfAp1LqWlZnsICPB7ZFRVl2f/RDov/zcPujKUyUu+0tWVJgEF3gxI/UE+BnUmGVeKqAHFm0pbp6kBUBdg6KQ1mwoLFF8CmvygxaU/2WMx8b/SbKoKUqdBlLcP5UE/zY/+6BPeDEjaohi8dcJzuHK6fXwjQwe6nMMe2GuBK8IEurzas43WfL+kJ4jGBmCmL1WlMpV6D0urbPFb5mk+9tcbyamEhyqMey5KBLczsMdG9jz2kZvEONIIE6aAA3V31rmGn9sxYQLHil6lkZHRIvHdfoXevLkKpW2y92Q5VHo2r8iwOzCwhGWTz2+iom0tam+MxmE1pdUXbDhm3WOT98bzZAnHjiHa/bvfu+5+CDMnjnigUYOrr4wUiN39nQfPD5n8XYtBr4pX5fN3og2WBoneRA0w20Ne8i8Idrr8qcYuWw6E3IgWJFbnbVlJwD1UieNWGt1QH2qUnUPIsLqf0TkJ7qIbtHj9rR0vjd3CWvbu+Je4Pv4TZMm1t7eEVR+1cxnmUJ5FoJgaogl6yUw7p4ACB5b3BnWkvXO8BLCgJ+d1ms5mQX1Gh2XWX/pHh/ck3AFrL+8/lWKGWatXv6oBzWNZg+4t27Vfkp/w/7NFpvOOY2TdDSy8t9p3LPnr3aOb1WWuPp5UEMtDA27hb1Ha0oqCvKZAZY9L/LNg2AcnV921848E+nDjc3kgZUWYszEaSv5orK1uGEAT3+LK87MixkjfU000tap7DEBhG455QcoKBpP8C9INupIlS7stQQl0RWX/t84kVUKndvg8YgBVpjp1Gj81Yqa8GWoYq+hunH2u0GOM174UpK+Sc9Q+immryKB9xQYZ2zLzRyq6dXNujU02Xdu/Ma1ygnKZ+shve8o3mQmR7BZa+VcVq96Pp5VsKG16og34PEWenzKGn3aV4ORGmGn7Osdw+GoLdAexWknyCPZoNCmWYZF291+hvlQh6A7XDSytPB3AwK+0KBHoXvaCV4wfhSaqAJXRSGMT9VlNhtYsQlO5itUYtc6yLhBGqYX6r6UGDyw+8/VqWu9BInHVAoy4gxTeX34SVnLTYdo7X8DbqxLwoqw/ZxNIstAJmhrlh49+OhYteoVSLPcial5cXnNHlj6EyHTsLZ5C4fHvt9RXwKWxBNZIP2qmgOTEAZIidkKy4Pb/mFFLWtM++y/M/bU+F1YMAjzyuZSzw31QVbPxQZxkRGm+KqeoYX8v6JJsNjr0HSwRpCpxkygpti6eB4QojiM0RI2LsaNsyiFiIpzLh7HD/gJxDkNITEcfOObMib6i1TrlMXYLfssjo+8HLjw/67MlRM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8254.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(7416014)(376014)(52116014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ouZwe6yr8MqWgesS9srpXKn3FBmVxdRlFWyWMcCb9BOoKgNuKIvTDeBrFw+spkxr92dEm+Pnn58GxDbVUAr43TEfFFgvreNAdK5n7BK+PJVE2FOZLkuvyxPDaemVkSYagvlflEqJPh2XTTsnOrAmpDXSPSHQ7FlRfQ2D9OHsGAmKuH1iNO39Ph8RuK4O96Vo4UCJx0MYBFSb2omGu+qldzrcmUjHWTC8UIUzfEselAt7hXOgIdgPYAFJVl/rYjzMrw3vNkkNIt1NPqe6tlU9e37MbnpOHNZbXdtFgxuDYwmJp3WLBkSNEVagkDdDrd47OCNQM/mVr8SAETObAUpdpJ2mEPDeKgXa7YCPwIXv7IAl05K5vUFUKMGyUisX0Fn5N1gl6PUDw32pJz0lWbhRBlqeFswbw0ZTq9xLxyRlb6THoF0ONxOz/TxXHXbI7VVUZmfbeOf5SQdnA0I4YSnjCFq5p0lZqY2OE+/E9vOlhAOeO+tzwCiQAqmbg49GtETKuOlB5jEEw7QAOFVLLZ630olVuevlz7EprcBO4HkZ2uADXT3zCQpq3pcdm+X9TTeVVxT+UO1m0OktNWXdE2eRL4/hnisahIirk7UDNYyQieRZcCgUgy/hURNU1QCJQgQ4pHYBzke4rxlKlrct/UExaLvdUK144U/IHpPdGPkUdSZvNOoGHDbS8kkyYOPwEZ0uuvreBhYqIKN91ZFWb0BahXaOhsSfLdQ3v2pVqVuJBXb9IuaLosuoHOoTaK0SjXb1WEryQlt9Wvof9ywtW6jT/wEUA553tJ1pm33YaqXFOd2NIQkxA5EdOAoEom+DOh+ndsZx0PSg3Hfmkz8an5XU3Lrcvxk4T+Woy93gRfKhE9FwCdwgA72yzwv11+ahEd2nJEH7VY3uXLnwqgYtsRp0qCr2zJO6o0eu3yRcyq4jpzVY/jT5G4f1BQfc8DxYf63qeFr31Z3GnbxL5CrUvVmjDpP9GrUkyIZ7CuViRbbBF6j1bHx1rsPU/4nYHeYONgVyo37id+v9KS1WlUKn2Tr1eXqpzNjwFhk2GF65pXEcFbJViKqyj7RSRPsJbgfPsO2n+v9WJIJXXPbMOaIW0+jRKVYNTcOx4f2vu8W5SqXLRrDHSjYredH1u+glgPX4ig+BsZcpJNxAWye53+juyXpKVu9+3FwFVi6A9KRCvqKGZ1TwlyoAtNv2vauc70G/6KnQD5dKktwSBH65Ve4fQq4+m9qb+a3y5+MdRJMeHANBPhuhg7ljuzAEHr58nPzxPMaE+46OITncuCqWDAei+BBue1sObJTRr3ht8/lvTiZTcHd4XJjDScOIdkz33kH0DG1nXFJ2kfvcdu8oyX6AtDF50fogTEmhmHx0kHwvS7s5ew9i0jzsPTBvOjoGPJ74qumt6FCqnBgjMX7gkB+lmxrbgxTgwHva6k7BolT7G5aSJNwl0CXSDyCpiVkqDm2i7OtSZYF7EKQx3p9O9a89h5EN6A6aGm1Bq+SnKT1JfEi3AGJA98MfKc1cfYc/27Hy5A7cqfg27VGkFeKWVWEKiKleVa+OQ8FWiW8LO9dnA5Jb1d65RaFcb0HykDm87pTOdLOA X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c8083c02-1d00-4d31-3320-08dcf2754d15 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8254.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 08:41:20.1499 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: y9fhxUa4bqwyEt5lA4KdGWcHuXxDHFYDwYt4RnurlWTzq286iWQFBxi2aP6ZCOkY/qNWLyMjq/WYAryjcx3fOA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7831 From: Hans Verkuil Add the capability of retrieving the min and max values of a compound control. Signed-off-by: Hans Verkuil Signed-off-by: Yunke Cao Signed-off-by: Ming Qian --- .../media/v4l/vidioc-g-ext-ctrls.rst | 22 ++- .../media/v4l/vidioc-queryctrl.rst | 9 +- .../media/videodev2.h.rst.exceptions | 3 + drivers/media/i2c/imx214.c | 4 +- .../media/platform/qcom/venus/venc_ctrls.c | 9 +- drivers/media/v4l2-core/v4l2-ctrls-api.c | 54 +++++-- drivers/media/v4l2-core/v4l2-ctrls-core.c | 153 +++++++++++++++--- drivers/media/v4l2-core/v4l2-ioctl.c | 4 +- include/media/v4l2-ctrls.h | 60 ++++++- include/uapi/linux/videodev2.h | 3 + 10 files changed, 272 insertions(+), 49 deletions(-) diff --git a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst b/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst index b74a74ac06fc..b8698b85bd80 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst @@ -338,14 +338,26 @@ still cause this situation. - Which value of the control to get/set/try. * - :cspan:`2` ``V4L2_CTRL_WHICH_CUR_VAL`` will return the current value of the control, ``V4L2_CTRL_WHICH_DEF_VAL`` will return the default - value of the control and ``V4L2_CTRL_WHICH_REQUEST_VAL`` indicates that - these controls have to be retrieved from a request or tried/set for - a request. In the latter case the ``request_fd`` field contains the + value of the control, ``V4L2_CTRL_WHICH_MIN_VAL`` will return the minimum + value of the control, and ``V4L2_CTRL_WHICH_MAX_VAL`` will return the maximum + value of the control. ``V4L2_CTRL_WHICH_REQUEST_VAL`` indicates that + the control value has to be retrieved from a request or tried/set for + a request. In that case the ``request_fd`` field contains the file descriptor of the request that should be used. If the device does not support requests, then ``EACCES`` will be returned. - When using ``V4L2_CTRL_WHICH_DEF_VAL`` be aware that you can only - get the default value of the control, you cannot set or try it. + When using ``V4L2_CTRL_WHICH_DEF_VAL``, ``V4L2_CTRL_WHICH_MIN_VAL`` + or ``V4L2_CTRL_WHICH_MAX_VAL`` be aware that you can only get the + default/minimum/maximum value of the control, you cannot set or try it. + + Whether a control supports querying the minimum and maximum values using + ``V4L2_CTRL_WHICH_MIN_VAL`` and ``V4L2_CTRL_WHICH_MAX_VAL`` is indicated + by the ``V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX`` flag. Most non-compound + control types support this. For controls with compound types, the + definition of minimum/maximum values are provided by + the control documentation. If a compound control does not document the + meaning of minimum/maximum value, then querying the minimum or maximum + value will result in the error code -EINVAL. For backwards compatibility you can also use a control class here (see :ref:`ctrl-class`). In that case all controls have to diff --git a/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst b/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst index 56d5c8b0b88b..3815732f6a9b 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst @@ -447,7 +447,10 @@ See also the examples in :ref:`control`. - n/a - A struct :c:type:`v4l2_rect`, containing a rectangle described by the position of its top-left corner, the width and the height. Units - depend on the use case. + depend on the use case. Support for ``V4L2_CTRL_WHICH_MIN_VAL`` and + ``V4L2_CTRL_WHICH_MAX_VAL`` is optional and depends on the + ``V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX`` flag. See the documentation of + the specific control on how to interpret the minimum and maximum values. * - ``V4L2_CTRL_TYPE_H264_SPS`` - n/a - n/a @@ -664,6 +667,10 @@ See also the examples in :ref:`control`. ``dims[0]``. So setting the control with a differently sized array will change the ``elems`` field when the control is queried afterwards. + * - ``V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX`` + - 0x1000 + - This control supports getting minimum and maximum values using + vidioc_g_ext_ctrls with V4L2_CTRL_WHICH_MIN/MAX_VAL. Return Value ============ diff --git a/Documentation/userspace-api/media/videodev2.h.rst.exceptions b/Documentation/userspace-api/media/videodev2.h.rst.exceptions index 3cf1380b52b0..35d3456cc812 100644 --- a/Documentation/userspace-api/media/videodev2.h.rst.exceptions +++ b/Documentation/userspace-api/media/videodev2.h.rst.exceptions @@ -396,6 +396,7 @@ replace define V4L2_CTRL_FLAG_HAS_PAYLOAD control-flags replace define V4L2_CTRL_FLAG_EXECUTE_ON_WRITE control-flags replace define V4L2_CTRL_FLAG_MODIFY_LAYOUT control-flags replace define V4L2_CTRL_FLAG_DYNAMIC_ARRAY control-flags +replace define V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX control-flags replace define V4L2_CTRL_FLAG_NEXT_CTRL control replace define V4L2_CTRL_FLAG_NEXT_COMPOUND control @@ -570,6 +571,8 @@ ignore define V4L2_CTRL_DRIVER_PRIV ignore define V4L2_CTRL_MAX_DIMS ignore define V4L2_CTRL_WHICH_CUR_VAL ignore define V4L2_CTRL_WHICH_DEF_VAL +ignore define V4L2_CTRL_WHICH_MIN_VAL +ignore define V4L2_CTRL_WHICH_MAX_VAL ignore define V4L2_CTRL_WHICH_REQUEST_VAL ignore define V4L2_OUT_CAP_CUSTOM_TIMINGS ignore define V4L2_CID_MAX_CTRLS diff --git a/drivers/media/i2c/imx214.c b/drivers/media/i2c/imx214.c index 4962cfe7c83d..b0439005ec71 100644 --- a/drivers/media/i2c/imx214.c +++ b/drivers/media/i2c/imx214.c @@ -774,7 +774,9 @@ static int imx214_ctrls_init(struct imx214 *imx214) imx214->unit_size = v4l2_ctrl_new_std_compound(ctrl_hdlr, NULL, V4L2_CID_UNIT_CELL_SIZE, - v4l2_ctrl_ptr_create((void *)&unit_size)); + v4l2_ctrl_ptr_create((void *)&unit_size), + v4l2_ctrl_ptr_create(NULL), + v4l2_ctrl_ptr_create(NULL)); v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &imx214_ctrl_ops, &props); diff --git a/drivers/media/platform/qcom/venus/venc_ctrls.c b/drivers/media/platform/qcom/venus/venc_ctrls.c index d9d2a293f3ef..7f370438d655 100644 --- a/drivers/media/platform/qcom/venus/venc_ctrls.c +++ b/drivers/media/platform/qcom/venus/venc_ctrls.c @@ -607,11 +607,16 @@ int venc_ctrl_init(struct venus_inst *inst) v4l2_ctrl_new_std_compound(&inst->ctrl_handler, &venc_ctrl_ops, V4L2_CID_COLORIMETRY_HDR10_CLL_INFO, - v4l2_ctrl_ptr_create(&p_hdr10_cll)); + v4l2_ctrl_ptr_create(&p_hdr10_cll), + v4l2_ctrl_ptr_create(NULL), + v4l2_ctrl_ptr_create(NULL)); v4l2_ctrl_new_std_compound(&inst->ctrl_handler, &venc_ctrl_ops, V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY, - v4l2_ctrl_ptr_create((void *)&p_hdr10_mastering)); + v4l2_ctrl_ptr_create((void *)&p_hdr10_mastering), + v4l2_ctrl_ptr_create(NULL), + v4l2_ctrl_ptr_create(NULL)); + v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE, diff --git a/drivers/media/v4l2-core/v4l2-ctrls-api.c b/drivers/media/v4l2-core/v4l2-ctrls-api.c index e5a364efd5e6..d44fbad95c11 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-api.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-api.c @@ -94,6 +94,22 @@ static int def_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl) return ptr_to_user(c, ctrl, ctrl->p_new); } +/* Helper function: copy the minimum control value back to the caller */ +static int min_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl) +{ + ctrl->type_ops->minimum(ctrl, 0, ctrl->p_new); + + return ptr_to_user(c, ctrl, ctrl->p_new); +} + +/* Helper function: copy the maximum control value back to the caller */ +static int max_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl) +{ + ctrl->type_ops->maximum(ctrl, 0, ctrl->p_new); + + return ptr_to_user(c, ctrl, ctrl->p_new); +} + /* Helper function: copy the caller-provider value as the new control value */ static int user_to_new(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl) { @@ -229,8 +245,8 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, cs->error_idx = i; if (cs->which && - cs->which != V4L2_CTRL_WHICH_DEF_VAL && - cs->which != V4L2_CTRL_WHICH_REQUEST_VAL && + (cs->which < V4L2_CTRL_WHICH_DEF_VAL || + cs->which > V4L2_CTRL_WHICH_MAX_VAL) && V4L2_CTRL_ID2WHICH(id) != cs->which) { dprintk(vdev, "invalid which 0x%x or control id 0x%x\n", @@ -259,6 +275,15 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, return -EINVAL; } + if (!(ctrl->flags & V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX) && + (cs->which == V4L2_CTRL_WHICH_MIN_VAL || + cs->which == V4L2_CTRL_WHICH_MAX_VAL)) { + dprintk(vdev, + "invalid which 0x%x or control id 0x%x\n", + cs->which, id); + return -EINVAL; + } + if (ctrl->cluster[0]->ncontrols > 1) have_clusters = true; if (ctrl->cluster[0] != ctrl) @@ -368,8 +393,8 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, */ static int class_check(struct v4l2_ctrl_handler *hdl, u32 which) { - if (which == 0 || which == V4L2_CTRL_WHICH_DEF_VAL || - which == V4L2_CTRL_WHICH_REQUEST_VAL) + if (which == 0 || (which >= V4L2_CTRL_WHICH_DEF_VAL && + which <= V4L2_CTRL_WHICH_MAX_VAL)) return 0; return find_ref_lock(hdl, which | 1) ? 0 : -EINVAL; } @@ -389,10 +414,12 @@ int v4l2_g_ext_ctrls_common(struct v4l2_ctrl_handler *hdl, struct v4l2_ctrl_helper *helpers = helper; int ret; int i, j; - bool is_default, is_request; + bool is_default, is_request, is_min, is_max; is_default = (cs->which == V4L2_CTRL_WHICH_DEF_VAL); is_request = (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL); + is_min = (cs->which == V4L2_CTRL_WHICH_MIN_VAL); + is_max = (cs->which == V4L2_CTRL_WHICH_MAX_VAL); cs->error_idx = cs->count; cs->which = V4L2_CTRL_ID2WHICH(cs->which); @@ -432,13 +459,14 @@ int v4l2_g_ext_ctrls_common(struct v4l2_ctrl_handler *hdl, /* * g_volatile_ctrl will update the new control values. - * This makes no sense for V4L2_CTRL_WHICH_DEF_VAL and + * This makes no sense for V4L2_CTRL_WHICH_DEF_VAL, + * V4L2_CTRL_WHICH_MIN_VAL, V4L2_CTRL_WHICH_MAX_VAL and * V4L2_CTRL_WHICH_REQUEST_VAL. In the case of requests * it is v4l2_ctrl_request_complete() that copies the * volatile controls at the time of request completion * to the request, so you don't want to do that again. */ - if (!is_default && !is_request && + if (!is_default && !is_request && !is_min && !is_max && ((master->flags & V4L2_CTRL_FLAG_VOLATILE) || (master->has_volatiles && !is_cur_manual(master)))) { for (j = 0; j < master->ncontrols; j++) @@ -467,6 +495,10 @@ int v4l2_g_ext_ctrls_common(struct v4l2_ctrl_handler *hdl, ret = -ENOMEM; else if (is_request && ref->p_req_valid) ret = req_to_user(cs->controls + idx, ref); + else if (is_min) + ret = min_to_user(cs->controls + idx, ref->ctrl); + else if (is_max) + ret = max_to_user(cs->controls + idx, ref->ctrl); else if (is_volatile) ret = new_to_user(cs->controls + idx, ref->ctrl); else @@ -564,9 +596,11 @@ int try_set_ext_ctrls_common(struct v4l2_fh *fh, cs->error_idx = cs->count; - /* Default value cannot be changed */ - if (cs->which == V4L2_CTRL_WHICH_DEF_VAL) { - dprintk(vdev, "%s: cannot change default value\n", + /* Default/minimum/maximum values cannot be changed */ + if (cs->which == V4L2_CTRL_WHICH_DEF_VAL || + cs->which == V4L2_CTRL_WHICH_MIN_VAL || + cs->which == V4L2_CTRL_WHICH_MAX_VAL) { + dprintk(vdev, "%s: cannot change default/min/max value\n", video_device_node_name(vdev)); return -EINVAL; } diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c index 4c8744c8cd96..a3abbde5379b 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-core.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c @@ -182,29 +182,64 @@ static void std_init_compound(const struct v4l2_ctrl *ctrl, u32 idx, } } -void v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctrl, u32 from_idx, - union v4l2_ctrl_ptr ptr) +static void std_min_compound(const struct v4l2_ctrl *ctrl, u32 idx, union v4l2_ctrl_ptr ptr) +{ + void *p = ptr.p + idx * ctrl->elem_size; + + if (ctrl->p_min.p_const) + memcpy(p, ctrl->p_min.p_const, ctrl->elem_size); + else + memset(p, 0, ctrl->elem_size); +} + +static void std_max_compound(const struct v4l2_ctrl *ctrl, u32 idx, union v4l2_ctrl_ptr ptr) +{ + void *p = ptr.p + idx * ctrl->elem_size; + + if (ctrl->p_max.p_const) + memcpy(p, ctrl->p_max.p_const, ctrl->elem_size); + else + memset(p, 0, ctrl->elem_size); +} + +static void __v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctrl, u32 from_idx, + u32 which, union v4l2_ctrl_ptr ptr) { unsigned int i; u32 tot_elems = ctrl->elems; u32 elems = tot_elems - from_idx; + s64 value; - if (from_idx >= tot_elems) + switch (which) { + case V4L2_CTRL_WHICH_DEF_VAL: + value = ctrl->default_value; + break; + case V4L2_CTRL_WHICH_MAX_VAL: + value = ctrl->maximum; + break; + case V4L2_CTRL_WHICH_MIN_VAL: + value = ctrl->minimum; + break; + default: return; + } switch (ctrl->type) { case V4L2_CTRL_TYPE_STRING: + if (which == V4L2_CTRL_WHICH_DEF_VAL) + value = ctrl->minimum; + for (i = from_idx; i < tot_elems; i++) { unsigned int offset = i * ctrl->elem_size; - memset(ptr.p_char + offset, ' ', ctrl->minimum); - ptr.p_char[offset + ctrl->minimum] = '\0'; + memset(ptr.p_char + offset, ' ', value); + ptr.p_char[offset + value] = '\0'; } break; case V4L2_CTRL_TYPE_INTEGER64: - if (ctrl->default_value) { + if (value) { for (i = from_idx; i < tot_elems; i++) - ptr.p_s64[i] = ctrl->default_value; + ptr.p_s64[i] = value; } else { memset(ptr.p_s64 + from_idx, 0, elems * sizeof(s64)); } @@ -214,9 +249,9 @@ void v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctrl, u32 from_idx, case V4L2_CTRL_TYPE_MENU: case V4L2_CTRL_TYPE_BITMASK: case V4L2_CTRL_TYPE_BOOLEAN: - if (ctrl->default_value) { + if (value) { for (i = from_idx; i < tot_elems; i++) - ptr.p_s32[i] = ctrl->default_value; + ptr.p_s32[i] = value; } else { memset(ptr.p_s32 + from_idx, 0, elems * sizeof(s32)); } @@ -226,32 +261,63 @@ void v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctrl, u32 from_idx, memset(ptr.p_s32 + from_idx, 0, elems * sizeof(s32)); break; case V4L2_CTRL_TYPE_U8: - memset(ptr.p_u8 + from_idx, ctrl->default_value, elems); + memset(ptr.p_u8 + from_idx, value, elems); break; case V4L2_CTRL_TYPE_U16: - if (ctrl->default_value) { + if (value) { for (i = from_idx; i < tot_elems; i++) - ptr.p_u16[i] = ctrl->default_value; + ptr.p_u16[i] = value; } else { memset(ptr.p_u16 + from_idx, 0, elems * sizeof(u16)); } break; case V4L2_CTRL_TYPE_U32: - if (ctrl->default_value) { + if (value) { for (i = from_idx; i < tot_elems; i++) - ptr.p_u32[i] = ctrl->default_value; + ptr.p_u32[i] = value; } else { memset(ptr.p_u32 + from_idx, 0, elems * sizeof(u32)); } break; default: - for (i = from_idx; i < tot_elems; i++) - std_init_compound(ctrl, i, ptr); + for (i = from_idx; i < tot_elems; i++) { + switch (which) { + case V4L2_CTRL_WHICH_DEF_VAL: + std_init_compound(ctrl, i, ptr); + break; + case V4L2_CTRL_WHICH_MAX_VAL: + std_max_compound(ctrl, i, ptr); + break; + case V4L2_CTRL_WHICH_MIN_VAL: + std_min_compound(ctrl, i, ptr); + break; + } + } break; } } + +void v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctrl, u32 from_idx, + union v4l2_ctrl_ptr ptr) +{ + __v4l2_ctrl_type_op_init(ctrl, from_idx, V4L2_CTRL_WHICH_DEF_VAL, ptr); +} EXPORT_SYMBOL(v4l2_ctrl_type_op_init); +void v4l2_ctrl_type_op_minimum(const struct v4l2_ctrl *ctrl, u32 from_idx, + union v4l2_ctrl_ptr ptr) +{ + __v4l2_ctrl_type_op_init(ctrl, from_idx, V4L2_CTRL_WHICH_MIN_VAL, ptr); +} +EXPORT_SYMBOL(v4l2_ctrl_type_op_minimum); + +void v4l2_ctrl_type_op_maximum(const struct v4l2_ctrl *ctrl, u32 from_idx, + union v4l2_ctrl_ptr ptr) +{ + __v4l2_ctrl_type_op_init(ctrl, from_idx, V4L2_CTRL_WHICH_MAX_VAL, ptr); +} +EXPORT_SYMBOL(v4l2_ctrl_type_op_maximum); + void v4l2_ctrl_type_op_log(const struct v4l2_ctrl *ctrl) { union v4l2_ctrl_ptr ptr = ctrl->p_cur; @@ -1296,6 +1362,8 @@ EXPORT_SYMBOL(v4l2_ctrl_type_op_validate); static const struct v4l2_ctrl_type_ops std_type_ops = { .equal = v4l2_ctrl_type_op_equal, .init = v4l2_ctrl_type_op_init, + .minimum = v4l2_ctrl_type_op_minimum, + .maximum = v4l2_ctrl_type_op_maximum, .log = v4l2_ctrl_type_op_log, .validate = v4l2_ctrl_type_op_validate, }; @@ -1768,7 +1836,10 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, s64 min, s64 max, u64 step, s64 def, const u32 dims[V4L2_CTRL_MAX_DIMS], u32 elem_size, u32 flags, const char * const *qmenu, - const s64 *qmenu_int, const union v4l2_ctrl_ptr p_def, + const s64 *qmenu_int, + const union v4l2_ctrl_ptr p_def, + const union v4l2_ctrl_ptr p_min, + const union v4l2_ctrl_ptr p_max, void *priv) { struct v4l2_ctrl *ctrl; @@ -1892,6 +1963,12 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, break; } + if (type < V4L2_CTRL_COMPOUND_TYPES && + type != V4L2_CTRL_TYPE_BUTTON && + type != V4L2_CTRL_TYPE_CTRL_CLASS && + type != V4L2_CTRL_TYPE_STRING) + flags |= V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX; + /* Sanity checks */ if (id == 0 || name == NULL || !elem_size || id >= V4L2_CID_PRIVATE_BASE || @@ -1900,6 +1977,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, handler_set_err(hdl, -ERANGE); return NULL; } + err = check_range(type, min, max, step, def); if (err) { handler_set_err(hdl, err); @@ -1941,6 +2019,10 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, if (type >= V4L2_CTRL_COMPOUND_TYPES && p_def.p_const) sz_extra += elem_size; + if (type >= V4L2_CTRL_COMPOUND_TYPES && p_min.p_const) + sz_extra += elem_size; + if (type >= V4L2_CTRL_COMPOUND_TYPES && p_max.p_const) + sz_extra += elem_size; ctrl = kvzalloc(sizeof(*ctrl) + sz_extra, GFP_KERNEL); if (ctrl == NULL) { @@ -2006,6 +2088,22 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, memcpy(ctrl->p_def.p, p_def.p_const, elem_size); } + if (flags & V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX) { + void *ptr = ctrl->p_def.p; + + if (p_min.p_const) { + ptr += elem_size; + ctrl->p_min.p = ptr; + memcpy(ctrl->p_min.p, p_min.p_const, elem_size); + } + + if (p_max.p_const) { + ptr += elem_size; + ctrl->p_max.p = ptr; + memcpy(ctrl->p_max.p, p_max.p_const, elem_size); + } + } + ctrl->type_ops->init(ctrl, 0, ctrl->p_cur); cur_to_new(ctrl); @@ -2056,7 +2154,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl, type, min, max, is_menu ? cfg->menu_skip_mask : step, def, cfg->dims, cfg->elem_size, - flags, qmenu, qmenu_int, cfg->p_def, priv); + flags, qmenu, qmenu_int, cfg->p_def, cfg->p_min, + cfg->p_max, priv); if (ctrl) ctrl->is_private = cfg->is_private; return ctrl; @@ -2081,7 +2180,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, } return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, min, max, step, def, NULL, 0, - flags, NULL, NULL, ptr_null, NULL); + flags, NULL, NULL, ptr_null, ptr_null, + ptr_null, NULL); } EXPORT_SYMBOL(v4l2_ctrl_new_std); @@ -2114,7 +2214,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, } return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, 0, max, mask, def, NULL, 0, - flags, qmenu, qmenu_int, ptr_null, NULL); + flags, qmenu, qmenu_int, ptr_null, ptr_null, + ptr_null, NULL); } EXPORT_SYMBOL(v4l2_ctrl_new_std_menu); @@ -2146,7 +2247,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl, } return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, 0, max, mask, def, NULL, 0, - flags, qmenu, NULL, ptr_null, NULL); + flags, qmenu, NULL, ptr_null, ptr_null, + ptr_null, NULL); } EXPORT_SYMBOL(v4l2_ctrl_new_std_menu_items); @@ -2154,7 +2256,9 @@ EXPORT_SYMBOL(v4l2_ctrl_new_std_menu_items); /* Helper function for standard compound controls */ struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl, const struct v4l2_ctrl_ops *ops, u32 id, - const union v4l2_ctrl_ptr p_def) + const union v4l2_ctrl_ptr p_def, + const union v4l2_ctrl_ptr p_min, + const union v4l2_ctrl_ptr p_max) { const char *name; enum v4l2_ctrl_type type; @@ -2168,7 +2272,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl, } return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, min, max, step, def, NULL, 0, - flags, NULL, NULL, p_def, NULL); + flags, NULL, NULL, p_def, p_min, p_max, NULL); } EXPORT_SYMBOL(v4l2_ctrl_new_std_compound); @@ -2192,7 +2296,8 @@ struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, } return v4l2_ctrl_new(hdl, ops, NULL, id, name, type, 0, max, 0, def, NULL, 0, - flags, NULL, qmenu_int, ptr_null, NULL); + flags, NULL, qmenu_int, ptr_null, ptr_null, + ptr_null, NULL); } EXPORT_SYMBOL(v4l2_ctrl_new_int_menu); diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 0304daa8471d..bfdba96e938c 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -893,7 +893,9 @@ static bool check_ext_ctrls(struct v4l2_ext_controls *c, unsigned long ioctl) return false; break; case V4L2_CTRL_WHICH_DEF_VAL: - /* Default value cannot be changed */ + case V4L2_CTRL_WHICH_MIN_VAL: + case V4L2_CTRL_WHICH_MAX_VAL: + /* Default, minimum or maximum value cannot be changed */ if (ioctl == VIDIOC_S_EXT_CTRLS || ioctl == VIDIOC_TRY_EXT_CTRLS) { c->error_idx = c->count; diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index b0db167a3ac4..4bce1af5259a 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h @@ -133,6 +133,8 @@ struct v4l2_ctrl_ops { * * @equal: return true if all ctrl->elems array elements are equal. * @init: initialize the value for array elements from from_idx to ctrl->elems. + * @minimum: set the value to the minimum value of the control. + * @maximum: set the value to the maximum value of the control. * @log: log the value. * @validate: validate the value for ctrl->new_elems array elements. * Return 0 on success and a negative value otherwise. @@ -142,6 +144,10 @@ struct v4l2_ctrl_type_ops { union v4l2_ctrl_ptr ptr1, union v4l2_ctrl_ptr ptr2); void (*init)(const struct v4l2_ctrl *ctrl, u32 from_idx, union v4l2_ctrl_ptr ptr); + void (*minimum)(const struct v4l2_ctrl *ctrl, u32 idx, + union v4l2_ctrl_ptr ptr); + void (*maximum)(const struct v4l2_ctrl *ctrl, u32 idx, + union v4l2_ctrl_ptr ptr); void (*log)(const struct v4l2_ctrl *ctrl); int (*validate)(const struct v4l2_ctrl *ctrl, union v4l2_ctrl_ptr ptr); }; @@ -247,6 +253,12 @@ typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv); * @p_def: The control's default value represented via a union which * provides a standard way of accessing control types * through a pointer (for compound controls only). + * @p_min: The control's minimum value represented via a union which + * provides a standard way of accessing control types + * through a pointer (for compound controls only). + * @p_max: The control's maximum value represented via a union which + * provides a standard way of accessing control types + * through a pointer (for compound controls only). * @p_cur: The control's current value represented via a union which * provides a standard way of accessing control types * through a pointer. @@ -306,6 +318,8 @@ struct v4l2_ctrl { } cur; union v4l2_ctrl_ptr p_def; + union v4l2_ctrl_ptr p_min; + union v4l2_ctrl_ptr p_max; union v4l2_ctrl_ptr p_new; union v4l2_ctrl_ptr p_cur; }; @@ -425,6 +439,8 @@ struct v4l2_ctrl_handler { * @step: The control's step value for non-menu controls. * @def: The control's default value. * @p_def: The control's default value for compound controls. + * @p_min: The control's minimum value for compound controls. + * @p_max: The control's maximum value for compound controls. * @dims: The size of each dimension. * @elem_size: The size in bytes of the control. * @flags: The control's flags. @@ -454,6 +470,8 @@ struct v4l2_ctrl_config { u64 step; s64 def; union v4l2_ctrl_ptr p_def; + union v4l2_ctrl_ptr p_min; + union v4l2_ctrl_ptr p_max; u32 dims[V4L2_CTRL_MAX_DIMS]; u32 elem_size; u32 flags; @@ -723,17 +741,25 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items(struct v4l2_ctrl_handler *hdl, * @ops: The control ops. * @id: The control ID. * @p_def: The control's default value. + * @p_min: The control's minimum value. + * @p_max: The control's maximum value. * - * Sames as v4l2_ctrl_new_std(), but with support to compound controls, thanks - * to the @p_def field. Use v4l2_ctrl_ptr_create() to create @p_def from a - * pointer. Use v4l2_ctrl_ptr_create(NULL) if the default value of the - * compound control should be all zeroes. + * Same as v4l2_ctrl_new_std(), but with support for compound controls. + * To fill in the @p_def, @p_min and @p_max fields, use v4l2_ctrl_ptr_create() + * to convert a pointer to a const union v4l2_ctrl_ptr. + * Use v4l2_ctrl_ptr_create(NULL) if you want the default, minimum or maximum + * value of the compound control to be all zeroes. + * If the compound control does not set the ``V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX`` + * flag, then it does not has minimum and maximum values. In that case just use + * v4l2_ctrl_ptr_create(NULL) for the @p_min and @p_max arguments. * */ struct v4l2_ctrl *v4l2_ctrl_new_std_compound(struct v4l2_ctrl_handler *hdl, const struct v4l2_ctrl_ops *ops, u32 id, - const union v4l2_ctrl_ptr p_def); + const union v4l2_ctrl_ptr p_def, + const union v4l2_ctrl_ptr p_min, + const union v4l2_ctrl_ptr p_max); /** * v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control. @@ -1571,6 +1597,30 @@ bool v4l2_ctrl_type_op_equal(const struct v4l2_ctrl *ctrl, void v4l2_ctrl_type_op_init(const struct v4l2_ctrl *ctrl, u32 from_idx, union v4l2_ctrl_ptr ptr); +/** + * v4l2_ctrl_type_op_minimum - Default v4l2_ctrl_type_ops minimum callback. + * + * @ctrl: The v4l2_ctrl pointer. + * @from_idx: Starting element index. + * @ptr: The v4l2 control value. + * + * Return: void + */ +void v4l2_ctrl_type_op_minimum(const struct v4l2_ctrl *ctrl, u32 from_idx, + union v4l2_ctrl_ptr ptr); + +/** + * v4l2_ctrl_type_op_maximum - Default v4l2_ctrl_type_ops maximum callback. + * + * @ctrl: The v4l2_ctrl pointer. + * @from_idx: Starting element index. + * @ptr: The v4l2 control value. + * + * Return: void + */ +void v4l2_ctrl_type_op_maximum(const struct v4l2_ctrl *ctrl, u32 from_idx, + union v4l2_ctrl_ptr ptr); + /** * v4l2_ctrl_type_op_log - Default v4l2_ctrl_type_ops log callback. * diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index c1c2ae150d30..c8cb2796130f 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -1912,6 +1912,8 @@ struct v4l2_ext_controls { #define V4L2_CTRL_WHICH_CUR_VAL 0 #define V4L2_CTRL_WHICH_DEF_VAL 0x0f000000 #define V4L2_CTRL_WHICH_REQUEST_VAL 0x0f010000 +#define V4L2_CTRL_WHICH_MIN_VAL 0x0f020000 +#define V4L2_CTRL_WHICH_MAX_VAL 0x0f030000 enum v4l2_ctrl_type { V4L2_CTRL_TYPE_INTEGER = 1, @@ -2019,6 +2021,7 @@ struct v4l2_querymenu { #define V4L2_CTRL_FLAG_EXECUTE_ON_WRITE 0x0200 #define V4L2_CTRL_FLAG_MODIFY_LAYOUT 0x0400 #define V4L2_CTRL_FLAG_DYNAMIC_ARRAY 0x0800 +#define V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX 0x1000 /* Query flags, to be ORed with the control ID */ #define V4L2_CTRL_FLAG_NEXT_CTRL 0x80000000 From patchwork Tue Oct 22 08:40:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 13845323 Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010037.outbound.protection.outlook.com [52.101.69.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 514BD187864; Tue, 22 Oct 2024 08:41:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.69.37 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729586489; cv=fail; b=JFiTxw5IkBDk6Dty4hS48K4Fe84Dp0eUUf45EZknPev7ctHcc01Pjbq6EmgYtWPvqYRNW/oCKX/nCeguOF6kQLFbST7WP8z7BZih3d+dFkNhoNfbk7IXRzHYF6vT/JVS0mr47RHr8el4dkZKE6weEze9b4LYtBiNInx4iQ/gpa4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729586489; c=relaxed/simple; bh=GLbEl+5LVeDE7BL2JwoiNqyJ8jD8lfsmaYFkLyeA0LI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=XlIJR+Chy+eiiC8+l8xrUaUGKZQUML4bUsXAvvmltBn0fEBW+POe7SRQeATFwx8lcJMYo1IFisks0pm4zn+C9rARZRhFMnPUiQ3QG0K3or7eLwEmM5fHKYh3oZbiCtxdHkpWr+1Au1NP7pulzvpgVGbGLXrrI/tqgOYVroMGsuw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=g7L+kyWO; arc=fail smtp.client-ip=52.101.69.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="g7L+kyWO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MCicKPC0rpFuhUslYchPgGaxkTbNjQlqMSOmQ85YT1C3Dtmo0MmYaA5djf59+Q2k2t5/63HEmUMOGO48h987ATzbf7jUOQfheJIj8dX8x3QxuEMvVdOWkH4jM6zKXNKtq37kfqrXuM2VVh5t1Jy6A5PgUdG48FTVcD2ov7ni4SGsYXwMROVSMM65N05nklW0Ij6KilSuC3YTFSq9UFaEv4bQn3Im2UykbVTJvoogzjOKS74EoGprVwFfBKNj1XQwfzD2yzcyx2qO1z5oPR5ru+Za0zl0RMKNcZix/L82H/IE6pmk0PzvI5ikbMhfEArdJDjKmIwS8gx3Vu87kk8fCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0kNrIVmP/RIPmOKRXkCTPwJ2jcK/8ecXMevlWn1EQ1k=; b=XQaPKTU+i7QlKnRg/HMePCeDgIV7IOLZ96/kFvMaM6EzISslWW3QrvFyfWdFefgA1/3DL5y4xg4ztZlyAKUTP/9bZaJUMcwxj52cuyNTzIBOrN/k+85kkZFwq88jJaeJwZY/RonBHDtYEDcq6OEeXm3D5ZBePPeA5B2dxZaHChm7eFwCqTEAYM40uPb7ZXnB7lGSY6N4KvBhEc4gDtwQyKemPyUx00VoJpdhHUXe86APsLGEEhtmu8X9Kkm6KrbHsi4YLqL3EVwAAJQSk3RU8Z5ilkAKcsLbNyKVoFpG6LPRx9m0QcQv92XtIAGfKoCHKHq90XhW7kaZh/fTniWqtg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0kNrIVmP/RIPmOKRXkCTPwJ2jcK/8ecXMevlWn1EQ1k=; b=g7L+kyWOWIrSgLzH2DMHJ1MtRBB6WKh/VY48Aw+oF6PYUnNl+dMMSf+LUObeBenlsXSUrdv2oIKZRv9lVFqWjdBHadFhm8jZP1S0qwL7/Q60I87o30i9RqjVxKS1/B80v8LTZbB0pyYCKgnjYx7aTBby9Z/zcBYTRl9jVCKrINHvtFfLEFdN9QoPSh4iqJSfaylexdcsRrxRMNWKknpcmPyD7xbhtLr19jK9vj/zT5NQhZRKPici/gaBadmWW0yXAsbKDFT7dB/5nsYbg7kqZTjmxUL0d0FxyCeIS5JOpRMPLTXdk6zDq2sSYK7HrDuzcYkphIyxUzsqB5uDokS1lg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB8254.eurprd04.prod.outlook.com (2603:10a6:102:1cd::24) by AS8PR04MB7831.eurprd04.prod.outlook.com (2603:10a6:20b:2a8::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Tue, 22 Oct 2024 08:41:25 +0000 Received: from PAXPR04MB8254.eurprd04.prod.outlook.com ([fe80::2755:55ac:5d6f:4f87]) by PAXPR04MB8254.eurprd04.prod.outlook.com ([fe80::2755:55ac:5d6f:4f87%3]) with mapi id 15.20.8069.027; Tue, 22 Oct 2024 08:41:25 +0000 From: Ming Qian To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl Cc: yunkec@google.com, nicolas@ndufresne.ca, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, xiahong.bao@nxp.com, ming.zhou@nxp.com, eagle.zhou@nxp.com, tao.jiang_2@nxp.com, ming.qian@oss.nxp.com, imx@lists.linux.dev, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RFC v3 4/4] media: v4l2-ctrls: Add video encoder ROI ctrls Date: Tue, 22 Oct 2024 17:40:40 +0900 Message-ID: <20241022084040.3390878-5-ming.qian@nxp.com> X-Mailer: git-send-email 2.43.0-rc1 In-Reply-To: <20241022084040.3390878-1-ming.qian@nxp.com> References: <20241022084040.3390878-1-ming.qian@nxp.com> X-ClientProxiedBy: SG2P153CA0007.APCP153.PROD.OUTLOOK.COM (2603:1096::17) To PAXPR04MB8254.eurprd04.prod.outlook.com (2603:10a6:102:1cd::24) Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8254:EE_|AS8PR04MB7831:EE_ X-MS-Office365-Filtering-Correlation-Id: 1c64fde8-d3b6-49e3-7b2b-08dcf2754fff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|7416014|376014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: R/uqbIPHIYWNJJzUGfPRFLJMhHv60maErZI+w/8M2aHk0YnNJhDVZxWG5piKpAzvqORX7X2T1Xxrg+gYPVjwkfNWKFZ+5giOhV81J/vnh07rgnz3udn12acMJbLjNkxcI1gCXVFeNa2Q5JuiGUr02V12AEQxagl/Ej5FavDqpmvfvtr+Mboi2ZZWBeUMWOkjqkUuphJbEZM3gpYMaeNNQtM7+UkV1iy8WzWJCvqAKUV/g7d2tHolniI/CjDHR7t0tR9fAWbGBQ7oU2t5PfO2SGaLf/LTVWbPPoG1AnJm3DvEoOB2s32UWNnbGJPCUWal7eyAvJS26njRoGIvURPaVyAElTWdGuLgIYlWJJ+WL1BArn8wyLerK10Pn1sS3/gYKlfqFEqk32vAVfsxx4JZyFgb+hPIiEnilSmy58kvu5varUruVtwp3nCWbDsSoesROGQYUAYa4yGa5Z5605Em24ACPRJtyPJXjOHnW5P/Rx4GdFXg/gpjf6IXe9tHsM5tCuTzhET7RNUOoqSfTmnILuvnhOn+8x1EouBGQD85L9jDSj1Nw7eBh4cN8p/VLVNsViCdCbtEIUm41A5PLa46sSmOVAlZpsGNLXQWzDdTSVUvbc4oy7hI2gnhveSFg1l8PewtO9ep2PyRGcc440dY0PkGTTjOJtnerjlUGix8mzidCzXojMedaRJuORybehNUncbj9G6WKPs2fJh1xR6r6veN77teFn6+ClL63GkyocBP5baFoZkL9thGi3tf1KuyxJ0pYYpe93zj/SeFjvzSfMo6vgHXV+r8/UvshNd3MnRfG4h59Dk9CQMRRRfGBRVUZCd4Az7jfmpBaMuk2Ez/cngJso9pWiDxezonP3GcjANnAKXNpESzvDNKRZW3lnpAQCGQV5c8v2VmDqRz8eZNJFGG2QP4JdFBvaIDGtZyc/o4t1LK++cOAzk/HCaow4nBd84XFJUH/a4zDtb3UfO4w+fFEKzQtshEjPAWwlZtO+3P68ofNQjnk1rY0pGz/CYxt2arakyGHrwNqkX0y3BnYzNQ14QX15mQaZV6icm5hd3CU9XpMVXJ+HHOujtQGAtHueg0X9U95kQhta5ndzuaI08VAB5IiZhHmCYwXdJpL10NItNQMMHDyJKgmhMtK51IsYJrjuoRT2czCxR7rAjtCl0DNkuRhDPWUkERfANLhty0T9IyrxEv0nNpwhZZwpeNrWpBcIca4PGW8qJlJkHPgzR6OKfAfURsNnGsrZdu+mOVt51OGLroXN/vGxph/TXSeFYqvpnmrmDbTuAIbsXcQl9/Ooy2L2XdbkOsFQKDR5yaXyAQ9eqIJutsvfTiPFknPStOul8hq66DBS2riaV5q+pYkOKXb2BikYkip1a6kvU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8254.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(7416014)(376014)(52116014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OV2vj4AFz2mSThnkkzRecXOPrJyL6ZpAbWF9LU6Uik0jUAkfB7JfyO5b4utFolKUg66GdA6hZ6O4A14xU2k2unBo8dIyGNYtxBw48uNJXRAMpxM3jo7aYJTSRxVJsPkzsGnHLOss/XKUq1gBi9uche9h6uhGfC7nCWPcVCQIi6zB12taqdUEWL9D6KxiyoMlEL7YOMAFzoJq9XvlYB5oU9NMEV9eM0z+VvPvvSivYeBGT5y2Ikr+5IrOWS+/omtGDNCWPPA/dFRniCxzXlfeDO48MfmvBL9C89o6XvOlAACiBHJ37Zt1o+3rhBQLHShVYy5K5ylt61XLTUWDIDmFMvBQQn/f/TXJ88/QHUE7zdP5SYxqMDz+qxkGL8eFUI+iYVHb3LiHEzymQ9VfjJMHJ6cU9sshak9rPMTNDkd4Vp+6zA9xfN910bNqTYTRTjINbsuoillVlZMYtTdNxbBLdhKp9INjbxZEX1TcFsokdwJu0Mlo9P1vkR5aL9z98f7IYAwcFS8Qt0cu2wVog0twUIs0A4VTNA9MT1oMkdzudcx/GPEPKuqC0Z+0fOfzpRQ2JJUMSFKeqpARnDtMxufHcBUTQ6u09IV+UX9F4o1STCUc2czKf56c4ibNBWAHZZhZdK6bIWroQfv0Sk6OWj2rfFF5F0PjArCYwTHvkg7Q3HI7GQMknnZKodkisv15gnC9kJ8zpjbX9IuR1DSK9Q/hkWcN/V6Hz032gXcCe7ppHVhrEUznjP2K5n+Mm7AdRQEaQjMsD/bim3grcZ70MuSthj+MY9D4LnDPaMBzDvhI5lK606U+jdy8A5KS0bkltfeI6ixEW+b++BP9uWyi3eaOJDYgYXZv9Pj/scwV7201WF+4tLCXzCW+7yanLqXCElYti/tM/ydRhW1blUKCZtfjOEpArat3dlNtUZKXlliRqZA08b69fiOEGARAj2n96pEEpVMZgN6iFEaY+ZuaVfypOoiD++QUIbVZXtNZK8lDrImmOKEMbKg+e0CkexXcs9+ktjIoq6WsUefqaPVpTJY8tNLN+12EgSFxfeXLCHZ2bdLz4Ozf9pHsJuIsARhxuy7iTYId3XIVA01XPZFXwAcHJq81z5AE6ftE+GTaSeG1eLZjojjHYK3OqhKS5wOZu10QACdLNIUMJx5WUBdkfcdMWmQg03D1HxeyURRPpDtHygDMhgJ3dF8DSzLKXP6WYctws2LRPCoUFbXRJZMYcY075zMPXzQu/CI+U6SgS4uR8UybNiiUUr98Xl6IVbY/KCmmr/VEsU/8UTt+aEINqFomoVg+/JZu5Z/RGtak0lqU2M1mzSvsZyMDSzH/OXATCDuKUyOrxUREKw03D073rfV/O3tXP107/qlRkpijIjcZ6LBZP8+SXcWI6haChfbDJj/Imd2m2FCV3W1t60dGp1Rh774R14D3PoDQOp7y9yB2U/EaxT2DCYsqN6a4sKKQYn8POrVhZxdvFBm6u52vd8/IMpkjVmcu3rlhvMfLlSzkd/SLthKInJAPkL+qzCZyA5PfUmsrYADSlVxgZHSU2M2dkGRSJM8VIkHcTSpqGJKfE4hFsosuJ9ybZdBJSshjaZX5 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c64fde8-d3b6-49e3-7b2b-08dcf2754fff X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8254.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 08:41:25.1587 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: x3IrJGAuSKdyW/uMmhc99j7v6vrjZY0wi1fH8NXywjO5UICuhDYmhEDWFVDZEVmOF9HgEKeu0n2tdh4Y1Ll5bw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB7831 Add some ctrls to support the video encoder region-of-interest(ROI) feature. The ROI QP Map and rectangular configuration are supported. Signed-off-by: Ming Qian Signed-off-by: TaoJiang --- .../media/v4l/ext-ctrls-codec.rst | 95 +++++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls-defs.c | 46 +++++++++ include/uapi/linux/v4l2-controls.h | 16 ++++ 3 files changed, 157 insertions(+) diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst index 4a379bd9e3fb..7188d8212677 100644 --- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst @@ -1667,6 +1667,101 @@ enum v4l2_mpeg_video_h264_hierarchical_coding_type - Codecs need to always use the specified range, rather then a HW custom range. Applicable to encoders +``V4L2_CID_MPEG_VIDEO_ROI_MODE`` + (enum) + +enum v4l2_mpeg_video_roi_mode - + Indicates Video Encoding region-of-interest (ROI) Mode. + Possible values are: + + +.. flat-table:: + :header-rows: 0 + :stub-columns: 0 + + * - ``V4L2_MPEG_VIDEO_ROI_MODE_NONE`` + - No ROI in the MPEG stream + * - ``V4L2_MPEG_VIDEO_ROI_MODE_RECT_DELTA_QP`` + - Rectangle ROI mode and specifies ROI delta QP. + * - ``V4L2_MPEG_VIDEO_ROI_MODE_RECT_PRIORITY`` + - Rectangle ROI mode and specifies ROI priority. + * - ``V4L2_MPEG_VIDEO_ROI_MODE_MAP_DELTA_QP`` + - Map ROI mode and specifies ROI delta QP + * - ``V4L2_MPEG_VIDEO_ROI_MODE_MAP_ABSOLUTE_QP`` + - Map ROI mode and specifies ROI absolute QP value + +``V4L2_CID_MPEG_VIDEO_ROI_BLOCK_SIZE (struct)`` + This control returns the ROI block size in pixels. The struct + :c:type:`v4l2_area` provides the width and height in separate + fields. The resolution of the frame will be rounded up to be + aligned to this value when it's partitioned in blocks for QP + maps and the number of QP values in those maps will be the + number of blocks of these indicated pixel size that comprise + a full frame. This control depends on the encoding format, + and the detailed encoder hardware. + Applicable to encoders. + +``V4L2_CID_MPEG_VIDEO_ROI_RECT (struct)`` + A struct :c:type:`v4l2_rect` provides the rectangular region + described by the position of its top-left corner, the width + and the height. The unit is in pixels. And it should be aligned + to the ROI block size, which can be queried from + ``V4L2_CID_MPEG_VIDEO_ROI_BLOCK_SIZE``. X,Y gets rounded down, + and width/height up. The maximum number of rectangular regions + depends on the hardware. This control is a dynamically sized array. + This control is applicable when ``V4L2_CID_MPEG_VIDEO_ROI_MODE`` + value is ``V4L2_MPEG_VIDEO_ROI_MODE_RECT_DELTA_QP`` or + ``V4L2_MPEG_VIDEO_ROI_MODE_RECT_PRIORITY``. For overlapping + regions, the value that is first in the ROI array will have priority. + Applicable to encoders. + +``V4L2_MPEG_VIDEO_ROI_MODE_RECT_DELTA_QP (integer)`` + Specifies the ROI delta QP of a rectangular region. The delta QP + is the value that will be added on top of the frame level QP. + It can be positive (more distortion) or negative (less distortion) + values. This control is applicable when + ``V4L2_CID_MPEG_VIDEO_ROI_MODE`` value is + ``V4L2_MPEG_VIDEO_ROI_MODE_RECT_DELTA_QP``, and need to be used + in combination with ``V4L2_CID_MPEG_VIDEO_ROI_RECT``. + This control is a dynamically sized array, and the array size + should match ``V4L2_CID_MPEG_VIDEO_ROI_RECT``. + Applicable to encoders. + +``V4L2_MPEG_VIDEO_ROI_MODE_RECT_PRIORITY (integer)`` + Specifies the ROI priority of a rectangular region. it can + be positive (more important) or negative (less important) + values and is compared with non-ROI region (taken as value 0). + This control is applicable when ``V4L2_CID_MPEG_VIDEO_ROI_MODE`` + value is ``V4L2_MPEG_VIDEO_ROI_MODE_RECT_PRIORITY``, and need + to be used in combination with ``V4L2_CID_MPEG_VIDEO_ROI_RECT``. + Applicable to encoders. + +``V4L2_CID_MPEG_VIDEO_ROI_MAP_DELTA_QP (integer)`` + This is to configure ROI as a map as an integer array, + each value represents the delta QP of a block region + in raster scan order. The block size can be got from + ``V4L2_CID_MPEG_VIDEO_ROI_BLOCK_SIZE``. This control is a + dynamically sized array, the array size can be calculated + from video resolution and the ROI block size, and the + width and height should be rounded up to be aligned to + the block size. This control is applicable when + ``V4L2_CID_MPEG_VIDEO_ROI_MODE`` value is + ``V4L2_CID_MPEG_VIDEO_ROI_MAP_DELTA_QP``. + Applicable to encoders. + +``V4L2_CID_MPEG_VIDEO_ROI_MAP_ABSOLUTE_QP (integer)`` + This is to configure ROI as a map as an integer array, + each value represents the absolute QP of a block region + in raster scan order. The block size can be got from + ``V4L2_CID_MPEG_VIDEO_ROI_BLOCK_SIZE``. This control is a + dynamically sized array, the array size can be calculated + from video resolution and the ROI block size, and the + width and height should be rounded up to be aligned to + the block size. This control is applicable when + ``V4L2_CID_MPEG_VIDEO_ROI_MODE`` value is + ``V4L2_CID_MPEG_VIDEO_ROI_MAP_ABSOLUTE_QP``. + Applicable to encoders. + .. raw:: latex \normalsize diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/media/v4l2-core/v4l2-ctrls-defs.c index 1ea52011247a..4d89309bf8d0 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c @@ -612,6 +612,15 @@ const char * const *v4l2_ctrl_get_menu(u32 id) NULL, }; + static const char * const mpeg_video_roi_mode[] = { + "None", + "Rectangle Delta QP", + "Rectangle Priority", + "Map Delta QP", + "Map Absolute QP", + NULL, + }; + switch (id) { case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return mpeg_audio_sampling_freq; @@ -750,6 +759,8 @@ const char * const *v4l2_ctrl_get_menu(u32 id) return camera_orientation; case V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE: return intra_refresh_period_type; + case V4L2_CID_MPEG_VIDEO_ROI_MODE: + return mpeg_video_roi_mode; default: return NULL; } @@ -971,6 +982,13 @@ const char *v4l2_ctrl_get_name(u32 id) case V4L2_CID_MPEG_VIDEO_FRAME_LTR_INDEX: return "Frame LTR Index"; case V4L2_CID_MPEG_VIDEO_USE_LTR_FRAMES: return "Use LTR Frames"; case V4L2_CID_MPEG_VIDEO_AVERAGE_QP: return "Average QP Value"; + case V4L2_CID_MPEG_VIDEO_ROI_MODE: return "Video ROI Mode"; + case V4L2_CID_MPEG_VIDEO_ROI_BLOCK_SIZE: return "Video ROI Block Size"; + case V4L2_CID_MPEG_VIDEO_ROI_RECT: return "Video ROI Rectangle Region"; + case V4L2_CID_MPEG_VIDEO_ROI_RECT_DELTA_QP: return "Video ROI Rectangle Delta QP"; + case V4L2_CID_MPEG_VIDEO_ROI_RECT_PRIORITY: return "Video ROI Rectangle Priority"; + case V4L2_CID_MPEG_VIDEO_ROI_MAP_DELTA_QP: return "Video ROI Delta QP Map"; + case V4L2_CID_MPEG_VIDEO_ROI_MAP_ABSOLUTE_QP: return "Video ROI Absolute QP Map"; case V4L2_CID_FWHT_I_FRAME_QP: return "FWHT I-Frame QP Value"; case V4L2_CID_FWHT_P_FRAME_QP: return "FWHT P-Frame QP Value"; @@ -1512,6 +1530,34 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, *type = V4L2_CTRL_TYPE_INTEGER; *flags |= V4L2_CTRL_FLAG_READ_ONLY; break; + case V4L2_CID_MPEG_VIDEO_ROI_MODE: + *type = V4L2_CTRL_TYPE_MENU; + *flags |= V4L2_CTRL_FLAG_UPDATE; + break; + case V4L2_CID_MPEG_VIDEO_ROI_BLOCK_SIZE: + *type = V4L2_CTRL_TYPE_AREA; + *flags |= V4L2_CTRL_FLAG_READ_ONLY; + break; + case V4L2_CID_MPEG_VIDEO_ROI_RECT: + *type = V4L2_CTRL_TYPE_RECT; + *flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY | V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX; + break; + case V4L2_CID_MPEG_VIDEO_ROI_RECT_DELTA_QP: + *type = V4L2_CTRL_TYPE_INTEGER; + *flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY | V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX; + break; + case V4L2_CID_MPEG_VIDEO_ROI_RECT_PRIORITY: + *type = V4L2_CTRL_TYPE_INTEGER; + *flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY | V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX; + break; + case V4L2_CID_MPEG_VIDEO_ROI_MAP_DELTA_QP: + *type = V4L2_CTRL_TYPE_INTEGER; + *flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY | V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX; + break; + case V4L2_CID_MPEG_VIDEO_ROI_MAP_ABSOLUTE_QP: + *type = V4L2_CTRL_TYPE_INTEGER; + *flags |= V4L2_CTRL_FLAG_DYNAMIC_ARRAY | V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX; + break; case V4L2_CID_PIXEL_RATE: *type = V4L2_CTRL_TYPE_INTEGER64; *flags |= V4L2_CTRL_FLAG_READ_ONLY; diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h index 974fd254e573..bf67d53af737 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -900,6 +900,22 @@ enum v4l2_mpeg_video_av1_level { #define V4L2_CID_MPEG_VIDEO_AVERAGE_QP (V4L2_CID_CODEC_BASE + 657) +enum v4l2_mpeg_video_roi_mode { + V4L2_MPEG_VIDEO_ROI_MODE_NONE, + V4L2_MPEG_VIDEO_ROI_MODE_RECT_DELTA_QP, + V4L2_MPEG_VIDEO_ROI_MODE_RECT_PRIORITY, + V4L2_MPEG_VIDEO_ROI_MODE_MAP_DELTA_QP, + V4L2_MPEG_VIDEO_ROI_MODE_MAP_ABSOLUTE_QP +}; + +#define V4L2_CID_MPEG_VIDEO_ROI_MODE (V4L2_CID_CODEC_BASE + 658) +#define V4L2_CID_MPEG_VIDEO_ROI_BLOCK_SIZE (V4L2_CID_CODEC_BASE + 659) +#define V4L2_CID_MPEG_VIDEO_ROI_RECT (V4L2_CID_CODEC_BASE + 660) +#define V4L2_CID_MPEG_VIDEO_ROI_RECT_DELTA_QP (V4L2_CID_CODEC_BASE + 661) +#define V4L2_CID_MPEG_VIDEO_ROI_RECT_PRIORITY (V4L2_CID_CODEC_BASE + 662) +#define V4L2_CID_MPEG_VIDEO_ROI_MAP_DELTA_QP (V4L2_CID_CODEC_BASE + 663) +#define V4L2_CID_MPEG_VIDEO_ROI_MAP_ABSOLUTE_QP (V4L2_CID_CODEC_BASE + 664) + /* MPEG-class control IDs specific to the CX2341x driver as defined by V4L2 */ #define V4L2_CID_CODEC_CX2341X_BASE (V4L2_CTRL_CLASS_CODEC | 0x1000) #define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE (V4L2_CID_CODEC_CX2341X_BASE+0)