From patchwork Fri Jul 25 10:33:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 23955 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 7FF1BC3237 for ; Fri, 25 Jul 2025 10:34:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7C4F3690BB; Fri, 25 Jul 2025 12:33:59 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OjlJ4K6e"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AA9C569071 for ; Fri, 25 Jul 2025 12:33:57 +0200 (CEST) Received: from [192.168.0.172] (mob-5-90-139-29.net.vodafone.it [5.90.139.29]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E44D6C73; Fri, 25 Jul 2025 12:33:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1753439598; bh=cJOZvjVobbNT//xYrrhU5PiPAC92pDU3Hm0IA71Cbu0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OjlJ4K6eFxUZRMpWymBPv3kcgTjYAk0L+aASqN1ZCmTTXH07WtsI3cgHvjhzC7iD9 YTyMVh+WS8+mhgHZ4PzhbU9I2clwGsf3H3BmDHlgC1G/O6Gt6D2ovrZRnbQQ4cKNlr th+vWyObVUK2cXD4kp/ISAZxrXrIuHmTZDJTskbE= From: Jacopo Mondi Date: Fri, 25 Jul 2025 12:33:46 +0200 Subject: [PATCH 1/9] include: linux: Update media.h with media flags MIME-Version: 1.0 Message-Id: <20250725-multicontext-v1-1-ea558291e101@ideasonboard.com> References: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> In-Reply-To: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1015; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=cJOZvjVobbNT//xYrrhU5PiPAC92pDU3Hm0IA71Cbu0=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBog12TfQodz5Ha0hFF3h4nZIzIMW4fdSteaHAMK B54JKPRYyuJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaINdkwAKCRByNAaPFqFW PGe4D/4hcHHUM6OWMyypMz8b74F5k1wuRATLzdjDfE5q1GDV4WRb+oAjKLehUu/r5+IOeDMojlh R7CaF9dN+KKCNX+dKr50Q2NVSYCpQ+5Fm6dRre90MIPkKu3fIICt01Z4u2djlBirSRKclSPgvq7 bNhDlb4enl7XZqA1se+ORSUtfb0nDGE+/HRkJK/RVAiP78Xx4cRfuPm7rGarCdljOhwQoagfbDc IacqHqliUunr5RwklZXPYioBY3tqeuZZAVi/7CO5ulMhaxcY1YEBdG7EhD2rLI5VWcCmi7Mhw8b 0cK7sHZQTxpD2f8Z0jYuRNdRKlo4zm68gOKxz5rTMtnEmJpz9sDXdaTYnt4/X0kNQMl8C18cLBp BMUFiIyLp0xC4aG3c2IAkSyVrlCocyH3o86fQXrqk8s2HzHvQqmBP4R1LaCAG2IpCwJbRdw76jJ Dh4ucrA/4w8MM2551DTvrPLDn5fAuRx6lH25xka6MKVnxhm2WGvL4nRqL70dLziv8YtRqFC1iKd xikoIgqZ6l1TA/2oSQgVcWQQyL1JHvEeHUCGSl2bhOfcDlht6zykG9LHyT0SPuJrhKoQxrmCuJA 98H7fR0Nt7GdHxycW0j2oix3PcG5uvtZlyC2lV8D4QtH0ftpAfbr2kz12hhNWFwdcT/+epTu6AR UoZAF/3COWvp3og== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Temporary update the media.h header from Linux kernel using the flags introduced by: https://patchwork.linuxtv.org/project/linux-media/patch/20250724-multicontext-mainline-2025-v2-21-c9b316773486@ideasonboard.com/ Signed-off-by: Jacopo Mondi Reviewed-by: Isaac Scott --- include/linux/media.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/media.h b/include/linux/media.h index 4a733b9beb27d6af3e1067dee5096f280be86eab..fd17e3a458165c91d63cd393047bdf796a45c801 100644 --- a/include/linux/media.h +++ b/include/linux/media.h @@ -23,6 +23,9 @@ #include #include +/* Media device flags. */ +#define MEDIA_DEVICE_FL_CONTEXT 0x00000001 + struct media_device_info { char driver[16]; char model[32]; @@ -31,7 +34,8 @@ struct media_device_info { __u32 media_version; __u32 hw_revision; __u32 driver_version; - __u32 reserved[31]; + __u32 flags; + __u32 reserved[30]; }; /* From patchwork Fri Jul 25 10:33:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 23956 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 2B70BC3237 for ; Fri, 25 Jul 2025 10:34:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 96BB1690A8; Fri, 25 Jul 2025 12:34:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qcbQasQT"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0D5ED69071 for ; Fri, 25 Jul 2025 12:33:58 +0200 (CEST) Received: from [192.168.0.172] (mob-5-90-139-29.net.vodafone.it [5.90.139.29]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4CFD578E; Fri, 25 Jul 2025 12:33:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1753439598; bh=Z2/WtdDONORQH89nZEXPQ2EnQzqm68lnaSQvjcasAW4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qcbQasQT15D3rIqEZ03q0aWvOkyp2cKM1PLatmoxChOLzg7Ja7tsjvwT4PRJca2Bn MfPvxJxluMAzj1a1QYkHa+rQBWaU3F3EyuRC9dH3Yv+PjgE1jSkDrNgqXoYQ0FYrY4 HnDjbWebFtT1A4feHVsNvnynnRZOx1yQ3ySYulmI= From: Jacopo Mondi Date: Fri, 25 Jul 2025 12:33:47 +0200 Subject: [PATCH 2/9] include: linux: videodev2: Add BIND_CONTEXT MIME-Version: 1.0 Message-Id: <20250725-multicontext-v1-2-ea558291e101@ideasonboard.com> References: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> In-Reply-To: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1306; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=Z2/WtdDONORQH89nZEXPQ2EnQzqm68lnaSQvjcasAW4=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBog12TFVED8n7/x4tTZbt5cQQds/8hpR05Hh5iu nPBdNsrMKWJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaINdkwAKCRByNAaPFqFW PKGsD/9TJvkqAgYHmli22CVhs0d4brShFAi7e1Io7B+a+lds4drx4qHGEob+Wpr92GiUaTwZ/9x maYqvgYCr39MpFSgfb7y25Ul6Yhdt5OZ/iVPQXZIzqpHbuqWIa3cdtHcolWHhuARJe5M9bFMHig /NNA3X90DYJFsAjLemkq5uu5NViwHsoSyJWHWECV14qZMk4zyrJlTgXSqJdHezMymNeOZfYI7/8 GsbNLMzdQVg2jyumQiR5f4hNQPwveWG/mq5khEtoNqFWf7sI1FiHy9lVg+xsb39OMXuyb39Gfmx Waqe/ST6Rl6VT32kGir08pISeU7toCn3HjsysfuyJAjEsK54sY1HbpJlUJtUD7qiyc7VzPgvMdU E+nTWNIKCzbEtGyeAySudHBmNJxiyaaH33jd/T6U2485Q8y9XX53LQPDEJQZk0dv6Lq/0LWgSbE G8H6con49+UlZYhRp+k/wHQt8+bYZ9iYCIzL7CRSipiCHOZbefJ1ZtLPnQGgXmrcM+8JpmI8NrN thYZTQ7MlsIuayDITDU1Vl75NCZCdjr2XjqTfUrAFRMqfg5auIUZEon1YVLI/fSiGsrodxal2Rc zOIZa8I+SciSf8Hx2gl+Lv9d5b0IQy+FvCfzG+CQvDc5Jk9C4QE4/W8aqw9qsEHrt3Af2i4e+Jp GalnnYpqgDuBbYA== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Temporary update the media.h header from Linux kernel using the flags introduced by: https://patchwork.linuxtv.org/project/linux-media/patch/20250724-multicontext-mainline-2025-v2-6-c9b316773486@ideasonboard.com/ Signed-off-by: Jacopo Mondi Reviewed-by: Isaac Scott --- include/linux/videodev2.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h index 317d063a7e2bf5c54b01b8c2328a1857dc2f6fc3..3025db045572a867b1da12b26da703a31d1dd453 100644 --- a/include/linux/videodev2.h +++ b/include/linux/videodev2.h @@ -1011,6 +1011,14 @@ struct v4l2_jpegcompression { * always use APP0 */ }; +/* + * V I D E O D E V I C E C O N T E X T + */ + +struct v4l2_context { + __u32 context_fd; +}; + /* * M E M O R Y - M A P P I N G B U F F E R S */ @@ -2733,6 +2741,8 @@ struct v4l2_remove_buffers { #define VIDIOC_QUERY_EXT_CTRL _IOWR('V', 103, struct v4l2_query_ext_ctrl) #define VIDIOC_REMOVE_BUFS _IOWR('V', 104, struct v4l2_remove_buffers) +/* Context handling */ +#define VIDIOC_BIND_CONTEXT _IOW('V', 105, struct v4l2_context) /* Reminder: when adding new ioctls please add support for them to drivers/media/v4l2-core/v4l2-compat-ioctl32.c as well! */ From patchwork Fri Jul 25 10:33:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 23957 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 421D2C3237 for ; Fri, 25 Jul 2025 10:34:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 17B5C690CA; Fri, 25 Jul 2025 12:34:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="FTwOeef2"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 77F14690A6 for ; Fri, 25 Jul 2025 12:33:58 +0200 (CEST) Received: from [192.168.0.172] (mob-5-90-139-29.net.vodafone.it [5.90.139.29]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A7F48C73; Fri, 25 Jul 2025 12:33:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1753439598; bh=THF0Kw9TXJ7PML3qqZjgbn6VWRx4chsRFzNQGGbndxc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FTwOeef2Ut4UC9+1L8kW+dT+/mlv2ANP2iT8rUpCPBrTjjLuFkEW7/Aq5MpHAjr7Q Y1D7kE40++uPWRwwa2GA/4yOU/1PmcejJgt7mco7JNwA+P+IqHENz9sHYReQls3W2D CL8bP2W+XoTDO5wOwYsRu8xKkkeSlHvN5MqD7JZo= From: Jacopo Mondi Date: Fri, 25 Jul 2025 12:33:48 +0200 Subject: [PATCH 3/9] include: linux: v4l2-subdev: Add SUBDEV_BIND_CONTEXT MIME-Version: 1.0 Message-Id: <20250725-multicontext-v1-3-ea558291e101@ideasonboard.com> References: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> In-Reply-To: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1702; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=THF0Kw9TXJ7PML3qqZjgbn6VWRx4chsRFzNQGGbndxc=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBog12Tj+omHfCPgWR//IcQRAQW58uSQn+pFjzXA oYpgX+EKUWJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaINdkwAKCRByNAaPFqFW PLxvEAC2DpJv30fCkZMOJ/fKL1ibWGzUvVXiWij7Lb9vr6+1iRZbHTlJqGpcGVcMElgABUjvOnP moFQyjksJM5KF3mdarGqZULc0a50sBFoFCiolUxF6iw260ndJR2v7HYtWwM+zO5ObnbpMUUeN7o 8yMh5NOIDdotX3EogpDATCX5yvCPbR+cVEMuba2w1CN4O+mFauhEDS1hwu66+5dRrHIltWU5/O+ ImfLGGRLAdDdsHTAsDeQkcj23Ly91ELlbC1EI0Es4bQtcYFZMqsxrfspPUyxkmsoU3yQHfWc5so MUuEmFRyOF1uT97knAyyLdCV6ti6G8poU5zsyPCNy0i1tjBjdpiF3NDuNgmB/XsrNvSCRayF08k xkueO6QnS41pRi8z5qIPZY+KKXtOCXa21rx/nmw3xEhkC87BiIHpJOrtO/3y3Wy+a7EIQWBg4cI 7Rjg5XGTssJihn+xa7k31sStRoKGNGwP4fwIY6xEwLEQnHKUmYlVsJJSGa6B95Gp2XArXWw8m1R KkcvfL6xT3a8lp6auqaUGOy+YoH9pX2c+k2iMpE65Vitup5kvbLTRt59OGsiguMgYr+yX3Czbht Ni/okIOrBNsAQk4hniuiI5MwX3JORblwMHfinPysQ+V0ug/VJTM4lI2riDuEBywvoN34QhtZryV bW3jyBGJ5c7P7vQ== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Temporary update the media.h header from Linux kernel using the flags introduced by: https://patchwork.linuxtv.org/project/linux-media/patch/20250724-multicontext-mainline-2025-v2-13-c9b316773486@ideasonboard.com/ Signed-off-by: Jacopo Mondi Reviewed-by: Isaac Scott --- include/linux/v4l2-subdev.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/v4l2-subdev.h b/include/linux/v4l2-subdev.h index 839b1329afb259c96551cf76e9186bcb3229554a..9234a4cfc20a866840348224425948f3aa6d5d63 100644 --- a/include/linux/v4l2-subdev.h +++ b/include/linux/v4l2-subdev.h @@ -248,6 +248,16 @@ struct v4l2_subdev_routing { __u32 reserved[11]; }; +/** + * struct v4l2_subdev_bind_context - Subdev context information + * + * @context_fd: The file descriptor of the media_device instance the subdevice + * has to be bound to + */ +struct v4l2_subdev_bind_context { + __u32 context_fd; +}; + /* * The client is aware of streams. Setting this flag enables the use of 'stream' * fields (referring to the stream number) with various ioctls. If this is not @@ -290,6 +300,7 @@ struct v4l2_subdev_client_capability { #define VIDIOC_SUBDEV_S_SELECTION _IOWR('V', 62, struct v4l2_subdev_selection) #define VIDIOC_SUBDEV_G_ROUTING _IOWR('V', 38, struct v4l2_subdev_routing) #define VIDIOC_SUBDEV_S_ROUTING _IOWR('V', 39, struct v4l2_subdev_routing) +#define VIDIOC_SUBDEV_BIND_CONTEXT _IOWR('V', 50, struct v4l2_subdev_bind_context) #define VIDIOC_SUBDEV_G_CLIENT_CAP _IOR('V', 101, struct v4l2_subdev_client_capability) #define VIDIOC_SUBDEV_S_CLIENT_CAP _IOWR('V', 102, struct v4l2_subdev_client_capability) From patchwork Fri Jul 25 10:33:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 23958 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E204BC3237 for ; Fri, 25 Jul 2025 10:34:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2D2CB690CF; Fri, 25 Jul 2025 12:34:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="igWb+iy4"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 10BC9690B3 for ; Fri, 25 Jul 2025 12:33:58 +0200 (CEST) Received: from [192.168.0.172] (mob-5-90-139-29.net.vodafone.it [5.90.139.29]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1743478E; Fri, 25 Jul 2025 12:33:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1753439599; bh=KzSgFu4jAF2dlBOo2vbhWbq+HKvYpf+PUmT/IPXaAZM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=igWb+iy4UQQ53ee5XXfKZcCS3LK8lLu4eulwlMHobfXaoax1nPk4z+/oK44xFf1fi KlXs8Mvpad5c3XKdt68Q174WwVCotuh/2Df8WgxtZYtEmCBTy9F0l4nVFJXXMA8qwf mg6LrRP8ufCLx0zSqQAjJzg1VRC7W+ULsrgs0Fn8= From: Jacopo Mondi Date: Fri, 25 Jul 2025 12:33:49 +0200 Subject: [PATCH 4/9] libcamera: v4l2_videodevice: Add bind context MIME-Version: 1.0 Message-Id: <20250725-multicontext-v1-4-ea558291e101@ideasonboard.com> References: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> In-Reply-To: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2013; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=KzSgFu4jAF2dlBOo2vbhWbq+HKvYpf+PUmT/IPXaAZM=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBog12T735g8B3cRtq4rxFOGDBktRToj/5gc6Pps LqpQpPr8giJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaINdkwAKCRByNAaPFqFW PFBID/0SfxLw1lNvxu7vf3ikmBwBtaVaIleaKigSJ+bEGdWxEFzeEGqx8SqpT4QH6gYcczP+kur af6yZxI/R/7s9nl7oAXFPkUNOyPMSQWryJuUgBDOSBrY8nCNT64jGWf3GaZqAD1N3gxY/zK8p65 uG3D9AemhBzfU0be/LMmnOwG/6fuf8y5FvO5LCH6c0UCW1pqxC5INsFHUTl5laVxYCVa1GK4//2 d/UTHjM/k2jdkFCIz0soPGRDJtEZrtaRrJkkORb2+VX/4SVYBQr9bfwMUqLZ1o1Jw9+5uuHdDqK 91rz46HE04pl2WuJoQ+BeAmZkzyll9qsKhlOMqXzbgTRNAS+rye5lBBQioor5URhAiWG+gZPuz8 5ERAjRVZ76XNAxspxTTGEq96ps9edsvQA3wjcg2Pe+pS/XhfvS5cFyE44QGOKRtS/gfpmMWMws9 jNfuLjGn+xiVQTfIRb7d5HgTySQy5CESKbI9xZ2/etRWmeKTjO+A0T+j1UD8i/imvFj8Bz7DBiL GA365rh+Fv2a0t/6kyWgDVNZN2uRxPWRGWNyquwECJ7WngZ0PdpguT+HZXp7gofdnmc6GV3rker bXZVisVzT3MjuSIn27dsyov7PeHPjyCrIGZI0qXVezMjcDD53V19B+804jET4RG4M1MNnC3ye0y Ic85KIbppzumWxA== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a function to the V4L2VideoDevice class that allows to bind a video device to a media device context using the VIDIOC_BIND_CONTEXT ioctl. Signed-off-by: Jacopo Mondi Reviewed-by: Isaac Scott --- include/libcamera/internal/v4l2_videodevice.h | 2 ++ src/libcamera/v4l2_videodevice.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index ae6a76cb02090ddadf5ad1331a47fd68585cf586..765574b3e0b52b625e927a50045a61f8c2a0ac6e 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -202,6 +202,8 @@ public: const V4L2Capability &caps() const { return caps_; } + int bindContext(unsigned int context); + int getFormat(V4L2DeviceFormat *format); int tryFormat(V4L2DeviceFormat *format); int setFormat(V4L2DeviceFormat *format); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 76bdad40ca8d7a024e4644888737371eff1f09fd..a854f3b10201eaa4f643d0e15fc04b3c49fbeffe 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -795,6 +795,24 @@ std::string V4L2VideoDevice::logPrefix() const (V4L2_TYPE_IS_OUTPUT(bufferType_) ? ":out]" : ":cap]"); } +/** + * \brief Bind a video device to a media device context + * \param[in] context The file descriptor that identifies the media device + * context + * \return 0 on success or a negative error code otherwise + */ +int V4L2VideoDevice::bindContext(unsigned int context) +{ + struct v4l2_context c = {}; + c.context_fd = context; + + int ret = ioctl(VIDIOC_BIND_CONTEXT, &c); + if (ret) + LOG(V4L2, Error) << "Unable to bind context: " << strerror(-ret); + + return ret; +} + /** * \brief Retrieve the image format set on the V4L2 video device * \param[out] format The image format applied on the video device From patchwork Fri Jul 25 10:33:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 23959 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 9BDFDC3323 for ; Fri, 25 Jul 2025 10:34:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B4D5C690D9; Fri, 25 Jul 2025 12:34:08 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="b21ZIVjX"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4D947690B7 for ; Fri, 25 Jul 2025 12:33:59 +0200 (CEST) Received: from [192.168.0.172] (mob-5-90-139-29.net.vodafone.it [5.90.139.29]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 80641C73; Fri, 25 Jul 2025 12:33:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1753439599; bh=7CHQlqJbhPu1j9qyzC4tfgPWW4kyttKI0UNVFyIDEjw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=b21ZIVjX9IPHeCA7+btK2Fn/xweg05D0YtgsWQlHhNHmgcnoUeduDAysMssRmaPmF hBpKAWrlljCnFk21Vt3NF87MADsZOOtPJ0lIhQEjWkfNufp8poJSlG6JGVQwFqbamf +zPamzmmoEC/Go7B9mCAd+qr9CxhY9Rbnyh7wf4Y= From: Jacopo Mondi Date: Fri, 25 Jul 2025 12:33:50 +0200 Subject: [PATCH 5/9] libcamera: v4l2_subdevice: Add bind context MIME-Version: 1.0 Message-Id: <20250725-multicontext-v1-5-ea558291e101@ideasonboard.com> References: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> In-Reply-To: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2076; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=7CHQlqJbhPu1j9qyzC4tfgPWW4kyttKI0UNVFyIDEjw=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBog12UY0LMH8DuPMmnXZVIRpJjzZe48UDHJD/sq 8/V2iK0fuKJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaINdlAAKCRByNAaPFqFW PP/VD/9FxrhdBj7e3wn2YEBcPhxhRT64m/2c8OMR8jeIkwM9L8kVEFuWbJjxnzWjbhQu+uLSZwn dZtGiJY5G9aCfFisKGFBQ2TW54qyIc3ckAbO7fw8kbEBKTHewZy5DBceODn0VRbMINN31osujcb q63fg1x/AxBxOxDpuw+u3kINPNvr7XmQ0zp4JZ/kvigcOOYfZHEQ7H3t1EaxO87L2uKpBdacutZ sTpvX+jjNHttEC+udTf2iqjKTTfIOlKzXBtGDj76c8csBvDpjTI9YDusx8Rq3+gnnUxTYY1bJJX i9yUdXLVcNwKV3IH6tadEAZ5gKDnNST2qIl0P8eu2iBqNdcsIQySFESYgUu2k3q2K8X3DpDFDN4 T0XenLFB/b2hmuaIZSCvAae9prxEgBeb1yli8PASwmgb9dMOXsiH6TloaJVJ+xS1+z2aqFyqmrB APqzNjpBmBSRCLXmmrfo3RavpZs3naaejYQObHFYITfn69zmbbglJnDTpGkipBZEcDM2cbL3UBh ulYxssZJdENW+8X3c3wwKPl3w/OPEQmI3icRF4BmYCVDl9LxYbcyfk7BwgA32EeHzwrWiDsB/PL +N6IJYoa/m8yUhFJIQdfKgwR2pY11SUCT644dXTXC6PkwhF/CHwOd7iAbt0Xcm1L3CmqfiwNB0s n/ILybzsDRwdF6g== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a function to the V4L2Subdevice class that allows to bind a subdevice to a media device context using the VIDIOC_SUBDEV_BIND_CONTEXT ioctl. Signed-off-by: Jacopo Mondi Reviewed-by: Isaac Scott --- include/libcamera/internal/v4l2_subdevice.h | 2 ++ src/libcamera/v4l2_subdevice.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index fa2a4a21eefbb792c69fa6357934d607a009d11a..f65a587c3034df014390863319a350c8fbd4ed5a 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -140,6 +140,8 @@ public: return formats({ pad, 0 }); } + int bindContext(unsigned int context); + int getFormat(const Stream &stream, V4L2SubdeviceFormat *format, Whence whence = ActiveFormat); int getFormat(unsigned int pad, V4L2SubdeviceFormat *format, diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index ce6b0d38cbf1a598e6dc73de8cb36ba245ed73f9..9038783bd2975b6b2063a5d60890e2de82c4aa0d 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -1351,6 +1351,24 @@ std::optional V4L2Subdevice::toColorSpace(const v4l2_mbus_framefmt & return V4L2Device::toColorSpace(format, colourEncoding); } +/** + * \brief Bind a subdevice to a media device context + * \param[in] context The file descriptor that identifies the media device + * context + * \return 0 on success or a negative error code otherwise + */ +int V4L2Subdevice::bindContext(unsigned int context) +{ + struct v4l2_subdev_bind_context c = {}; + c.context_fd = context; + + int ret = ioctl(VIDIOC_SUBDEV_BIND_CONTEXT, &c); + if (ret) + LOG(V4L2, Error) << "Unable to bind context: " << strerror(-ret); + + return ret; +} + /** * \brief Retrieve the image format set on one of the V4L2 subdevice streams * \param[in] stream The stream the format is to be retrieved from From patchwork Fri Jul 25 10:33:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 23960 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id D35ABC3237 for ; Fri, 25 Jul 2025 10:34:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 79AF0690DC; Fri, 25 Jul 2025 12:34:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OkqJBlUT"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B3E14690BC for ; Fri, 25 Jul 2025 12:33:59 +0200 (CEST) Received: from [192.168.0.172] (mob-5-90-139-29.net.vodafone.it [5.90.139.29]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DF72178E; Fri, 25 Jul 2025 12:33:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1753439600; bh=MheqSlSDoWQPQzlMwHnXKCZq6yEzivBzqHP37UxYB2Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OkqJBlUTUoCxcnxqaO+g/AoqKU8GBgg/swmziWgALM1tlaffNLQgHQid8QH/iifgq lm6GJZkpL5x8ZllQ6SXxDvV41R3oZoy9m/sLCoeLFGIkx4tY3iFeimXqoSxI/gUBfv 5WP0++Z0HEiRdmf67IfIMbFOxzcUTUUgibhEo/4k= From: Jacopo Mondi Date: Fri, 25 Jul 2025 12:33:51 +0200 Subject: [PATCH 6/9] libcamera: media-device: Introduce SharedMediaDevice MIME-Version: 1.0 Message-Id: <20250725-multicontext-v1-6-ea558291e101@ideasonboard.com> References: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> In-Reply-To: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=9954; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=MheqSlSDoWQPQzlMwHnXKCZq6yEzivBzqHP37UxYB2Y=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBog12UFPasn238Sp/uOOJcU82+qewXNDgbdEoEX xUbsUBVRFqJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaINdlAAKCRByNAaPFqFW PAG9D/44+42lD1nKTlxPur9EmawIO7/bcUpbKVt4e3FniiVdO1oVr6MI9AN/B2uluazHuHzhYLs 5KQx6QZkwLw6T20qJRHReUnF3TbP8sCNnvBVJ598xalRcSIcYHYSCoom/Mn5ta/vE8csWER3sey fZvu66oqohukfXBXcxLgoImRAZb/nk8MRrJ4h08WFc1tCZPR10RFkNeM/kX+F8PhKLGgiDkPdL8 4iqFB5o7WMoPxNH4TnZkkF8ELCMNliULlBxgkrtKpvub8LDygrioQn4KD9n4aBWYA+Q/cGNbhQf oI2oFM4Wk+xv6k3EsOFGZeLsE4d08RN1OcJblbmyxnW1icAEf5N7/zT5ZwpxFQ5abo/ZTneIjrj A8Ymxrt5cxLVIogWbtaHPrKWp8RvrrjhqXdMzqf87ToPKTyeWeDpYJMqHcfdSpDvYC8uuBYrRai zzu0DvmQC1PZYjO8OZnAPfrRd6yp1EuNhH8/6SMifYgeO+slkO1WvLmMxbnloyWj0PcurAA5D0q oYFYF8+hECCcXCJnVdjzy3hhbtNktkCajEYXabR5HhkshBxlvV9PegkNd+ieN7aKMpWqqCRuUV5 SdRi4GAFqfeJg1x3ccEQ23vQvQ8kqEpEKp3lNMJAzTMeoThN91caz8Qk1xngtPJStM57bNawnER rdZnnkDFxeGyTdw== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Introduce the SharedMediaDevice class derived from the MediaDevice class, that represents a media device that supports multi-context operations. Disallow direct construction of MediaDevice and introduce the MediaDeviceFactory class that instantiate the correct class from the MediaDevice class hierarchy inspecting the newly introduced media_device_info.flags field. The new SharedMediaDevice class represents a media device that can be concurrently accessed by different processes, for this reason overload the acquire/lock operations to be effectively nops. Signed-off-by: Jacopo Mondi Reviewed-by: Isaac Scott --- include/libcamera/internal/media_device.h | 39 +++++++-- src/libcamera/device_enumerator.cpp | 8 +- src/libcamera/media_device.cpp | 139 ++++++++++++++++++++++++++++++ 3 files changed, 178 insertions(+), 8 deletions(-) diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h index b3a48b98d64b019fb42c5224d29105e1d57a3e3c..ea0e9d66009933bbb9613d27423d2f951520c887 100644 --- a/include/libcamera/internal/media_device.h +++ b/include/libcamera/internal/media_device.h @@ -21,18 +21,24 @@ namespace libcamera { +class MediaDeviceFactory +{ +public: + static std::unique_ptr + createMediaDevice(const std::string &deviceNode); +}; + class MediaDevice : protected Loggable { public: - MediaDevice(const std::string &deviceNode); - ~MediaDevice(); + virtual ~MediaDevice(); - bool acquire(); - void release(); - bool busy() const { return acquired_; } + virtual bool acquire(); + virtual void release(); + virtual bool busy() const { return acquired_; } - bool lock(); - void unlock(); + virtual bool lock(); + virtual void unlock(); int populate(); bool isValid() const { return valid_; } @@ -58,9 +64,12 @@ public: std::vector locateEntities(unsigned int function); protected: + MediaDevice(const std::string &deviceNode); std::string logPrefix() const override; private: + friend class MediaDeviceFactory; + int open(); void close(); @@ -92,4 +101,20 @@ private: std::vector entities_; }; +class SharedMediaDevice : public MediaDevice +{ +public: + bool acquire() override; + void release() override; + bool busy() const override { return false; } + + bool lock() override; + void unlock() override; + +private: + friend class MediaDeviceFactory; + + SharedMediaDevice(const std::string &deviceNode); +}; + } /* namespace libcamera */ diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index ae17862f676310ef568e5331106ed661e84b5130..e73bb0050843c5281986e8e05d2013102905d270 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -217,7 +217,13 @@ DeviceEnumerator::~DeviceEnumerator() */ std::unique_ptr DeviceEnumerator::createDevice(const std::string &deviceNode) { - std::unique_ptr media = std::make_unique(deviceNode); + std::unique_ptr media = MediaDeviceFactory::createMediaDevice(deviceNode); + if (!media) { + LOG(DeviceEnumerator, Info) + << "Unable to create a media device for " << deviceNode + << ", skipping"; + return nullptr; + } int ret = media->populate(); if (ret < 0) { diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 353f34a81eca600a4a35594d782d3dc5dd690bdf..70d073f964bde0236585de083baca4cd9c30d193 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -31,6 +31,56 @@ namespace libcamera { LOG_DEFINE_CATEGORY(MediaDevice) +/** + * \class MediaDeviceFactory + * \brief Factory class that instantiates a MediaDevice or SharedMediaDevice + * + * The MediaDevice and SharedMediaDevice classes cannot be instantiated + * directly, but instead the MediaDeviceFactory shall be used to create + * an instance of these classes using the MediaDeviceFactory::createMediaDevice + * function. + */ + +/** + * \brief Create an instance of the MediaDevice class hierarchy + * \param[in] deviceNode The media device node path + * + * If a media device supports multi-context operations and advertise it through + * the presence of the MEDIA_DEVICE_FL_CONTEXT flag in the + * media_device_info.flags field an instance of SharedMediaDevice will be + * created and returned. If instead the media device doesn's support + * multi-context operations an instance of the MediaDevice class is created and + * returned. + * + * \return A unique_ptr<> that wraps an instance of SharedMediaDevice or + * MediaDevice + */ +std::unique_ptr +MediaDeviceFactory::createMediaDevice(const std::string &deviceNode) +{ + /* + * Inspect the media device info flags to decide which class to + * instantiate. + */ + auto fd = UniqueFD(::open(deviceNode.c_str(), O_RDWR | O_CLOEXEC)); + if (!fd.isValid()) + return {}; + + struct media_device_info info = {}; + int ret = ioctl(fd.get(), MEDIA_IOC_DEVICE_INFO, &info); + if (ret) { + LOG(MediaDevice, Error) + << "Failed to get media device info " << strerror(-ret); + return {}; + } + + if (info.flags & MEDIA_DEVICE_FL_CONTEXT) + return std::unique_ptr + (new SharedMediaDevice(deviceNode)); + + return std::unique_ptr(new MediaDevice(deviceNode)); +} + /** * \class MediaDevice * \brief The MediaDevice represents a Media Controller device with its full @@ -40,6 +90,9 @@ LOG_DEFINE_CATEGORY(MediaDevice) * created, and that association is kept for the lifetime of the MediaDevice * instance. * + * Instances of MediaDevice are created by the MediaDeviceFactory + * createMediaDevice() function and cannot be directly instantiated. + * * The instance is created with an empty media graph. Before performing any * other operation, it must be populate by calling populate(). Instances of * MediaEntity, MediaPad and MediaLink are created to model the media graph, @@ -56,6 +109,30 @@ LOG_DEFINE_CATEGORY(MediaDevice) * managers to claim media devices they support during enumeration. */ +/** + * \class SharedMediaDevice + * \brief The SharedMediaDevice represents a Media Controller device that + * supports multi-context operations + * + * \sa MediaDevice + * \sa MediaDeviceFactory + * + * A SharedMediaDevice is associated with a media controller device node that + * supports multi-context operations. Compared to the MediaDevice base class a + * SharedMediaDevice allows multiple open() calls to happen and is never + * uniquely owned as each time the media device gets open a new context gets + * created. This means that the acquire() and release() operations are + * effectively nop (and as a consequence busy() always return false). + * + * Instances of MediaDevice are created by the MediaDeviceFactory + * createMediaDevice() function and cannot be directly instantiated. + * + * Similarly to the MediaDevice class, instances of SharedMediaDevice are + * created with an empty media graph and needs to be populated using the + * populate() function. Media entities enumerated in the graph can be accessed + * through the same functions as the ones provided by the MediaDevice class. + */ + /** * \brief Construct a MediaDevice * \param[in] deviceNode The media device node path @@ -68,6 +145,17 @@ MediaDevice::MediaDevice(const std::string &deviceNode) { } +/** + * \brief Construct a SharedMediaDevice + * \param[in] deviceNode The media device node path + * + * \copydoc MediaDevice::MediaDevice + */ +SharedMediaDevice::SharedMediaDevice(const std::string &deviceNode) + : MediaDevice(deviceNode) +{ +} + MediaDevice::~MediaDevice() { fd_.reset(); @@ -113,6 +201,19 @@ bool MediaDevice::acquire() return true; } +/** + * \brief Acquiring a SharedMediaDevice is a nop + * + * A SharedMediaDevice is designed to be opened multiple times. Acquiring + * a SharedMediaDevice is effectively a nop. + * + * \return Always return true + */ +bool SharedMediaDevice::acquire() +{ + return true; +} + /** * \brief Release a device previously claimed for exclusive use * \sa acquire(), busy() @@ -123,6 +224,15 @@ void MediaDevice::release() acquired_ = false; } +/** + * \brief Releasing a SharedMediaDevice is a nop + * + * As acquiring a SharedMediaDevice is a nop, releasing it is a nop as well. + */ +void SharedMediaDevice::release() +{ +} + /** * \brief Lock the device to prevent it from being used by other instances of * libcamera @@ -151,6 +261,19 @@ bool MediaDevice::lock() return true; } +/** + * \brief Locking a SharedMediaDevice is a nop + * + * As SharedMediaDevice is designed to be opened multiple times locking + * a SharedMediaDevice is effectively a nop. + * + * \return Always return true + */ +bool SharedMediaDevice::lock() +{ + return true; +} + /** * \brief Unlock the device and free it for use for libcamera instances * @@ -168,6 +291,15 @@ void MediaDevice::unlock() std::ignore = lockf(fd_.get(), F_ULOCK, 0); } +/** + * \brief Unlocking a SharedMediaDevice is a nop + * + * As locking a SharedMediaDevice is a nop, unlocking it is a nop as well. + */ +void SharedMediaDevice::unlock() +{ +} + /** * \fn MediaDevice::busy() * \brief Check if a device is in use @@ -176,6 +308,13 @@ void MediaDevice::unlock() * \sa acquire(), release() */ +/** + * \fn SharedMediaDevice::busy() + * \brief As SharedMediaDevice is designed to be opened multiple times, for this + * reason it is never marked as busy + * \return Always returns false + */ + /** * \brief Populate the MediaDevice with device information and media objects * From patchwork Fri Jul 25 10:33:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 23961 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 1738BC3323 for ; Fri, 25 Jul 2025 10:34:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7AAAE690BC; Fri, 25 Jul 2025 12:34:11 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lVHvyY3U"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8CC6F6909F for ; Fri, 25 Jul 2025 12:34:00 +0200 (CEST) Received: from [192.168.0.172] (mob-5-90-139-29.net.vodafone.it [5.90.139.29]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 52054C73; Fri, 25 Jul 2025 12:33:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1753439600; bh=h6fVQQRDCDzLgTYQD7LIce+Sr45tSyEOBhr9buH9vYA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lVHvyY3UpPvD1g4BKix2rto9FLdcYD+vwIx06q0jiq6VcyCE2tu8UMxB3fIsdgMdn 1b9gXAhbD/LIiuCAyBGozWhjWOhM22YcfpYkn3bhe0T/7LMDjrIIoGsOOE/8mbd/i+ z5JYAUGUHtPq/upBGb7Y8tqbJlRkRKBqaLeMPNv8= From: Jacopo Mondi Date: Fri, 25 Jul 2025 12:33:52 +0200 Subject: [PATCH 7/9] libcamera: media-device: Introduce MediaContext MIME-Version: 1.0 Message-Id: <20250725-multicontext-v1-7-ea558291e101@ideasonboard.com> References: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> In-Reply-To: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8005; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=h6fVQQRDCDzLgTYQD7LIce+Sr45tSyEOBhr9buH9vYA=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBog12UvJmBPXTa4+aDCplmm6WscOZgcTD3zCvnh XEJJZ8XRBiJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaINdlAAKCRByNAaPFqFW PES0D/wP9pW8NmeR9R1mTbxSwTOgZDgsmBG44X23brpOuRz3GKduV2AA+Yr29aPG2x7OmrKmGEL m7PkeqyJaMhvn8Wp/J8neJh9YrwPhZJ8540XBWRBma7KnsfSPOMLXOrQMfv2rOIWCPmyt1kwa26 vVuBUXtUarMfHx/Pe68SetXEDLF90bj+VoCdQ8qPq8/K5N/yyfm4tfMo7Fc8nuxTPOwwKJNwgpF qVmc9c4DXsYCZA4VjcmEH2XQkthD0GOdvGZnsbpxqU+rexKr4A0Xo4X7SN9w7NOJf0o9DoMQ40k nA29b2ccCkB/mFaGZ52OUWZtRfkt7m/BVtTAUHvhEfEgELFRZ6YdMJhTbP+ZgJiJbthCEX1bXxn TXqfrdcKLxfPbrEQZsMY/Go2AL7WJ2VB6lt65Mw4QcMRGtLEXt4JxIhwOce6R94pYmCrI54r8Gn uD3VEzTzZ4zXPtBH/SzExJylc7lexO/CYlkn/XfR93Bb2tUfUt+1mGzhLSmpBJ5Nvk7Ix+hxRxn r8gsII4gl4aXCyR7gDelSknoVmFkx67zR0p7QuLXcgq+XoF9ZH7nmvhmsl6BuNDTJOGVd+VNg+V 9hEl2dJOFWWXiuQqj9kH3rEc/sEooF/8uh9w8a0tbOItPCw63tm1MMvSRj256z8pNKbwZV0BIuL GG+AQKkssHCLKrg== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Introduce the MediaContext class that represents a media device context to which video devices and subdevices can be bound to. A MediaContext can be created from a MediaDevice (which does not support multi-context) and from SharedMediaDevice (which supports multi-context). Binding devices to a MediaContext created from MediaDevice is a nop, while MediaContext created from SharedMediaDevice perform proper bindings. Signed-off-by: Jacopo Mondi Reviewed-by: Isaac Scott --- include/libcamera/internal/media_device.h | 23 ++++- src/libcamera/media_device.cpp | 135 ++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h index ea0e9d66009933bbb9613d27423d2f951520c887..2dbfcc447d84bb6a1eee4ed598d22b5cc45adbe9 100644 --- a/include/libcamera/internal/media_device.h +++ b/include/libcamera/internal/media_device.h @@ -21,6 +21,9 @@ namespace libcamera { +class V4L2VideoDevice; +class V4L2Subdevice; + class MediaDeviceFactory { public: @@ -28,6 +31,19 @@ public: createMediaDevice(const std::string &deviceNode); }; +class MediaContext +{ +public: + MediaContext(); + MediaContext(UniqueFD &&fd); + + int bindDevice(V4L2VideoDevice *dev); + int bindDevice(V4L2Subdevice *dev); + +private: + UniqueFD fd_; +}; + class MediaDevice : protected Loggable { public: @@ -63,10 +79,14 @@ public: std::vector locateEntities(unsigned int function); + virtual std::unique_ptr createContext(); + protected: MediaDevice(const std::string &deviceNode); std::string logPrefix() const override; + std::string deviceNode_; + private: friend class MediaDeviceFactory; @@ -88,7 +108,6 @@ private: int setupLink(const MediaLink *link, unsigned int flags); std::string driver_; - std::string deviceNode_; std::string model_; unsigned int version_; unsigned int hwRevision_; @@ -111,6 +130,8 @@ public: bool lock() override; void unlock() override; + std::unique_ptr createContext() override; + private: friend class MediaDeviceFactory; diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 70d073f964bde0236585de083baca4cd9c30d193..2b7df346ad9916cf22641ea770e0a1507921d89d 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -21,6 +21,9 @@ #include +#include "libcamera/internal/v4l2_subdevice.h" +#include "libcamera/internal/v4l2_videodevice.h" + /** * \file media_device.h * \brief Provide a representation of a Linux kernel Media Controller device @@ -81,6 +84,99 @@ MediaDeviceFactory::createMediaDevice(const std::string &deviceNode) return std::unique_ptr(new MediaDevice(deviceNode)); } +/** + * \class MediaContext + * \brief Represents a media device context + * + * A media device context is obtained from a MediaDevice or a SharedMediaDevice + * instance with the MediaDevice::createContext() and + * SharedMediaDevice::createContext() functions. + * + * MediaContext instances obtained from a MediaDevice that does not support + * multi-context operations will not have a valid file descriptor associated as + * the media device they are created from doesn't support multiple open. For + * this reason binding a device to a context that is obtained from a MediaDevice + * is a nop. + * + * MediaContext instances obtained from a SharedMediaDevice that supports + * multi-context operations owns the file descriptor that identifies the media + * context, obtained by opening the media device multiple times and provided to + * the context at creation time. Binding devices to a context obtained from a + * SharedMediaDevice associates the devices to an execution context which + * remains valid until the last bound device stays valid. + * + * Users of this class can bind devices on valid and invalid MultiContext + * instances alike. If the kernel driver supports multi-context operations + * then the device can be opened multiple times and multiple contexts can be + * created to which devices can be bound to. If the kernel driver doesn't + * support multi-context operations then it can be opened a single time only + * and a creating contexts and bindings devices to it is effectively a nop. + */ + +/** + * \brief Constructs a MediaContext not associated to any media device context + * + * Constructs a media device context not associated to any valid media device + * context file descriptor. Binding devices to such media device context + * is effectively a nop. + */ +MediaContext::MediaContext() +{ +} + +/** + * \brief Construct a MediaContext associated to a valid media device context + * \param[in] fd The file descriptor that identifies a media device context + * + * Construct a media device context to which devices can be bound to. + * + * Constructing a MediaContext with an associated valid media device context + * allows to create isolated execution contexts by binding devices to it. + * + * The file descriptor \a fd obtained by opening the media device and that + * identifies the media device context is moved in the newly constructed + * MediaContext which maintains its ownership and automatically closes it at + * destruction time. + */ +MediaContext::MediaContext(UniqueFD &&fd) + : fd_(std::move(fd)) +{ +} + +/** + * \brief Bind a V4L2 video device to a media device context + * \param[in] dev The video device to bind + * + * If the MediaContext has been created by a MediaDevice that does not + * support multi-context operations, this function is effectively a nop. + * + * \return 0 on success or a negative error code otherwise + */ +int MediaContext::bindDevice(V4L2VideoDevice *dev) +{ + if (fd_.get() == -1) + return 0; + + return dev->bindContext(fd_.get()); +} + +/** + * \brief Bind a V4L2 subdevice to a media device context + * \param[in] dev The subdevice to bind + * + * If the MediaContext has been created by a MediaDevice that does not + * support multi-context operations, this function is effectively a nop. + * + * \return 0 on success or a negative error code otherwise + */ +int MediaContext::bindDevice(V4L2Subdevice *dev) +{ + if (fd_.get() == -1) + return 0; + + return dev->bindContext(fd_.get()); +} + /** * \class MediaDevice * \brief The MediaDevice represents a Media Controller device with its full @@ -603,6 +699,45 @@ int MediaDevice::disableLinks() * driver unloading for most devices. The media device is passed as a parameter. */ +/** + * \brief Create a MediaContext not associated with a media device context + * \return A MediaContext to which bindings devices is a nop + */ +std::unique_ptr MediaDevice::createContext() +{ + return std::make_unique(); +} + +/** + * \brief Create a MediaContext associated with a media device context + * + * Create a MediaContext by opening the media device and create a media + * device context using the obtained file descriptor. + * + * The open file descriptor is moved to the MediaContext whose ownership is + * moved to the caller of this function. + * + * \return A MediaContext to which is possible to bind devices to + */ +std::unique_ptr SharedMediaDevice::createContext() +{ + auto fd = UniqueFD(::open(deviceNode_.c_str(), O_RDWR | O_CLOEXEC)); + if (!fd.isValid()) { + int ret = -errno; + LOG(MediaDevice, Error) + << "Failed to open media device at " + << deviceNode_ << ": " << strerror(-ret); + return {}; + } + + return std::make_unique(std::move(fd)); +} + +/** + * \var MediaDevice::deviceNode_ + * \brief The media device device node path + */ + /** * \brief Open the media device * From patchwork Fri Jul 25 10:33:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 23962 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 380C5C332A for ; Fri, 25 Jul 2025 10:34:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 95C7C690D4; Fri, 25 Jul 2025 12:34:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="pkr+jGc+"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BDE79690C1 for ; Fri, 25 Jul 2025 12:34:00 +0200 (CEST) Received: from [192.168.0.172] (mob-5-90-139-29.net.vodafone.it [5.90.139.29]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C198AE9B; Fri, 25 Jul 2025 12:33:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1753439601; bh=cvrNmyHuY4zMvLFKpyeMUlm71YVcNgYowpc8no0CGeo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pkr+jGc+LP4yVpAoCjmrcYssGRB3HcNKBnCdBlLsBjPVlO5/LX4lfiO8ItEaGlTml ydPoIRvV5nJDrbDbg/UHmMxau8m/T4GxEXztFORanvL8V6LblbIjkNVmRgol63RoWk neUEqHrC+v6M/cZjpp3DG3rAUqHb8uDWoSY8nV6o= From: Jacopo Mondi Date: Fri, 25 Jul 2025 12:33:53 +0200 Subject: [PATCH DNI 8/9] libcamera: rpi/pisp: Bind devices in a context MIME-Version: 1.0 Message-Id: <20250725-multicontext-v1-8-ea558291e101@ideasonboard.com> References: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> In-Reply-To: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2537; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=cvrNmyHuY4zMvLFKpyeMUlm71YVcNgYowpc8no0CGeo=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBog12UhuJ9z9YjRKe8uEfLSClxp9sDWlloXEQ15 dWm3sS1OgKJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaINdlAAKCRByNAaPFqFW PPkTD/9aYroHvwT8Ae25nmgtzdkNjkc5/VqshBEYV1ecygcAYbMEtwqywepBH3aV8FVhgRo+/1p mEdSObaQiw3TraoCmmQ6uWUSxfleo0oanyZ1+IDc8Qpb8GACuY/zLfbkNpzTiGWd786sAyfRgo/ zad/BScmZiYvMwkumYcz+QeELSJgbSfjPwcGJ/VUBS6A3NnQ0tUFqUE9L+jOGExMwYTfOujT6nU e+H+rbWEVfPdUjd8XyoYyc69SekjTEJL0K9H/ofPoCvnxDskAxqsFMI7bE2CbjZNfQaDB0feXN3 HuUl4jmsLkJLiSAOmGN7CT48ZMOuyovjXH+nBtsG8sUmZbbgIO2MVdz4a86oFdXQoJnNZk8QxGV s/3KH02w495CIkLu7uh+Xa+VVJCHY3gT+p3zMBAi1BfWlETw6Rq3aPQ3ESCs6Vv348lI0Dsroqn 8RvxBoPY+XLsIgW80OVHOhYAPJSwG0jj98nlPZONTyC2tIlJEke6CLFlgoMK/1RLMSPNTpb2Ptl lY7URZQu/TzD2bAjnJXyt0HNZMyTOQb/+sL0bpFrasZapTJ0iUsCJisYoa3bHfprqYsxwAJD2fK 7tdjMKDkDV/d4MACfCMyOagKPJFqS0104H+a9wkLJXsvGQxoTOGxaygA2bZUYl4BI3VdjHWFaIM TVV/tRFjQ7yU/rA== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Create a MediaContext for each detected camera sensor and bind the ISP video devices to it. This allows multi-camera operations with a single, multiplexed, ISP device. Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/rpi/pisp/pisp.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/libcamera/pipeline/rpi/pisp/pisp.cpp b/src/libcamera/pipeline/rpi/pisp/pisp.cpp index 15dd950682eeff9dc1a9b4ae2f927da85c0eaac6..49a97415c67f0c7c36b3c0b8bd597c278af16838 100644 --- a/src/libcamera/pipeline/rpi/pisp/pisp.cpp +++ b/src/libcamera/pipeline/rpi/pisp/pisp.cpp @@ -740,6 +740,16 @@ public: return cfe_[Cfe::Output0].dev(); } + int bindDevice(V4L2VideoDevice *dev) + { + return mediaContext_->bindDevice(dev); + } + + int bindDevice(V4L2Subdevice *dev) + { + return mediaContext_->bindDevice(dev); + } + CameraConfiguration::Status platformValidate(RPi::RPiCameraConfiguration *rpiConfig) const override; @@ -776,6 +786,8 @@ public: unsigned int tdnInputIndex_; unsigned int stitchInputIndex_; + std::unique_ptr mediaContext_; + struct Config { /* * Number of CFE config and stats buffers to allocate and use. A @@ -935,6 +947,7 @@ bool PipelineHandlerPiSP::match(DeviceEnumerator *enumerator) ("pisp_frontend", true, pisp->pispVariant_); pisp->be_ = SharedMemObject ("pisp_backend", BackEnd::Config({}), pisp->pispVariant_); + pisp->mediaContext_ = ispDevice->createContext(); if (!pisp->fe_.fd().isValid() || !pisp->be_.fd().isValid()) { LOG(RPI, Error) << "Failed to create ISP shared objects"; @@ -1155,6 +1168,16 @@ int PipelineHandlerPiSP::platformRegister(std::unique_ptr &came return ret; } + /* Bind devices to the media device. */ + data->bindDevice(data->isp_[Isp::Input].dev()); + data->bindDevice(data->isp_[Isp::Output0].dev()); + data->bindDevice(data->isp_[Isp::Output1].dev()); + data->bindDevice(data->isp_[Isp::Config].dev()); + data->bindDevice(data->isp_[Isp::TdnInput].dev()); + data->bindDevice(data->isp_[Isp::TdnOutput].dev()); + data->bindDevice(data->isp_[Isp::StitchInput].dev()); + data->bindDevice(data->isp_[Isp::StitchOutput].dev()); + /* Write up all the IPA connections. */ data->ipa_->prepareIspComplete.connect(data, &PiSPCameraData::prepareIspComplete); data->ipa_->processStatsComplete.connect(data, &PiSPCameraData::processStatsComplete); From patchwork Fri Jul 25 10:33:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 23963 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0FC66C3237 for ; Fri, 25 Jul 2025 10:34:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 34396690E0; Fri, 25 Jul 2025 12:34:15 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Exg3aeMp"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 03BBF690C5 for ; Fri, 25 Jul 2025 12:34:01 +0200 (CEST) Received: from [192.168.0.172] (mob-5-90-139-29.net.vodafone.it [5.90.139.29]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2F9B4EFE; Fri, 25 Jul 2025 12:33:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1753439601; bh=Q6wYIQe29ouJXmG8lgb1hJm9s1RxN6DJrcd0SCbO3Uc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Exg3aeMp/9vitan42hCMrUk9Qc8nVh/VaRPbnGw6XjHy26EdvkKFcPMEMiKMbeStc 6lo0Px8cgU+bdakvvEbxBKHNhgs6Khxg1BrNkHTV4/jS7fOrPv+IZ95R6CaZ7H0UmU 28V1Z5OPB4hnNv/T4PkaX+aQ1V1OF5rQYaiLM8HU= From: Jacopo Mondi Date: Fri, 25 Jul 2025 12:33:54 +0200 Subject: [PATCH DNI 9/9] : rpi/pisp: Set format and bind ISP subdev MIME-Version: 1.0 Message-Id: <20250725-multicontext-v1-9-ea558291e101@ideasonboard.com> References: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> In-Reply-To: <20250725-multicontext-v1-0-ea558291e101@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4124; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=Q6wYIQe29ouJXmG8lgb1hJm9s1RxN6DJrcd0SCbO3Uc=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBog12UXwJsF/KeG8Soae8cZ181GrwtSG8RkA/3x sRTKerlwBaJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaINdlAAKCRByNAaPFqFW PCFdD/48df13uHSXgoSjPY6vTtZrTHTSrO8/L6q4rAqO4agTIoqvjXyJAp5UGYybB3C2DSw+KAM /slhPrRHy0eAYPtywm+HwIURKlLwU/qdaxXoDSpve7CtvAQFBey/z9OhrUdBqCoPGunZgWiGXla vYhA1pcgMeMAk9mFqH8C/atCbjM6xQeDjj+rh83UVWBo/rZmmk/KISdaa2+IoQxFj7OQFGWyuOf p+kviEhnHDBpJduN7JLNyIWsnznrWfp3sT97tZd6sAkSEXvvW9Z/QHrczIEb0Ory5ns9EDG/Okt ALM8cBb7EailDU19L/3p71ZeCJumkzCCAooFVVPVX5VIg7tbZMmlW0nRI+qZ/VWqj8BzbZPp7lu OH2hSZWQzMvCUpF5jlBf6q8nQ5eybcEY7DydgYdJJhqle/Slr3WaI9GiTxXnEs90nM05oRUbxDW fK6TXwuQdnSvo3toGKIPlU3T9icU7bSMwq42PATnyMQj8GzNl6hssBLud5jPyt3t4Mzw3+WJ+Ym /4TROXUlCy8TmWlLSP5F9eGWiTXEM+Ju9RRMLWP7uF4kFqFIykcUvgvTLE44j83+TWOkEMpA93o v4NwjsvYMlvfiG5ZiL53l38A9gPw6qDe9PI/1fY9TF3ed8slmsxbaVZtbhsgEb93ENrsniBnBYE DYJF61RapDQMK5Q== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The in-review patch series that introduces multi-context support in the Linux kernel also modifies the RaspberryPi BE driver to expose the ISP subdevice to userspace. In order to have this libcamera series tested with the kernel series, set format on the ISP subdev to pass link validation and also bind the ISP subdev to the media device context. Signed-off-by: Jacopo Mondi --- src/libcamera/pipeline/rpi/pisp/pisp.cpp | 49 +++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/rpi/pisp/pisp.cpp b/src/libcamera/pipeline/rpi/pisp/pisp.cpp index 49a97415c67f0c7c36b3c0b8bd597c278af16838..ea693da42e66cd4a2ea1770856fe3c4aa8f7d396 100644 --- a/src/libcamera/pipeline/rpi/pisp/pisp.cpp +++ b/src/libcamera/pipeline/rpi/pisp/pisp.cpp @@ -780,6 +780,7 @@ public: std::unique_ptr csi2Subdev_; std::unique_ptr feSubdev_; + std::unique_ptr ispSubdev_; std::vector tdnBuffers_; std::vector stitchBuffers_; @@ -1136,8 +1137,14 @@ int PipelineHandlerPiSP::platformRegister(std::unique_ptr &came data->csi2Subdev_ = std::make_unique(cfe->getEntityByName("csi2")); data->feSubdev_ = std::make_unique(cfe->getEntityByName("pisp-fe")); + data->ispSubdev_ = std::make_unique(isp->getEntityByName("pispbe")); data->csi2Subdev_->open(); data->feSubdev_->open(); + if (data->ispSubdev_->open()) { + /* Depends on an out-of-tree patch. */ + LOG(RPI, Error) << "Make sure to have V4L2_SUBDEV_FL_HAS_DEVNODE in the pispbe driver"; + return -EINVAL; + } /* * Open all CFE and ISP streams. The exception is the embedded data @@ -1177,6 +1184,7 @@ int PipelineHandlerPiSP::platformRegister(std::unique_ptr &came data->bindDevice(data->isp_[Isp::TdnOutput].dev()); data->bindDevice(data->isp_[Isp::StitchInput].dev()); data->bindDevice(data->isp_[Isp::StitchOutput].dev()); + data->bindDevice(data->ispSubdev_.get()); /* Write up all the IPA connections. */ data->ipa_->prepareIspComplete.connect(data, &PiSPCameraData::prepareIspComplete); @@ -2188,6 +2196,10 @@ int PiSPCameraData::configureEntities(V4L2SubdeviceFormat sensorFormat, constexpr unsigned int feVideo1SourcePad = 3; constexpr unsigned int feStatsSourcePad = 4; + constexpr unsigned int ispInputPad = 0; + constexpr unsigned int ispOutput0Pad = 3; + constexpr unsigned int ispOutput1Pad = 4; + const MediaEntity *csi2 = csi2Subdev_->entity(); const MediaEntity *fe = feSubdev_->entity(); @@ -2253,8 +2265,43 @@ int PiSPCameraData::configureEntities(V4L2SubdeviceFormat sensorFormat, feFormat.code = bayerToMbusCode(feOutputBayer); ret = feSubdev_->setFormat(feVideo0SourcePad, &feFormat); + if (ret) + return ret; - return ret; + /* Apply format on the ISP subdev pad #0 (matches the input image size). */ + V4L2DeviceFormat ispVdevFormat; + isp_[Isp::Input].dev()->getFormat(&ispVdevFormat); + + V4L2SubdeviceFormat ispSubdevFormat; + ispSubdevFormat.code = MEDIA_BUS_FMT_FIXED; + ispSubdevFormat.size = ispVdevFormat.size; + ret = ispSubdev_->setFormat(ispInputPad, &ispSubdevFormat); + if (ret) + return ret; + + /* Apply format on the ISP subdev pads connected to active inputs. */ + pisp_be_global_config global; + be_->GetGlobal(global); + unsigned int beEnabled = global.rgb_enables; + + if (beEnabled & PISP_BE_RGB_ENABLE_OUTPUT0) { + isp_[Isp::Output0].dev()->getFormat(&ispVdevFormat); + + ispSubdevFormat.size = ispVdevFormat.size; + ret = ispSubdev_->setFormat(ispOutput0Pad, &ispSubdevFormat); + if (ret) + return ret; + } + if (beEnabled & PISP_BE_RGB_ENABLE_OUTPUT1) { + isp_[Isp::Output1].dev()->getFormat(&ispVdevFormat); + + ispSubdevFormat.size = ispVdevFormat.size; + ret = ispSubdev_->setFormat(ispOutput1Pad, &ispSubdevFormat); + if (ret) + return ret; + } + + return 0; } void PiSPCameraData::prepareCfe()