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