From patchwork Mon Jun 29 16:29:44 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 27099 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 8BFFAC3261 for ; Mon, 29 Jun 2026 16:31:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5A42765F96; Mon, 29 Jun 2026 18:31:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Vzzh3iR/"; 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 CC90265F46 for ; Mon, 29 Jun 2026 18:30:25 +0200 (CEST) Received: from pb-laptop.local (185.221.140.128.nat.pool.zt.hu [185.221.140.128]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A363AE91 for ; Mon, 29 Jun 2026 18:29:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1782750582; bh=GSAt56pEicC5fChkWf1srdN1G08/7viSQOP33NdqEok=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Vzzh3iR/yFdI6Zg+qsYe9gpv4tWwrHjHLZCH/oB+KWnGwcZu8kGhKgqnpEMWiGbpq B3U1CurYTb5gCGaUCDDuXPmVUu+FcCwJQ5qPHtTbd7limFIw0rGC+E58WKp9WtXIIK 9dkxAQW76/r8u9m3SWHxsdIaDOZaJjDGcov9Qfyg= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH v1 21/54] libcamera: camera: Add `StreamData` Date: Mon, 29 Jun 2026 18:29:44 +0200 Message-ID: <20260629163017.863145-22-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260629163017.863145-1-barnabas.pocze@ideasonboard.com> References: <20260629163017.863145-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 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 an internal `StreamData` type that contains private data about the streams of a camera. This currently replaces the separate `activeStreams_` `std::set`. The `streams_` member is not merged as that is exposed via `Camera::streams()`. Signed-off-by: Barnabás Pőcze --- include/libcamera/internal/camera.h | 7 ++++++- src/libcamera/camera.cpp | 29 ++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/include/libcamera/internal/camera.h b/include/libcamera/internal/camera.h index 8a2e9ed589..43b6a6e4a2 100644 --- a/include/libcamera/internal/camera.h +++ b/include/libcamera/internal/camera.h @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -54,6 +55,10 @@ private: CameraRunning, }; + struct StreamData { + bool active = false; + }; + bool isAcquired() const; bool isRunning() const; int isAccessAllowed(State state, bool allowDisconnected = false, @@ -68,7 +73,7 @@ private: std::shared_ptr pipe_; std::string id_; std::set streams_; - std::set activeStreams_; + std::unordered_map streamData_; bool disconnected_; std::atomic state_; diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 93b9e603dd..aa5682f9d7 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -934,6 +934,11 @@ Camera::Camera(std::unique_ptr d, const std::string &id, _d()->properties_.set(properties::PipelineHandler, _d()->pipe_->name()); _d()->streams_ = streams; _d()->validator_ = std::make_unique(this); + + for (const Stream *s : streams) { + [[maybe_unused]] auto [it, inserted] = _d()->streamData_.try_emplace(s); + ASSERT(inserted); + } } Camera::~Camera() @@ -969,10 +974,11 @@ int Camera::exportFrameBuffers(Stream *stream, if (ret < 0) return ret; - if (streams().find(stream) == streams().end()) + auto it = d->streamData_.find(stream); + if (it == d->streamData_.end()) return -EINVAL; - if (d->activeStreams_.find(stream) == d->activeStreams_.end()) + if (!it->second.active) return -EINVAL; return d->pipe_->invokeMethod(&PipelineHandler::exportFrameBuffers, @@ -1220,21 +1226,29 @@ int Camera::configure(CameraConfiguration *config) if (ret) return ret; - d->activeStreams_.clear(); + auto resetStreamData = [&] { + for (auto &[stream, data] : d->streamData_) + data.active = false; + }; + utils::scope_exit streamDataGuard(std::ref(resetStreamData)); + + resetStreamData(); for (const StreamConfiguration &cfg : *config) { Stream *stream = cfg.stream(); - if (!stream) { + auto it = d->streamData_.find(stream); + + if (it == d->streamData_.end() || it->second.active) { LOG(Camera, Fatal) << "Pipeline handler failed to update stream configuration"; - d->activeStreams_.clear(); return -EINVAL; } stream->configuration_ = cfg; - d->activeStreams_.insert(stream); + it->second.active = true; } d->setState(Private::CameraConfigured); + streamDataGuard.release(); return 0; } @@ -1364,7 +1378,8 @@ int Camera::queueRequest(Request *request) } for (const auto &[stream, buffer] : request->buffers()) { - if (d->activeStreams_.find(stream) == d->activeStreams_.end()) { + auto it = d->streamData_.find(stream); + if (it == d->streamData_.end() || !it->second.active) { LOG(Camera, Error) << "Invalid request"; return -EINVAL; }