From patchwork Fri Apr 4 07:46:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 23135 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 0B889C3213 for ; Fri, 4 Apr 2025 07:46:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B1027689A8; Fri, 4 Apr 2025 09:46:39 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="l/sB304N"; 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 6FC5768994 for ; Fri, 4 Apr 2025 09:46:36 +0200 (CEST) Received: from neptunite.flets-east.jp (unknown [IPv6:2404:7a81:160:2100:cd45:d129:c842:b4ce]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 112B149E; Fri, 4 Apr 2025 09:44:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1743752682; bh=/pn/fLE22NrypW+Ye7UsywrcyAV80+/orN2kactWvLw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l/sB304NuXuFYFPe675kVnH999/uWuzsmrJXT0clk3pW0riBNgzTxRXYfN9Hwzp0B IRS9lZmEx3eEuKTOSE5eO4uLiA8l/+id5uwLgKSZgiYMiQXLyRbxE2ON1CUsn1LQ8x 3lgUpmL8810VAAWzw0pFdZLwtLZFxuVO3fQfuJFc= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Paul Elder Subject: [PATCH 1/3] libcamera: v4l2: Support fromEntityName with shared_ptr Date: Fri, 4 Apr 2025 16:46:21 +0900 Message-ID: <20250404074624.2975182-2-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250404074624.2975182-1-paul.elder@ideasonboard.com> References: <20250404074624.2975182-1-paul.elder@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" From: Kieran Bingham To facilitate expanding the use of a shared_ptr in preference of a raw MediaDevice* pointer, add an additional implementation for fromEntityName for both of v4l2_videodevice and v4l2_subdevice to support this type. Signed-off-by: Kieran Bingham Signed-off-by: Paul Elder --- include/libcamera/internal/v4l2_subdevice.h | 2 ++ include/libcamera/internal/v4l2_videodevice.h | 2 ++ src/libcamera/v4l2_subdevice.cpp | 15 +++++++++++++++ src/libcamera/v4l2_videodevice.cpp | 15 +++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index fa2a4a21eefb..08216cd56bc3 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -163,6 +163,8 @@ public: static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); + static std::unique_ptr + fromEntityName(std::shared_ptr, const std::string &entity); protected: std::string logPrefix() const override; diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index ae6a76cb0209..e35fb11bc99f 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -228,6 +228,8 @@ public: static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); + static std::unique_ptr + fromEntityName(std::shared_ptr, const std::string &entity); V4L2PixelFormat toV4L2PixelFormat(const PixelFormat &pixelFormat) const; diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 33279654db8c..13f5316a3fc3 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -1766,6 +1766,21 @@ V4L2Subdevice::fromEntityName(const MediaDevice *media, return std::make_unique(mediaEntity); } +/** + * \brief Create a new video subdevice instance from \a entity in media device + * \a media + * \param[in] media The media device where the entity is registered + * \param[in] entity The media entity name + * + * \return A newly created V4L2Subdevice on success, nullptr otherwise + */ +std::unique_ptr +V4L2Subdevice::fromEntityName(std::shared_ptr media, + const std::string &entity) +{ + return fromEntityName(media.get(), entity); +} + std::string V4L2Subdevice::logPrefix() const { return "'" + entity_->name() + "'"; diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index f5b3fa09d9a0..ce7be7deb91f 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -2109,6 +2109,21 @@ V4L2VideoDevice::fromEntityName(const MediaDevice *media, return std::make_unique(mediaEntity); } +/** + * \brief Create a new video device instance from \a entity in media device + * \a media + * \param[in] media The media device where the entity is registered + * \param[in] entity The media entity name + * + * \return A newly created V4L2VideoDevice on success, nullptr otherwise + */ +std::unique_ptr +V4L2VideoDevice::fromEntityName(std::shared_ptr media, + const std::string &entity) +{ + return fromEntityName(media.get(), entity); +} + /** * \brief Convert \a PixelFormat to a V4L2PixelFormat supported by the device * \param[in] pixelFormat The PixelFormat to convert From patchwork Fri Apr 4 07:46:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 23136 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 5C730C3284 for ; Fri, 4 Apr 2025 07:46:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7870C689AB; Fri, 4 Apr 2025 09:46:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DxGFZwh/"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 69DD368994 for ; Fri, 4 Apr 2025 09:46:38 +0200 (CEST) Received: from neptunite.flets-east.jp (unknown [IPv6:2404:7a81:160:2100:cd45:d129:c842:b4ce]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 09DD2710; Fri, 4 Apr 2025 09:44:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1743752684; bh=8b0nqoC5zuWIoG+JqdXRWPJN9yWv3vtuOd/nenj2OQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DxGFZwh/YZVsiDAZpGf7Qx8OJ4ADFCpxMTK+UqQoyh12C5OcA7sdew0n9++K/PJAh EO9Irkyh0+SUne0wDyqpQ6jmXJ7DWt9wLlaLScGTZHfTSgVyP7IeCsGdF3tx129Kie ASVLOID7rkCE9pGQiwU3x0zpGSKdVr1z562IyaDs= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Paul Elder Subject: [PATCH 2/3] libcamera: pipeline: utilise shared MediaDevice pointers Date: Fri, 4 Apr 2025 16:46:22 +0900 Message-ID: <20250404074624.2975182-3-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250404074624.2975182-1-paul.elder@ideasonboard.com> References: <20250404074624.2975182-1-paul.elder@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" From: Kieran Bingham Adapt the PipelineHandler::acquireMediaDevice() support function to return a shared pointer instead of the underlying raw pointer. Propagate this update to all pipeline handlers that use the MediaDevice and store a std::shared_ptr accordingly. Signed-off-by: Kieran Bingham Signed-off-by: Paul Elder --- include/libcamera/internal/pipeline_handler.h | 8 ++++---- src/libcamera/pipeline/imx8-isi/imx8-isi.cpp | 2 +- src/libcamera/pipeline/ipu3/cio2.cpp | 2 +- src/libcamera/pipeline/ipu3/cio2.h | 2 +- src/libcamera/pipeline/ipu3/imgu.cpp | 3 ++- src/libcamera/pipeline/ipu3/imgu.h | 4 ++-- src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ++-- src/libcamera/pipeline/mali-c55/mali-c55.cpp | 2 +- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 2 +- src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 2 +- src/libcamera/pipeline/rkisp1/rkisp1_path.h | 2 +- .../pipeline/rpi/common/pipeline_base.cpp | 6 ++++-- src/libcamera/pipeline/rpi/common/pipeline_base.h | 9 ++++++--- src/libcamera/pipeline/rpi/pisp/pisp.cpp | 10 ++++++---- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 13 +++++++++---- src/libcamera/pipeline/simple/simple.cpp | 13 +++++++------ src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 6 +++--- src/libcamera/pipeline/vimc/vimc.cpp | 6 +++--- src/libcamera/pipeline_handler.cpp | 14 ++++++++------ test/delayed_controls.cpp | 2 +- test/libtest/buffer_source.cpp | 2 +- 21 files changed, 65 insertions(+), 49 deletions(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index 5fa8bc2f66ee..0199ab7911c0 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -38,8 +38,8 @@ public: virtual ~PipelineHandler(); virtual bool match(DeviceEnumerator *enumerator) = 0; - MediaDevice *acquireMediaDevice(DeviceEnumerator *enumerator, - const DeviceMatch &dm); + std::shared_ptr acquireMediaDevice(DeviceEnumerator *enumerator, + const DeviceMatch &dm); bool acquire(Camera *camera); void release(Camera *camera); @@ -74,7 +74,7 @@ protected: void clearMediaDevices(); void registerCamera(std::shared_ptr camera); - void hotplugMediaDevice(MediaDevice *media); + void hotplugMediaDevice(std::shared_ptr media); virtual int queueRequestDevice(Camera *camera, Request *request) = 0; virtual void stopDevice(Camera *camera) = 0; @@ -87,7 +87,7 @@ protected: private: void unlockMediaDevices(); - void mediaDeviceDisconnected(MediaDevice *media); + void mediaDeviceDisconnected(std::shared_ptr media); virtual void disconnect(); void doQueueRequest(Request *request); diff --git a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp index 4e66b3368d5a..850dbfcdc64b 100644 --- a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp +++ b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp @@ -139,7 +139,7 @@ private: void bufferReady(FrameBuffer *buffer); - MediaDevice *isiDev_; + std::shared_ptr isiDev_; std::unique_ptr crossbar_; std::vector pipes_; diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp index aa544d7b0303..ebbd424c56ea 100644 --- a/src/libcamera/pipeline/ipu3/cio2.cpp +++ b/src/libcamera/pipeline/ipu3/cio2.cpp @@ -112,7 +112,7 @@ std::vector CIO2Device::sizes(const PixelFormat &format) const * \return 0 on success or a negative error code otherwise * \retval -ENODEV No supported image sensor is connected to this CIO2 instance */ -int CIO2Device::init(const MediaDevice *media, unsigned int index) +int CIO2Device::init(std::shared_ptr media, unsigned int index) { int ret; diff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h index 963c2f6b93a4..fdf85f2655f0 100644 --- a/src/libcamera/pipeline/ipu3/cio2.h +++ b/src/libcamera/pipeline/ipu3/cio2.h @@ -38,7 +38,7 @@ public: std::vector formats() const; std::vector sizes(const PixelFormat &format) const; - int init(const MediaDevice *media, unsigned int index); + int init(std::shared_ptr media, unsigned int index); int configure(const Size &size, const Transform &transform, V4L2DeviceFormat *outputFormat); diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp index 7be780913fae..391e000f6e12 100644 --- a/src/libcamera/pipeline/ipu3/imgu.cpp +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -330,7 +330,8 @@ FOV calcFOV(const Size &in, const ImgUDevice::PipeConfig &pipe) * * \return 0 on success or a negative error code otherwise */ -int ImgUDevice::init(MediaDevice *media, unsigned int index) +int ImgUDevice::init(std::shared_ptr media, + unsigned int index) { int ret; diff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h index fa508316b301..272f861f98c4 100644 --- a/src/libcamera/pipeline/ipu3/imgu.h +++ b/src/libcamera/pipeline/ipu3/imgu.h @@ -64,7 +64,7 @@ public: Size viewfinder; }; - int init(MediaDevice *media, unsigned int index); + int init(std::shared_ptr media, unsigned int index); PipeConfig calculatePipeConfig(Pipe *pipe); @@ -118,7 +118,7 @@ private: V4L2DeviceFormat *outputFormat); std::string name_; - MediaDevice *media_; + std::shared_ptr media_; }; } /* namespace libcamera */ diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index e31e3879dcc9..17205f96446a 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -164,8 +164,8 @@ private: ImgUDevice imgu0_; ImgUDevice imgu1_; - MediaDevice *cio2MediaDev_; - MediaDevice *imguMediaDev_; + std::shared_ptr cio2MediaDev_; + std::shared_ptr imguMediaDev_; std::vector ipaBuffers_; }; diff --git a/src/libcamera/pipeline/mali-c55/mali-c55.cpp b/src/libcamera/pipeline/mali-c55/mali-c55.cpp index a05e11fccf8d..7615122d907b 100644 --- a/src/libcamera/pipeline/mali-c55/mali-c55.cpp +++ b/src/libcamera/pipeline/mali-c55/mali-c55.cpp @@ -684,7 +684,7 @@ private: bool registerTPGCamera(MediaLink *link); bool registerSensorCamera(MediaLink *link); - MediaDevice *media_; + std::shared_ptr media_; std::unique_ptr isp_; std::unique_ptr stats_; std::unique_ptr params_; diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 705615b86b0c..d4ec538f478b 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -200,7 +200,7 @@ private: int updateControls(RkISP1CameraData *data); - MediaDevice *media_; + std::shared_ptr media_; std::unique_ptr isp_; std::unique_ptr param_; std::unique_ptr stat_; diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp index eee5b09e2ff0..2e567ace0b78 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp @@ -59,7 +59,7 @@ RkISP1Path::RkISP1Path(const char *name, const Span &formats) { } -bool RkISP1Path::init(MediaDevice *media) +bool RkISP1Path::init(std::shared_ptr media) { std::string resizer = std::string("rkisp1_resizer_") + name_ + "path"; std::string video = std::string("rkisp1_") + name_ + "path"; diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h index 2a1ef0abe6d1..154310ac37c1 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h @@ -36,7 +36,7 @@ class RkISP1Path public: RkISP1Path(const char *name, const Span &formats); - bool init(MediaDevice *media); + bool init(std::shared_ptr media); int setEnabled(bool enable) { return link_->setEnabled(enable); } bool isEnabled() const { return link_->flags() & MEDIA_LNK_FL_ENABLED; } diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp index 1f13e5230fae..23ce54eca144 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.cpp +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.cpp @@ -784,8 +784,10 @@ int PipelineHandlerBase::queueRequestDevice(Camera *camera, Request *request) } int PipelineHandlerBase::registerCamera(std::unique_ptr &cameraData, - MediaDevice *frontend, const std::string &frontendName, - MediaDevice *backend, MediaEntity *sensorEntity) + std::shared_ptr frontend, + const std::string &frontendName, + std::shared_ptr backend, + MediaEntity *sensorEntity) { CameraData *data = cameraData.get(); int ret; diff --git a/src/libcamera/pipeline/rpi/common/pipeline_base.h b/src/libcamera/pipeline/rpi/common/pipeline_base.h index aae0c2f35888..e422bbf7405f 100644 --- a/src/libcamera/pipeline/rpi/common/pipeline_base.h +++ b/src/libcamera/pipeline/rpi/common/pipeline_base.h @@ -229,13 +229,16 @@ public: protected: int registerCamera(std::unique_ptr &cameraData, - MediaDevice *frontent, const std::string &frontendName, - MediaDevice *backend, MediaEntity *sensorEntity); + std::shared_ptr frontend, + const std::string &frontendName, + std::shared_ptr backend, + MediaEntity *sensorEntity); void mapBuffers(Camera *camera, const BufferMap &buffers, unsigned int mask); virtual int platformRegister(std::unique_ptr &cameraData, - MediaDevice *unicam, MediaDevice *isp) = 0; + std::shared_ptr unicam, + std::shared_ptr isp) = 0; private: CameraData *cameraData(Camera *camera) diff --git a/src/libcamera/pipeline/rpi/pisp/pisp.cpp b/src/libcamera/pipeline/rpi/pisp/pisp.cpp index 91e7f4c94d96..d0cb71b49e11 100644 --- a/src/libcamera/pipeline/rpi/pisp/pisp.cpp +++ b/src/libcamera/pipeline/rpi/pisp/pisp.cpp @@ -866,7 +866,8 @@ private: int prepareBuffers(Camera *camera) override; int platformRegister(std::unique_ptr &cameraData, - MediaDevice *cfe, MediaDevice *isp) override; + std::shared_ptr cfe, + std::shared_ptr isp) override; }; bool PipelineHandlerPiSP::match(DeviceEnumerator *enumerator) @@ -884,7 +885,7 @@ bool PipelineHandlerPiSP::match(DeviceEnumerator *enumerator) cfe.add("rp1-cfe-fe-image0"); cfe.add("rp1-cfe-fe-stats"); cfe.add("rp1-cfe-fe-config"); - MediaDevice *cfeDevice = acquireMediaDevice(enumerator, cfe); + std::shared_ptr cfeDevice = acquireMediaDevice(enumerator, cfe); if (!cfeDevice) { LOG(RPI, Debug) << "Unable to acquire a CFE instance"; @@ -900,7 +901,7 @@ bool PipelineHandlerPiSP::match(DeviceEnumerator *enumerator) isp.add("pispbe-tdn_input"); isp.add("pispbe-stitch_output"); isp.add("pispbe-stitch_input"); - MediaDevice *ispDevice = acquireMediaDevice(enumerator, isp); + std::shared_ptr ispDevice = acquireMediaDevice(enumerator, isp); if (!ispDevice) { LOG(RPI, Debug) << "Unable to acquire ISP instance"; @@ -1065,7 +1066,8 @@ int PipelineHandlerPiSP::prepareBuffers(Camera *camera) } int PipelineHandlerPiSP::platformRegister(std::unique_ptr &cameraData, - MediaDevice *cfe, MediaDevice *isp) + std::shared_ptr cfe, + std::shared_ptr isp) { PiSPCameraData *data = static_cast(cameraData.get()); int ret; diff --git a/src/libcamera/pipeline/rpi/vc4/vc4.cpp b/src/libcamera/pipeline/rpi/vc4/vc4.cpp index fe910bdf2ff9..d58035ecd198 100644 --- a/src/libcamera/pipeline/rpi/vc4/vc4.cpp +++ b/src/libcamera/pipeline/rpi/vc4/vc4.cpp @@ -5,6 +5,8 @@ * Pipeline handler for VC4-based Raspberry Pi devices */ +#include + #include #include #include @@ -158,7 +160,8 @@ private: int prepareBuffers(Camera *camera) override; int platformRegister(std::unique_ptr &cameraData, - MediaDevice *unicam, MediaDevice *isp) override; + std::shared_ptr unicam, + std::shared_ptr isp) override; }; bool PipelineHandlerVc4::match(DeviceEnumerator *enumerator) @@ -173,7 +176,7 @@ bool PipelineHandlerVc4::match(DeviceEnumerator *enumerator) */ for (unsigned int i = 0; i < numUnicamDevices; i++) { DeviceMatch unicam("unicam"); - MediaDevice *unicamDevice = acquireMediaDevice(enumerator, unicam); + std::shared_ptr unicamDevice = acquireMediaDevice(enumerator, unicam); if (!unicamDevice) { LOG(RPI, Debug) << "Unable to acquire a Unicam instance"; @@ -181,7 +184,7 @@ bool PipelineHandlerVc4::match(DeviceEnumerator *enumerator) } DeviceMatch isp("bcm2835-isp"); - MediaDevice *ispDevice = acquireMediaDevice(enumerator, isp); + std::shared_ptr ispDevice = acquireMediaDevice(enumerator, isp); if (!ispDevice) { LOG(RPI, Debug) << "Unable to acquire ISP instance"; @@ -303,7 +306,9 @@ int PipelineHandlerVc4::prepareBuffers(Camera *camera) return 0; } -int PipelineHandlerVc4::platformRegister(std::unique_ptr &cameraData, MediaDevice *unicam, MediaDevice *isp) +int PipelineHandlerVc4::platformRegister(std::unique_ptr &cameraData, + std::shared_ptr unicam, + std::shared_ptr isp) { Vc4CameraData *data = static_cast(cameraData.get()); diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 451491f5608e..feaa16094b65 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -407,7 +407,7 @@ public: V4L2VideoDevice *video(const MediaEntity *entity); V4L2Subdevice *subdev(const MediaEntity *entity); - MediaDevice *converter() { return converter_; } + MediaDevice *converter() { return converter_.get(); } bool swIspEnabled() const { return swIspEnabled_; } protected: @@ -427,7 +427,8 @@ private: return static_cast(camera->_d()); } - bool matchDevice(MediaDevice *media, const SimplePipelineInfo &info, + bool matchDevice(std::shared_ptr media, + const SimplePipelineInfo &info, DeviceEnumerator *enumerator); std::vector locateSensors(MediaDevice *media); @@ -438,7 +439,7 @@ private: std::map entities_; - MediaDevice *converter_; + std::shared_ptr converter_; bool swIspEnabled_; }; @@ -1663,7 +1664,7 @@ int SimplePipelineHandler::resetRoutingTable(V4L2Subdevice *subdev) return 0; } -bool SimplePipelineHandler::matchDevice(MediaDevice *media, +bool SimplePipelineHandler::matchDevice(std::shared_ptr media, const SimplePipelineInfo &info, DeviceEnumerator *enumerator) { @@ -1681,7 +1682,7 @@ bool SimplePipelineHandler::matchDevice(MediaDevice *media, swIspEnabled_ = info.swIspEnabled; /* Locate the sensors. */ - std::vector sensors = locateSensors(media); + std::vector sensors = locateSensors(media.get()); if (sensors.empty()) { LOG(SimplePipeline, Info) << "No sensor found for " << media->deviceNode(); return false; @@ -1799,7 +1800,7 @@ bool SimplePipelineHandler::matchDevice(MediaDevice *media, bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) { - MediaDevice *media; + std::shared_ptr media; for (const SimplePipelineInfo &inf : supportedDevices) { DeviceMatch dm(inf.driver); diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 5adc89fdb29c..a1e036a32d5f 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -46,7 +46,7 @@ public: { } - int init(MediaDevice *media); + int init(std::shared_ptr media); void addControl(uint32_t cid, const ControlInfo &v4l2info, ControlInfoMap::Map *ctrls); void imageBufferReady(FrameBuffer *buffer); @@ -449,7 +449,7 @@ int PipelineHandlerUVC::queueRequestDevice(Camera *camera, Request *request) bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) { - MediaDevice *media; + std::shared_ptr media; DeviceMatch dm("uvcvideo"); media = acquireMediaDevice(enumerator, dm); @@ -491,7 +491,7 @@ void PipelineHandlerUVC::releaseDevice(Camera *camera) data->video_->close(); } -int UVCCameraData::init(MediaDevice *media) +int UVCCameraData::init(std::shared_ptr media) { int ret; diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index 07273bd2b6c3..59c564b8a9f6 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -49,7 +49,7 @@ LOG_DEFINE_CATEGORY(VIMC) class VimcCameraData : public Camera::Private { public: - VimcCameraData(PipelineHandler *pipe, MediaDevice *media) + VimcCameraData(PipelineHandler *pipe, std::shared_ptr media) : Camera::Private(pipe), media_(media) { } @@ -59,7 +59,7 @@ public: void imageBufferReady(FrameBuffer *buffer); void paramsComputed(unsigned int id, const Flags flags); - MediaDevice *media_; + std::shared_ptr media_; std::unique_ptr sensor_; std::unique_ptr debayer_; std::unique_ptr scaler_; @@ -476,7 +476,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator) dm.add("RGB/YUV Input"); dm.add("Scaler"); - MediaDevice *media = acquireMediaDevice(enumerator, dm); + std::shared_ptr media = acquireMediaDevice(enumerator, dm); if (!media) return false; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 8f12957b75fa..5fe2c64c8bc6 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -125,10 +125,12 @@ PipelineHandler::~PipelineHandler() * * \context This function shall be called from the CameraManager thread. * - * \return A pointer to the matching MediaDevice, or nullptr if no match is found + * \return A shared pointer to the matching MediaDevice, or nullptr if no match + * is found */ -MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator, - const DeviceMatch &dm) +std::shared_ptr +PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator, + const DeviceMatch &dm) { std::shared_ptr media = enumerator->search(dm); if (!media) @@ -139,7 +141,7 @@ MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator, mediaDevices_.push_back(media); - return media.get(); + return media; } /** @@ -712,7 +714,7 @@ void PipelineHandler::registerCamera(std::shared_ptr camera) * handler gets notified and automatically disconnects all the cameras it has * registered without requiring any manual intervention. */ -void PipelineHandler::hotplugMediaDevice(MediaDevice *media) +void PipelineHandler::hotplugMediaDevice(std::shared_ptr media) { media->disconnected.connect(this, [this, media] { mediaDeviceDisconnected(media); }); } @@ -720,7 +722,7 @@ void PipelineHandler::hotplugMediaDevice(MediaDevice *media) /** * \brief Slot for the MediaDevice disconnected signal */ -void PipelineHandler::mediaDeviceDisconnected(MediaDevice *media) +void PipelineHandler::mediaDeviceDisconnected(std::shared_ptr media) { media->disconnected.disconnect(this); diff --git a/test/delayed_controls.cpp b/test/delayed_controls.cpp index 7bd30e7aead8..b305be48aafc 100644 --- a/test/delayed_controls.cpp +++ b/test/delayed_controls.cpp @@ -47,7 +47,7 @@ protected: return TestSkip; } - dev_ = V4L2VideoDevice::fromEntityName(media_.get(), "vivid-000-vid-cap"); + dev_ = V4L2VideoDevice::fromEntityName(media_, "vivid-000-vid-cap"); if (dev_->open()) { cerr << "Failed to open video device" << endl; return TestFail; diff --git a/test/libtest/buffer_source.cpp b/test/libtest/buffer_source.cpp index dde11f365e43..19b25fed50a0 100644 --- a/test/libtest/buffer_source.cpp +++ b/test/libtest/buffer_source.cpp @@ -52,7 +52,7 @@ int BufferSource::allocate(const StreamConfiguration &config) return TestSkip; } - std::unique_ptr video = V4L2VideoDevice::fromEntityName(media_.get(), videoDeviceName); + std::unique_ptr video = V4L2VideoDevice::fromEntityName(media_, videoDeviceName); if (!video) { std::cout << "Failed to get video device from entity " << videoDeviceName << std::endl; From patchwork Fri Apr 4 07:46:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 23137 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 393CBC3213 for ; Fri, 4 Apr 2025 07:46:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E13F668994; Fri, 4 Apr 2025 09:46:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="k3luEyQy"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 60D70689A7 for ; Fri, 4 Apr 2025 09:46:40 +0200 (CEST) Received: from neptunite.flets-east.jp (unknown [IPv6:2404:7a81:160:2100:cd45:d129:c842:b4ce]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 009A8E7C; Fri, 4 Apr 2025 09:44:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1743752686; bh=93RY5jnnnjYjjAm+2P+LXmX/6tBKmI3TYg5wKctvC+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k3luEyQyP1JuX68lQuvxU05NTOA0MOlzcwOCej0ZEzAW4iaUQq3vDoa4oqMDtpfxq 5pxdBQaUQbCB+BLm3cLiPyIgBAFqqAPn6lncpP95Rkdxd0D+YhtAk5Knlixyw8JF7c D08vK4L80XCK47pMPn4d3zDAOVDbBcGOhHv9wpuE= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Paul Elder Subject: [PATCH 3/3] libcamera: v4l2: Remove fromEntityName(MediaDevice*) Date: Fri, 4 Apr 2025 16:46:23 +0900 Message-ID: <20250404074624.2975182-4-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250404074624.2975182-1-paul.elder@ideasonboard.com> References: <20250404074624.2975182-1-paul.elder@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" From: Kieran Bingham Now that all users of the fromEntityName() helpers use the shared_ptr variant, remove the original functions that are no longer used. Signed-off-by: Kieran Bingham Signed-off-by: Paul Elder --- include/libcamera/internal/v4l2_subdevice.h | 2 -- include/libcamera/internal/v4l2_videodevice.h | 2 -- src/libcamera/v4l2_subdevice.cpp | 17 +---------------- src/libcamera/v4l2_videodevice.cpp | 17 +---------------- 4 files changed, 2 insertions(+), 36 deletions(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 08216cd56bc3..1ad21fdc6a27 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -161,8 +161,6 @@ public: const std::string &model(); const V4L2SubdeviceCapability &caps() const { return caps_; } - static std::unique_ptr - fromEntityName(const MediaDevice *media, const std::string &entity); static std::unique_ptr fromEntityName(std::shared_ptr, const std::string &entity); diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index e35fb11bc99f..640990e279e2 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -226,8 +226,6 @@ public: void setDequeueTimeout(utils::Duration timeout); Signal<> dequeueTimeout; - static std::unique_ptr - fromEntityName(const MediaDevice *media, const std::string &entity); static std::unique_ptr fromEntityName(std::shared_ptr, const std::string &entity); diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 13f5316a3fc3..305a1b0f1bae 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -1756,7 +1756,7 @@ const std::string &V4L2Subdevice::model() * \return A newly created V4L2Subdevice on success, nullptr otherwise */ std::unique_ptr -V4L2Subdevice::fromEntityName(const MediaDevice *media, +V4L2Subdevice::fromEntityName(std::shared_ptr media, const std::string &entity) { MediaEntity *mediaEntity = media->getEntityByName(entity); @@ -1766,21 +1766,6 @@ V4L2Subdevice::fromEntityName(const MediaDevice *media, return std::make_unique(mediaEntity); } -/** - * \brief Create a new video subdevice instance from \a entity in media device - * \a media - * \param[in] media The media device where the entity is registered - * \param[in] entity The media entity name - * - * \return A newly created V4L2Subdevice on success, nullptr otherwise - */ -std::unique_ptr -V4L2Subdevice::fromEntityName(std::shared_ptr media, - const std::string &entity) -{ - return fromEntityName(media.get(), entity); -} - std::string V4L2Subdevice::logPrefix() const { return "'" + entity_->name() + "'"; diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index ce7be7deb91f..9769243de8cc 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -2099,7 +2099,7 @@ void V4L2VideoDevice::watchdogExpired() * \return A newly created V4L2VideoDevice on success, nullptr otherwise */ std::unique_ptr -V4L2VideoDevice::fromEntityName(const MediaDevice *media, +V4L2VideoDevice::fromEntityName(std::shared_ptr media, const std::string &entity) { MediaEntity *mediaEntity = media->getEntityByName(entity); @@ -2109,21 +2109,6 @@ V4L2VideoDevice::fromEntityName(const MediaDevice *media, return std::make_unique(mediaEntity); } -/** - * \brief Create a new video device instance from \a entity in media device - * \a media - * \param[in] media The media device where the entity is registered - * \param[in] entity The media entity name - * - * \return A newly created V4L2VideoDevice on success, nullptr otherwise - */ -std::unique_ptr -V4L2VideoDevice::fromEntityName(std::shared_ptr media, - const std::string &entity) -{ - return fromEntityName(media.get(), entity); -} - /** * \brief Convert \a PixelFormat to a V4L2PixelFormat supported by the device * \param[in] pixelFormat The PixelFormat to convert