From patchwork Wed Apr 8 11:56:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 26508 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 65A80C32BB for ; Wed, 8 Apr 2026 11:56:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1E96162E05; Wed, 8 Apr 2026 13:56:38 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.b="WxvRR6oD"; dkim=pass (2048-bit key; unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="Xd/U8/TS"; dkim-atps=neutral Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6FCC862DDA for ; Wed, 8 Apr 2026 13:56:36 +0200 (CEST) Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 63878Ekp2450585 for ; Wed, 8 Apr 2026 11:56:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=W+1iJkfEjBH FzIiPGPwUKqcpbF9+SIRH8ysjR3FBK3g=; b=WxvRR6oDoeq3Ey28NQvcact+D1b CyoqmADJ9QegACZ0ewdOOiF6XW0Erw0LLOpmB+JBGmC4xJ1dvOMIFFDTPbXDthQg T+FFCPcwR5f36vbEJ9lgpEFIM0sXWzi59g84Dt/CfnxnrIcF3kssYW8KhBuLan/g Z+U3y2GG1C7KNwj7VRXkjJS613y64PIopka+Gs3X/LgGhcXTu702P+wUgwxXXl0A GdsikM2MlWpnM6veXLsIptmUSyI4O9e5C2Kb4LM5RTgKis7w4umfkFrBVaKCbPOY 8S3kXj3e9uaNctyDZD29EVm4Xpvr7OlzGm22vsEpI/KewhhHAB8F/7+04Cw== Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ddae6amnf-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 08 Apr 2026 11:56:35 +0000 (GMT) Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-50b3544bc7bso84700881cf.2 for ; Wed, 08 Apr 2026 04:56:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1775649394; x=1776254194; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W+1iJkfEjBHFzIiPGPwUKqcpbF9+SIRH8ysjR3FBK3g=; b=Xd/U8/TSegsCPiQ6zB80ojufL9tVi6FoGukDoS3RzqPIiWGV3DmOmjqM7zsLOyMGiO 0wRZc+cSdDeYLDkhFQooZ1SAnEbH5lWSwT5EdaCkcyd6eN3ih8G3xBLaOytgNI/BwuqY Go+2VVWZpX6N4q/idEfFSjQ4fOm1Xm0/XfrPfLrDfIqKurYGV8LbuvL+xKy4/p2xBqgS CxHsYfD/2bhvUh3oRFy9Skqte9R7RbefZjTcdxq8mgrkkYJnYA+cZP7sX6BO9Pwwc+4v UgEogixfRvTl5ZMYH9nsJpExq7dil7/WKCtfFbI4AES5TWIHTfZ5Khb+x/7fSmi/Jzn4 gzjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775649394; x=1776254194; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=W+1iJkfEjBHFzIiPGPwUKqcpbF9+SIRH8ysjR3FBK3g=; b=gFl5OBtDkfmaBw8RiHYxpx8MUpdA/GRasI6L5vdj3c2yJJvLtmuelCvV7pLMEw0RCl zhdJCjCOxpFzv49P2QnDY8RVRfJUmOc4Av8GwC1iqGQv+PiQeWOujO6BOyCRToj3RNDr JnheFTeWlQQb0WGy27v6YBUWiGHUQKPMGI8KR6iUJGQlYHGLFa2rkQuev6YA+QDeS/Zh 5i4WFwX4uv+b+Z4n7dYBuVGEo+hOgUVbp1skBD6pHUwrlbvJ9lXeG1wVZmw9hlw9+hAO 7yphl1wA9QatobDtxlCSyKZYTIbweofAU3x0fPIHk5WghvFMIexYbI8poE8VU2TODqmO OgPw== X-Gm-Message-State: AOJu0YwLxXqSMW+2Tfv39tgIF1S5P1YpOR1cTy2tTAXcMW5PHHHkDvfz 7OKUVcmsy1hu0i2hxAdkuI9mVo0wvf6Kau8qe5XV86XcNhxHLOp9UenJ5KgYyxPd1n3JHs7aG30 XDk2DBL4W4CCnpVjrcUGUF1pPK7P3MIsu6MVsddIP9i03ZMk8xpIv9Yfbx8QgosOMVtu2WGbMPt I54qKWVtHi X-Gm-Gg: AeBDieu7p9DSiMdMxux6248m0uOi/vv5QC2zMIW7jFpUkNz3oiUURdrThiwDX8ZD+jJ vb1ACkGNQUd7h4FQgQR5snsQfzfBOYYTxIU5x7U6fDio+3Y8o1tbT7Mp0UeroyBz4NS1wPhiZSg IaIABFYkrvqFR9RSnyKix2UHmAJAem1WxZ1m9ocdvaaMCetABf+tWBCeRVvZuJsCOUciBaKAgOP 1y+VQi4Pdtb29GSN0CPpNBl/A+4HygM+VuDe/a8tD0SzC8HkRYuIO5OFmc92mjG9mqvsrGR85vA GVs8/yJKrCjD90Y9kP55ykXOM74m4LG5dCl2P1lPHoXyIkQqgCtKAxCkgiEdK8VF+Rs5sxsBS7q m7Gip4rHxdcdyKjv/YDqRIznc3qXeJ2IStdqFevFPWKcLFE6McvH+FjbSA9CcZEBqwlGotV4Haz WwClPqVxcSLJTCmjw5Ms2ctzYIT5DIb+eN X-Received: by 2002:ac8:7d0e:0:b0:50d:6d66:7267 with SMTP id d75a77b69052e-50d6d66736dmr280029371cf.7.1775649394224; Wed, 08 Apr 2026 04:56:34 -0700 (PDT) X-Received: by 2002:ac8:7d0e:0:b0:50d:6d66:7267 with SMTP id d75a77b69052e-50d6d66736dmr280029031cf.7.1775649393749; Wed, 08 Apr 2026 04:56:33 -0700 (PDT) Received: from t14s (2001-1c00-0c32-7800-07d4-cca3-ec08-7ac7.cable.dynamic.v6.ziggo.nl. [2001:1c00:c32:7800:7d4:cca3:ec08:7ac7]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b9c3c97219dsm632410766b.5.2026.04.08.04.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 04:56:32 -0700 (PDT) From: Hans de Goede To: libcamera-devel@lists.libcamera.org Cc: Loic Poulain , Hans de Goede Subject: [PATCH 1/3] libcamera: pipeline: Allow pipeline-handlers to opt out of locking the media devices Date: Wed, 8 Apr 2026 13:56:28 +0200 Message-ID: <20260408115630.12456-2-johannes.goede@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408115630.12456-1-johannes.goede@oss.qualcomm.com> References: <20260408115630.12456-1-johannes.goede@oss.qualcomm.com> MIME-Version: 1.0 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDA4MDExMCBTYWx0ZWRfX41gSiPp+R0/L 3qgSbDgelKyu45KZyCPYYsOv/VXEvfvB8o5lpxkDG0tfOXk+DucITfngf5Fz5uJqdIC0VFC4AYP D4h0CYCzBjOvDFYwXDEr2AMq2K0lOB3CTZZ6KVX3LfNfo16UtEmp2eYnwGvq8L5I3vO7aLgEkFa ob6UjlIQIAmzM2rkiRTY2Lig2qBLT1cTbSYoCaHOeuRwaOVC7hvo5KXZD6Fs0Oo9t17lpxGzBzW ydaXyh3+Xbq9Ue54uAgpQ10bwr00dHZjkJOw1MJI2NJN9ZVv5mkY4BaxS8o6KCgKkuTS6x7mcsT P0yzx2m+DRXrD7J4qI4EzYKsBaGHir+Y8QpMGqMoy6J6DM45MT/RvbA3zhN95oxysJaE5Ir1vbK uKpjZ6tcr7vFnVcn0JAZSdugp3enVsi/p8VGzQbZcpBgCJmBwDdReZwQuP56IxXsnFcD2Mw0kLM Ppx1hnsSAlsVtdodjSg== X-Proofpoint-GUID: NU7Ad-WpkZm6xNpN9WaLb2rZFyzKkZTI X-Proofpoint-ORIG-GUID: NU7Ad-WpkZm6xNpN9WaLb2rZFyzKkZTI X-Authority-Analysis: v=2.4 cv=K4AS2SWI c=1 sm=1 tr=0 ts=69d64273 cx=c_pps a=JbAStetqSzwMeJznSMzCyw==:117 a=5kIPp5jG11CJu4rz:21 a=xqWC_Br6kY4A:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=EUspDBNiAAAA:8 a=3LanLXOAZEJocNd9WM4A:9 a=uxP6HrT_eTzRwkO_Te1X:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293, Aquarius:18.0.1143, Hydra:6.1.51, FMLib:17.12.100.49 definitions=2026-04-08_03,2026-04-08_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 clxscore=1015 phishscore=0 malwarescore=0 spamscore=0 bulkscore=0 adultscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604010000 definitions=main-2604080110 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" On Qualcomm chips any CSI-phy can be connected to any CSI-decoder and any CSI-decoder can be connected to any Video-Front-End (VFE, DMA write engine and co). Basically there are 2 big cross-switches between PHYs and decoders and between decoders and VFEs which can be controlled through media-controller links. As such the entite CAMSS block with CSI-phys, decoders and VFEs is represented to userspace as a single /dev/media# node. As long as active links from unrelated cameras are not touched when setting up a new camera 2 independent raw data-streams can be run and managed by 2 different libcamera instances. But the standard locking of the /dev/media# node by the first libcamera instance to start streaming from one of the camera blocks this. Add a new lockOnAcquire_ class member which defaults to true and allow pipeline-handlers to opt out of the /dev/media# locking by setting this to false. Note pipeline-handlers which opt-out will need to implement their own alternative locking from acquireDevice(). This could be done for example by using lockf() on the phy, decoder and VFE v4l2-subdevs used by the camera being acquired. Signed-off-by: Hans de Goede --- include/libcamera/internal/pipeline_handler.h | 2 ++ src/libcamera/pipeline_handler.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index b4f97477a..1c88d2e99 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -70,6 +70,7 @@ public: CameraManager *cameraManager() const { return manager_; } + protected: void registerCamera(std::shared_ptr camera); void hotplugMediaDevice(std::shared_ptr media); @@ -83,6 +84,7 @@ protected: CameraManager *manager_; const unsigned int maxQueuedRequestsDevice_; + bool lockOnAcquire_; private: void unlockMediaDevices(); diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 5c469e5ba..34bfda4af 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -72,7 +72,7 @@ LOG_DEFINE_CATEGORY(Pipeline) PipelineHandler::PipelineHandler(CameraManager *manager, unsigned int maxQueuedRequestsDevice) : manager_(manager), maxQueuedRequestsDevice_(maxQueuedRequestsDevice), - useCount_(0) + lockOnAcquire_(true), useCount_(0) { } @@ -170,7 +170,7 @@ PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator, */ bool PipelineHandler::acquire(Camera *camera) { - if (useCount_ == 0) { + if (useCount_ == 0 && lockOnAcquire_) { for (std::shared_ptr &media : mediaDevices_) { if (!media->lock()) { unlockMediaDevices(); @@ -180,7 +180,7 @@ bool PipelineHandler::acquire(Camera *camera) } if (!acquireDevice(camera)) { - if (useCount_ == 0) + if (useCount_ == 0 && lockOnAcquire_) unlockMediaDevices(); return false; @@ -212,7 +212,7 @@ void PipelineHandler::release(Camera *camera) releaseDevice(camera); - if (useCount_ == 1) + if (useCount_ == 1 && lockOnAcquire_) unlockMediaDevices(); --useCount_; From patchwork Wed Apr 8 11:56:29 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 26509 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 EBB63BDCBD for ; Wed, 8 Apr 2026 11:56:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AD32662E11; Wed, 8 Apr 2026 13:56:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.b="ga+odE8H"; dkim=pass (2048-bit key; unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="Uo+VBgsG"; dkim-atps=neutral Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C4E4C62E0D for ; Wed, 8 Apr 2026 13:56:38 +0200 (CEST) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 638Aii0r249550 for ; Wed, 8 Apr 2026 11:56:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=VGDyW/FEB0G bROb7MhWm4EA0EZyx0U/3giZ87KYrgO0=; b=ga+odE8HhiDFgCXdFfPtfhTgDXL 4bKPYKqQ+FYv2ZvkxME0vL270/J2uhqt3Wuh4lDj3BORXB3ZbcTcpGfDtSqu7ubm 4ZJYQQ1yrPKBx8EHoSF7bjNfRNtMoQX/Iddo4GkYzm+VY/Hk8ZtfzOzIhFNvEblq dDfwcN8BAZGXiPVqlCav8oGEi5S04zv+Fm4MxIGU0Y1P6ykZoPo+krAu/JaHuXJt Hn+S2XFNw7ag+ccI/qDTtnPYZWZ2oGACloUb8ennTUDjKuDrhJ3JIdDZV0GchGBn ut4qwqLnMRCATL/MMpZEFAl/MDUDvaIPB9HbLVS36JtbHdDWy/3aCW2SaRA== Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4dd8x9ayhy-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 08 Apr 2026 11:56:37 +0000 (GMT) Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-50d5d1c2289so147135151cf.2 for ; Wed, 08 Apr 2026 04:56:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1775649395; x=1776254195; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VGDyW/FEB0GbROb7MhWm4EA0EZyx0U/3giZ87KYrgO0=; b=Uo+VBgsGqEvdPItDTKi6oHVLbwRTlv7pwUjXH889fznVNtc9Gta93sknLvBXBoP5Cd nlT1n179JKM2cl/ahNhXuV11CP7f91LQo7aCaFLPfaamzWyZFyzBtdGWk4FMRnVbQaVg bREA8jJ3jqBLFp0tgdAXt5rNFl9PFPZqmAIScPnX6xAp1JYPbZT+PjuyzhMtFbl+h91C LLJPdsXz6qR2s3GXDTCS5kOHbwlHvqEF6R6n0VwV3DNbnuuSh1FsLqpqjXwFUsFHGCyS 07IudMJRWT7wE2BCSE+cJmWAn5HGQ6oWjBAKJLIh/6FtFMmGmf6hJQPY3+yKSKAXqobI 5g6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775649395; x=1776254195; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=VGDyW/FEB0GbROb7MhWm4EA0EZyx0U/3giZ87KYrgO0=; b=Zmwga7a/pXLJHEBTI73NXUXrFKFp6KzjpadQFBIT336EWV71OMTAou1Rg0Thb6H0Rf C+kDCXl2Nwu05vqSmsLaKFfeKdVr1xY0fmPOKetqO/TAEYnGFVzfmMDMr0BHzanjxA1r qFAfyU6q5Dd6dkx3eONXT79zL8UkA/oC0P/DazWOM+Zk1TygFwfaaE15ayt9eyPiSdtL NnmSAxZZCnw7LpTMZEJRVEMko+7K+kM3NSPCeSjK8lnXzKiDxpKJeaWPwYnMbqZLdaWO ZimB5hYrDijLpq7JfFDX6O7+MC0oQ4hT+5brwhbY19X6NxZ0LXzPBT1o8VvJq50QceWL 1nnA== X-Gm-Message-State: AOJu0YwVrIeg1dafBuA56L+4ZOU5wxX9uc9Vy+F1BHPDe4w39tgqb8ff 9ywzxpj5Ox2ujUrA2vob5LFqzkDE4D5KQ+rkn+rBIzE8rVEc9OlexWT4TzrZcvO+OPqEohLKQsM zAu0KSzoTMIrTRBMpyQet4j6/sakJWt0sUXYu9u7VhBj/7g7ae9oU5wZVzb6Aq06VW0kVT+sLl0 5Ic4TPTwTL X-Gm-Gg: AeBDievvgOR7hOVxup2phm2OMQXB3T3VeSjTlScR01M0xbm7mG5ldrcmxA33QXuJzBn Rh113D6btwa1VJfbtFqMh0txEw5ExZQjkSLPbrJWuib8XxgbyAjv7ETrTCRE/qesGBZYgaoN50V JBi83ONvM99t27VxyD1w2FnOX9kYOfhXzvIDFCSu09pa5DPZWlrhBwoj6Xy1o4mK0UYX1vAy8HZ zkS3bWzulmDRxzopXvG5d4qNCMwDsVnfgtlsLQBGi8ekAhonMRsCteZLNA5G1dNgtPZ3jFCA2TP 7NNC8X/L9gv58AOaDPoTZWDGYphU2RYOYWXDi902ANgkAe8DaO13Z6JWApoFP1Dd1/pb7We/k4X 3mL8VjOqDnPimLQApa2KERDuQwFBpY3hhWJlUByh1jTrPGIUKdIZLULmHfA+6uAE2UGytry8L/P mGLbFHegZw8V3DXgpZaUGFWJ6mg/JL+GDJ X-Received: by 2002:a05:622a:aa0b:10b0:509:2677:68f7 with SMTP id d75a77b69052e-50d6260b06dmr244381621cf.5.1775649395568; Wed, 08 Apr 2026 04:56:35 -0700 (PDT) X-Received: by 2002:a05:622a:aa0b:10b0:509:2677:68f7 with SMTP id d75a77b69052e-50d6260b06dmr244381381cf.5.1775649395117; Wed, 08 Apr 2026 04:56:35 -0700 (PDT) Received: from t14s (2001-1c00-0c32-7800-07d4-cca3-ec08-7ac7.cable.dynamic.v6.ziggo.nl. [2001:1c00:c32:7800:7d4:cca3:ec08:7ac7]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b9c3c97219dsm632410766b.5.2026.04.08.04.56.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 04:56:34 -0700 (PDT) From: Hans de Goede To: libcamera-devel@lists.libcamera.org Cc: Loic Poulain , Hans de Goede Subject: [PATCH 2/3] libcamera: media_object: Add MediaEntity::disableLinks() Date: Wed, 8 Apr 2026 13:56:29 +0200 Message-ID: <20260408115630.12456-3-johannes.goede@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408115630.12456-1-johannes.goede@oss.qualcomm.com> References: <20260408115630.12456-1-johannes.goede@oss.qualcomm.com> MIME-Version: 1.0 X-Authority-Analysis: v=2.4 cv=Rr716imK c=1 sm=1 tr=0 ts=69d64275 cx=c_pps a=WeENfcodrlLV9YRTxbY/uA==:117 a=xqWC_Br6kY4A:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=jrADUgksUtfPzxcU8k8A:9 a=kacYvNCVWA4VmyqE58fU:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDA4MDExMCBTYWx0ZWRfXyiBV9gi7gj39 4vFnsq2kbEW6R3faCoHQGu7h+sDeKpV2EforoztUySn1WdFNmwFJPs4/a4R1YsR7Qld7yjzHIRp mucvQHi+Vh7//NGx8DHexvMHKQPF423GoaNC+6EKx8J2QMhd/n01N4KtqhUmyHXXisvUphDJ5Zv MwGmCIrppSLOm9gZgS9lSB/WN3lG94NsnSa06PmRvtdtJ0G5Yp5PhKQKsXDGdesb95ModnqS1PY brfx9rn0ugKlpHrSAso8Pg3RbpH7zB38jqUbWNr7LQZLkxDePdlUDrDuzdkFutHmGiQ2zlXz+m4 aUGVhWyZz4ZVhkvR5hkFwHefuQjc56X2dgMzoBhd+zp1aq8lIV6vkByfF0YD/TDOIaryshMAmuW r6Ey6b+MmDQjZoF9VlyokKj7wRmXneYO1pT45zh9FH+fPms3mwxqxGAK5OZJXAFb85IP+MKxPcT N1Xn9LdnzHhHHtSzskQ== X-Proofpoint-ORIG-GUID: V_7hWNY1pGtLxZwPjX7wKYZmECX1Wa2I X-Proofpoint-GUID: V_7hWNY1pGtLxZwPjX7wKYZmECX1Wa2I X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293, Aquarius:18.0.1143, Hydra:6.1.51, FMLib:17.12.100.49 definitions=2026-04-08_03,2026-04-08_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 suspectscore=0 malwarescore=0 clxscore=1015 bulkscore=0 phishscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604010000 definitions=main-2604080110 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" Some pipeline-handlers may want finer-grained control over disabling links then MediaDevice::disableLinks() which simply disables all links on a media-device. Add a new MediaEntity::disableLinks() method which disables the links on a single MediaEntity and use that in MediaDevice::disableLinks() to avoid code duplication. Signed-off-by: Hans de Goede --- include/libcamera/internal/media_object.h | 1 + src/libcamera/media_device.cpp | 16 +++----------- src/libcamera/media_object.cpp | 27 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/include/libcamera/internal/media_object.h b/include/libcamera/internal/media_object.h index 54e2e5cef..121e80bac 100644 --- a/include/libcamera/internal/media_object.h +++ b/include/libcamera/internal/media_object.h @@ -118,6 +118,7 @@ public: const MediaPad *getPadById(unsigned int id) const; int setDeviceNode(const std::string &deviceNode); + int disableLinks() const; private: LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaEntity) diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 3f974eaab..4833d4bba 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -463,19 +463,9 @@ MediaLink *MediaDevice::link(const MediaPad *source, const MediaPad *sink) int MediaDevice::disableLinks() { for (MediaEntity *entity : entities_) { - for (MediaPad *pad : entity->pads()) { - if (!(pad->flags() & MEDIA_PAD_FL_SOURCE)) - continue; - - for (MediaLink *link : pad->links()) { - if (link->flags() & MEDIA_LNK_FL_IMMUTABLE) - continue; - - int ret = link->setEnabled(false); - if (ret) - return ret; - } - } + int ret = entity->disableLinks(); + if (ret) + return ret; } return 0; diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp index 3e3772a62..82ba5f4b2 100644 --- a/src/libcamera/media_object.cpp +++ b/src/libcamera/media_object.cpp @@ -428,6 +428,33 @@ int MediaEntity::setDeviceNode(const std::string &deviceNode) return 0; } +/** + * \brief Disable all links on the media entity + * + * Disable all the media entity links, clearing the MEDIA_LNK_FL_ENABLED flag + * on links which are not flagged as IMMUTABLE. + * + * \return 0 on success or a negative error code otherwise + */ +int MediaEntity::disableLinks() const +{ + for (MediaPad *pad : pads_) { + if (!(pad->flags() & MEDIA_PAD_FL_SOURCE)) + continue; + + for (MediaLink *link : pad->links()) { + if (link->flags() & MEDIA_LNK_FL_IMMUTABLE) + continue; + + int ret = link->setEnabled(false); + if (ret) + return ret; + } + } + + return 0; +} + /** * \brief Construct a MediaEntity * \param[in] dev The media device this entity belongs to From patchwork Wed Apr 8 11:56:30 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 26510 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 8B65EC32BB for ; Wed, 8 Apr 2026 11:56:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 436D762E13; Wed, 8 Apr 2026 13:56:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=qualcomm.com header.i=@qualcomm.com header.b="cgw+A09f"; dkim=pass (2048-bit key; unprotected) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="jg7hkND8"; dkim-atps=neutral Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 189C462E34 for ; Wed, 8 Apr 2026 13:56:38 +0200 (CEST) Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 638BOaDe1619593 for ; Wed, 8 Apr 2026 11:56:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=STA4e7kdkhh OHV0Gx9cgGOwpVazRhRx4+D19pzIa6GI=; b=cgw+A09fAuCJ9XvGS+/H90bwDAS zP6b6/WGeBKJCiVNMv+BZol/vxeG5hv6YqBTsu+Cmu/KuJS+/+xpBKBa6xPy918u mFPnKG5JDaB3EIxnT6uVKktM7wWJmot00xH75NClt0RtSRECxTB+UesXjJnrLiga Hioz2GwiLDhuTBChCVmwB26U7DTkrZW5lstAwC0sI8R2R7jHUTghm9UUhsqyXxNy KmsxUAHsQ5Fy640oG8g1zhgwfJ1Kci8GJ3ZoImmVVgIuTkCkan5JoZjbalpYMjyB 11YcyGLKxfapjZJ8SuZSJbKBFEPsPMJaidIPHiGg9FdrHo6kJ0z9xdPDAEQ== Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ddacrjnvq-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 08 Apr 2026 11:56:37 +0000 (GMT) Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-50d831e8083so76716411cf.3 for ; Wed, 08 Apr 2026 04:56:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1775649397; x=1776254197; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=STA4e7kdkhhOHV0Gx9cgGOwpVazRhRx4+D19pzIa6GI=; b=jg7hkND8182C0s7dZ/ohDdbcTeJY8s1qoL3loNzsV2DAY+gzLA35ypYtTOTKzHZdx/ C+UIdlwPr52Fxlpx2WR6nDzCBrRxaoeeSldDwBv9aFLdpB2B+5MS1pm2gSY5BaR0vX3H fK+E7RPti5JwDpBEpQIBJn9NQLdCAenIP+XW6EX/7UWBtUPPr6RZVOq3/hBdsXxbxtEJ scwyD+qksTOeHKU5jlzgopTy5SF/yOEZeeoNa2h1f3A71CkB/GFMZ9KqZ4tlyrmJuRrI 2qhRdR29uN0VXCLb1SXJhZgmjYZpkF6Di6VRFGe4Q34UGuyO79mgXt34Avlz+JwnMg6h LFAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775649397; x=1776254197; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=STA4e7kdkhhOHV0Gx9cgGOwpVazRhRx4+D19pzIa6GI=; b=pHR7+WNJnHaQryGP+5XDuxMolOwE2nnMCsbXTvSfHD2h+vmAREmsnR81w/Aok/f6mk Au4tm5VDYLadXEz11UCYnLQh7seNj07QX9Xzp1ijN9j3vngB9GBsM2VbonQIiUjmlpfi W9izkTFX1YrRtVqjJwxz3ZFUFTcU9xyckvP6d4rdhEScxHMEaLqPcz79c4zLKG0kwQD4 Ew67hHPmKhThiN2xo4xNw3XmDPtq9VLQIJDxHYqDurvGjlqZmVhmurDz+76kcRtpMY6Z bvv4o5rqhXaGjCM+N18e5CO9eK0kt1cFSeU/ZIKku7tzO1Al2BT5HQXbdj7Aiq+++qaB ALXw== X-Gm-Message-State: AOJu0YyZCCbTMBd8Y13hl6+reT+yhNAjT/Qshz8tHStDV7DOBkPBggBf Nj3w5WE3jCBBnGYnruHktaYGVECoc+V9GgxeoY43bbRMbTgDv7hDbfaU4f/d6uT39aGy23yrlx1 mZN8FkOv6jAOPAeGh8K3TJ0OEAlveIlaTcAEJfyssaoEF+OdKa0lC+nl3x13O1bQYYNPZzvrmrM qFMlJujSzF X-Gm-Gg: AeBDieux8wVbfsB2sM8ooG4iomWVG9ghLH8Eaz2n29rTzcIAIBOw5AQyeUSSctXFcRD vsSqzIrNS8hs5/YhYm2iALu/l/+J+ux8FJRlcrB3tNjG1DcxJIiY/AyO9/eqfhIM4j6m7zYHIoQ w5JppfHQ6kTzY1xhb6qOtHpXaYJ1GvVbzN15sAVB/ubvoyIOH5B7LhDEP0MWDw88g0+Rivt/TzZ qfpoXvQ4vsD+a0qMXhCk0uZnyTCU1ISwlO53CNmdY5yaALYjV6pNEOmy5DjfgDZIF/Colk9ZPrv woeNC9aTHrndWc8xHA7xf225TKkNJ9tQfiVatmijM12a87DE0FDIVbYuJgH88MHSo+gqIY17nJI CFHXDOEwy7htkUgSTENdezXsSwq308NKngFl4f43QHaxQeKUEaAdcmE2NUqjSutGOhxdT2DfFmE LsM/NAztNPezORx01ZU/gCRrFf7Qy0HExL X-Received: by 2002:a05:622a:2b03:b0:509:34b8:a373 with SMTP id d75a77b69052e-50d62cbfb5fmr310374391cf.32.1775649396856; Wed, 08 Apr 2026 04:56:36 -0700 (PDT) X-Received: by 2002:a05:622a:2b03:b0:509:34b8:a373 with SMTP id d75a77b69052e-50d62cbfb5fmr310374041cf.32.1775649396421; Wed, 08 Apr 2026 04:56:36 -0700 (PDT) Received: from t14s (2001-1c00-0c32-7800-07d4-cca3-ec08-7ac7.cable.dynamic.v6.ziggo.nl. [2001:1c00:c32:7800:7d4:cca3:ec08:7ac7]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b9c3c97219dsm632410766b.5.2026.04.08.04.56.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 04:56:35 -0700 (PDT) From: Hans de Goede To: libcamera-devel@lists.libcamera.org Cc: Loic Poulain , Hans de Goede Subject: [PATCH 3/3] libcamera: v4l2_device: add lock() and unlock() methods Date: Wed, 8 Apr 2026 13:56:30 +0200 Message-ID: <20260408115630.12456-4-johannes.goede@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408115630.12456-1-johannes.goede@oss.qualcomm.com> References: <20260408115630.12456-1-johannes.goede@oss.qualcomm.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: D6GuC2bsj-LERxRsyyq-0HjO9I5R8P-B X-Proofpoint-GUID: D6GuC2bsj-LERxRsyyq-0HjO9I5R8P-B X-Authority-Analysis: v=2.4 cv=WZs8rUhX c=1 sm=1 tr=0 ts=69d64275 cx=c_pps a=EVbN6Ke/fEF3bsl7X48z0g==:117 a=xqWC_Br6kY4A:10 a=A5OVakUREuEA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yx91gb_oNiZeI1HMLzn7:22 a=EUspDBNiAAAA:8 a=qZCpo_c2fvnUBkGHUDcA:9 a=a_PwQJl-kcHnX1M80qC6:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDA4MDExMCBTYWx0ZWRfX4sSW43JZFtP6 DWp096ktGdTC42X0Hk4AJikJQNu0A2iiJBVJtNXCaIlkT2tAEd6c7LTybRPeDcazHoTO439BWkM p31uj4MZLlLAIfp5h4YMvosAkjPLotk1EviS6+M+NBNkzreJh569PKuJLgUChtRD5EZo/ipAcOX g9sSYJ1MpeE7AnW/Xr9qC/rSWgzt923j+pBtx0lUJkDsHxBx/txgAFnUrHhCNbBIxPNENi9RncM OSkvSfE9BeU45QqmrQKwmMdaf2XjxtQufgZkcOImg1ACcgjts3HNbUOmhZyqgH2fS5cgR5u8xJU SGOxHyNZuC3Y/BI6zdwSRiEPAOpX/sb5XAqwjdMpHTTq/nMlDp9R+1gYPr6RG3G4mJ+S98waCcw DNGBL7EC1qib5F+wh+Xa7N/iOKNdPjgXD9LXvPkVkfaeug2KO7+yxai4u/0CQ8WQ3XiYGqBad2X gF5q9MYVV8rUPPr6dcw== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293, Aquarius:18.0.1143, Hydra:6.1.51, FMLib:17.12.100.49 definitions=2026-04-08_03,2026-04-08_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 adultscore=0 phishscore=0 clxscore=1015 bulkscore=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604010000 definitions=main-2604080110 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 lock() and unlock() methods to allow pipeline-handlers to do more fine grained locking the locking at the media-device label. Signed-off-by: Hans de Goede --- include/libcamera/internal/v4l2_device.h | 3 ++ src/libcamera/v4l2_device.cpp | 37 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index dbbd118ab..f34f5f2f1 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -52,6 +52,9 @@ public: void updateControlInfo(); + bool lock(); + void unlock(); + protected: V4L2Device(const std::string &deviceNode); ~V4L2Device(); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index b49d73b1c..e8764b37e 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -147,6 +147,43 @@ void V4L2Device::close() fd_.reset(); } +/** + * \brief Lock the device to prevent it from being used by other instances of + * libcamera + * + * Multiple instances of libcamera might be running on the same system, at the + * same time. To allow the different instances to coexist, system resources like + * v4l2 devices must be accessible for enumerating the cameras they provide at + * all times, while still allowing an instance to lock a resource while it + * prepares to actively use a camera from the resource. + * + * \return True if the device could be locked, false otherwise + * \sa unlock() + */ +bool V4L2Device::lock() +{ + if (!fd_.isValid()) + return false; + + if (lockf(fd_.get(), F_TLOCK, 0)) + return false; + + return true; +} + +/** + * \brief Unlock the device and free it for use for libcamera instances + * + * \sa lock() + */ +void V4L2Device::unlock() +{ + if (!fd_.isValid()) + return; + + std::ignore = lockf(fd_.get(), F_ULOCK, 0); +} + /** * \fn V4L2Device::isOpen() * \brief Check if the V4L2 device node is open