From patchwork Thu Oct 23 14:48:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 24732 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 29552C3259 for ; Thu, 23 Oct 2025 14:49:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2C6DA607F8; Thu, 23 Oct 2025 16:49:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nncI7e0w"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EF117606DE for ; Thu, 23 Oct 2025 16:48:57 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:7328:357b:4ce1:72b6]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 0536319E5; Thu, 23 Oct 2025 16:47:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761230833; bh=DQ4Dk4FvJ+uYS9yZjd701CRURlrCQeMEmCNaJG8L/xw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nncI7e0wlZgQmrY9JpWSpnTV/ut6iPBlcOA0uEYcCJ92PKNcQ4zpc32pnQ1ie3VtM G1ZCWsT/1X9DruMswpVE4FDkihCJI9HxJyqReySYsmAeBkFXhGiOMeG3MEMqUmwrj4 drf4u1YnRDcuSw6D0ZrATDUAm7G2gX53FVXbxfoc= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v2 04/35] libcamera: converter: Utilise shared MediaDevice pointers Date: Thu, 23 Oct 2025 16:48:05 +0200 Message-ID: <20251023144841.403689-5-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251023144841.403689-1-stefan.klug@ideasonboard.com> References: <20251023144841.403689-1-stefan.klug@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" With the upcoming addition of V4L2 requests support, the converters need to keep a handle to the corresponding media device. Prepare for that by changing the constructor parameter from a raw pointer to a shared pointer. Signed-off-by: Stefan Klug --- include/libcamera/internal/converter.h | 9 +++++---- .../libcamera/internal/converter/converter_v4l2_m2m.h | 2 +- src/libcamera/converter.cpp | 5 +++-- src/libcamera/converter/converter_v4l2_m2m.cpp | 4 ++-- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 2 +- src/libcamera/pipeline/simple/simple.cpp | 4 ++-- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/libcamera/internal/converter.h b/include/libcamera/internal/converter.h index 644ec429bb25..4915af7ac5de 100644 --- a/include/libcamera/internal/converter.h +++ b/include/libcamera/internal/converter.h @@ -46,7 +46,7 @@ public: Up, }; - Converter(MediaDevice *media, Features features = Feature::None); + Converter(std::shared_ptr media, Features features = Feature::None); virtual ~Converter(); virtual int loadConfiguration(const std::string &filename) = 0; @@ -107,7 +107,7 @@ public: const std::vector &compatibles() const { return compatibles_; } - static std::unique_ptr create(MediaDevice *media); + static std::unique_ptr create(std::shared_ptr media); static std::vector &factories(); static std::vector names(); @@ -116,7 +116,8 @@ private: static void registerType(ConverterFactoryBase *factory); - virtual std::unique_ptr createInstance(MediaDevice *media) const = 0; + virtual std::unique_ptr + createInstance(std::shared_ptr media) const = 0; std::string name_; std::vector compatibles_; @@ -131,7 +132,7 @@ public: { } - std::unique_ptr createInstance(MediaDevice *media) const override + std::unique_ptr createInstance(std::shared_ptr media) const override { return std::make_unique<_Converter>(media); } diff --git a/include/libcamera/internal/converter/converter_v4l2_m2m.h b/include/libcamera/internal/converter/converter_v4l2_m2m.h index 0ad7bf7fdbe2..d316754040dd 100644 --- a/include/libcamera/internal/converter/converter_v4l2_m2m.h +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h @@ -36,7 +36,7 @@ class V4L2M2MDevice; class V4L2M2MConverter : public Converter { public: - V4L2M2MConverter(MediaDevice *media); + V4L2M2MConverter(std::shared_ptr media); int loadConfiguration([[maybe_unused]] const std::string &filename) override { return 0; } bool isValid() const override { return m2m_ != nullptr; } diff --git a/src/libcamera/converter.cpp b/src/libcamera/converter.cpp index d551b908d523..142fb29a1272 100644 --- a/src/libcamera/converter.cpp +++ b/src/libcamera/converter.cpp @@ -8,6 +8,7 @@ #include "libcamera/internal/converter.h" #include +#include #include @@ -68,7 +69,7 @@ LOG_DEFINE_CATEGORY(Converter) * This searches for the entity implementing the data streaming function in the * media graph entities and use its device node as the converter device node. */ -Converter::Converter(MediaDevice *media, Features features) +Converter::Converter(std::shared_ptr media, Features features) { const std::vector &entities = media->entities(); auto it = std::find_if(entities.begin(), entities.end(), @@ -332,7 +333,7 @@ ConverterFactoryBase::ConverterFactoryBase(const std::string name, std::initiali * \return A new instance of the converter subclass corresponding to the media * device, or null if the media device driver name doesn't match anything */ -std::unique_ptr ConverterFactoryBase::create(MediaDevice *media) +std::unique_ptr ConverterFactoryBase::create(std::shared_ptr media) { const std::vector &factories = ConverterFactoryBase::factories(); diff --git a/src/libcamera/converter/converter_v4l2_m2m.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp index 0ce7a7a67f11..b2bd54f368d8 100644 --- a/src/libcamera/converter/converter_v4l2_m2m.cpp +++ b/src/libcamera/converter/converter_v4l2_m2m.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -261,8 +262,7 @@ void V4L2M2MConverter::V4L2M2MStream::captureBufferReady(FrameBuffer *buffer) * \brief Construct a V4L2M2MConverter instance * \param[in] media The media device implementing the converter */ - -V4L2M2MConverter::V4L2M2MConverter(MediaDevice *media) +V4L2M2MConverter::V4L2M2MConverter(std::shared_ptr media) : Converter(media) { if (deviceNode().empty()) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 959cdb41fe7e..0e2a210e1e80 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -1445,7 +1445,7 @@ bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator) std::shared_ptr dwpMediaDevice = enumerator->search(dwp); if (dwpMediaDevice) { - dewarper_ = std::make_unique(dwpMediaDevice.get()); + dewarper_ = std::make_unique(dwpMediaDevice); if (dewarper_->isValid()) { dewarper_->outputBufferReady.connect( this, &PipelineHandlerRkISP1::dewarpBufferReady); diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 1183be9a6b07..204b29f92907 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -413,7 +413,7 @@ public: V4L2VideoDevice *video(const MediaEntity *entity); V4L2Subdevice *subdev(const MediaEntity *entity); - MediaDevice *converter() { return converter_.get(); } + std::shared_ptr converter() { return converter_; } bool swIspEnabled() const { return swIspEnabled_; } protected: @@ -586,7 +586,7 @@ int SimpleCameraData::init() int ret; /* Open the converter, if any. */ - MediaDevice *converter = pipe->converter(); + std::shared_ptr converter = pipe->converter(); if (converter) { converter_ = ConverterFactoryBase::create(converter); if (!converter_) {