From patchwork Sun Dec 15 23:02:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 22326 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 D339BC32F6 for ; Sun, 15 Dec 2024 23:02:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3960867F42; Mon, 16 Dec 2024 00:02:40 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cxGMXoSw"; 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 0E6D367F3C for ; Mon, 16 Dec 2024 00:02:31 +0100 (CET) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A91E22C6; Mon, 16 Dec 2024 00:01:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1734303715; bh=tCzOv7ynYDErg4/AoDhNXCoBUptU08pA90XBObCwPJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cxGMXoSwHdIym1o0+5+uy2VQOPitPvT8S3Qf4mvdBRixgMEXGUuJRUfo+U5I3ajeO v1m+HjCn/ec2IByvxR+Zi6wPcM2Encrkc6pX+eD6zBNV4rPGAZo6YPv2CwG+sgfz8J E8MZ864d5FaImFKycSLYy3kelA8KiTxZJ76lLdzo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH 6/8] libcamera: Update string usage in internal APIs Date: Mon, 16 Dec 2024 01:02:04 +0200 Message-ID: <20241215230206.11002-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241215230206.11002-1-laurent.pinchart@ideasonboard.com> References: <20241215230206.11002-1-laurent.pinchart@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" Follow the string usage guidelines documented in the libcamera coding style in most of the internal APIs. This showcases usage of std::string_view where applicable. The rationale is explained in the guidelines. Signed-off-by: Laurent Pinchart --- .../internal/camera_sensor_properties.h | 4 ++-- include/libcamera/internal/converter.h | 3 ++- .../internal/converter/converter_v4l2_m2m.h | 3 +-- include/libcamera/internal/device_enumerator.h | 8 ++++---- include/libcamera/internal/formats.h | 3 ++- include/libcamera/internal/ipa_module.h | 3 ++- include/libcamera/internal/ipa_proxy.h | 7 ++++--- include/libcamera/internal/media_device.h | 9 +++++---- include/libcamera/internal/pipeline_handler.h | 7 ++++--- .../internal/software_isp/software_isp.h | 4 ++-- include/libcamera/internal/sysfs.h | 3 ++- include/libcamera/internal/v4l2_device.h | 3 ++- include/libcamera/internal/v4l2_subdevice.h | 3 ++- include/libcamera/internal/v4l2_videodevice.h | 7 ++++--- src/libcamera/device_enumerator.cpp | 10 +++++----- src/libcamera/formats.cpp | 2 +- src/libcamera/ipa_module.cpp | 2 +- src/libcamera/ipa_proxy.cpp | 8 ++++---- src/libcamera/media_device.cpp | 16 ++++++++-------- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 3 ++- src/libcamera/pipeline_handler.cpp | 6 +++--- .../sensor/camera_sensor_properties.cpp | 4 ++-- src/libcamera/software_isp/software_isp.cpp | 3 ++- src/libcamera/sysfs.cpp | 8 +++++--- src/libcamera/v4l2_device.cpp | 2 +- src/libcamera/v4l2_subdevice.cpp | 3 +-- src/libcamera/v4l2_videodevice.cpp | 7 +++---- 27 files changed, 76 insertions(+), 65 deletions(-) diff --git a/include/libcamera/internal/camera_sensor_properties.h b/include/libcamera/internal/camera_sensor_properties.h index d7d4dab626df7b82..b44093906d6390c0 100644 --- a/include/libcamera/internal/camera_sensor_properties.h +++ b/include/libcamera/internal/camera_sensor_properties.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include @@ -24,7 +24,7 @@ struct CameraSensorProperties { uint8_t hblankDelay; }; - static const CameraSensorProperties *get(const std::string &sensor); + static const CameraSensorProperties *get(std::string_view sensor); Size unitCellSize; std::map testPatternModes; diff --git a/include/libcamera/internal/converter.h b/include/libcamera/internal/converter.h index ffbb6f345cd5ed4f..fb8d81898e90bcb8 100644 --- a/include/libcamera/internal/converter.h +++ b/include/libcamera/internal/converter.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -44,7 +45,7 @@ public: Converter(MediaDevice *media, Features features = Feature::None); virtual ~Converter(); - virtual int loadConfiguration(const std::string &filename) = 0; + virtual int loadConfiguration(std::string_view filename) = 0; virtual bool isValid() const = 0; diff --git a/include/libcamera/internal/converter/converter_v4l2_m2m.h b/include/libcamera/internal/converter/converter_v4l2_m2m.h index 0bc0d053e2c47d3a..5475cc6b3ac58b30 100644 --- a/include/libcamera/internal/converter/converter_v4l2_m2m.h +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h @@ -11,7 +11,6 @@ #include #include #include -#include #include #include @@ -38,7 +37,7 @@ class V4L2M2MConverter : public Converter public: V4L2M2MConverter(MediaDevice *media); - int loadConfiguration([[maybe_unused]] const std::string &filename) { return 0; } + int loadConfiguration([[maybe_unused]] std::string_view filename) { return 0; } bool isValid() const { return m2m_ != nullptr; } std::vector formats(PixelFormat input); diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h index db3532a9887af913..c3a09f03433729c4 100644 --- a/include/libcamera/internal/device_enumerator.h +++ b/include/libcamera/internal/device_enumerator.h @@ -20,9 +20,9 @@ class MediaDevice; class DeviceMatch { public: - DeviceMatch(const std::string &driver); + DeviceMatch(std::string_view driver); - void add(const std::string &entity); + void add(std::string_view entity); bool match(const MediaDevice *device) const; @@ -46,9 +46,9 @@ public: Signal<> devicesAdded; protected: - std::unique_ptr createDevice(const std::string &deviceNode); + std::unique_ptr createDevice(std::string_view deviceNode); void addDevice(std::unique_ptr media); - void removeDevice(const std::string &deviceNode); + void removeDevice(std::string_view deviceNode); private: std::vector> devices_; diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h index 6a3e9c16a873e969..bd7ac6ed128f594b 100644 --- a/include/libcamera/internal/formats.h +++ b/include/libcamera/internal/formats.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include @@ -35,7 +36,7 @@ public: static const PixelFormatInfo &info(const PixelFormat &format); static const PixelFormatInfo &info(const V4L2PixelFormat &format); - static const PixelFormatInfo &info(const std::string &name); + static const PixelFormatInfo &info(std::string_view name); unsigned int stride(unsigned int width, unsigned int plane, unsigned int align = 1) const; diff --git a/include/libcamera/internal/ipa_module.h b/include/libcamera/internal/ipa_module.h index 7c49d3f342e5055c..5f7c7e6e9f6987a0 100644 --- a/include/libcamera/internal/ipa_module.h +++ b/include/libcamera/internal/ipa_module.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -23,7 +24,7 @@ namespace libcamera { class IPAModule : public Loggable { public: - explicit IPAModule(const std::string &libPath); + explicit IPAModule(std::string_view libPath); ~IPAModule(); bool isValid() const; diff --git a/include/libcamera/internal/ipa_proxy.h b/include/libcamera/internal/ipa_proxy.h index 983bcc5faa4bab3b..93b3b991f8d4b80e 100644 --- a/include/libcamera/internal/ipa_proxy.h +++ b/include/libcamera/internal/ipa_proxy.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include @@ -29,11 +30,11 @@ public: bool isValid() const { return valid_; } - std::string configurationFile(const std::string &name, - const std::string &fallbackName = std::string()) const; + std::string configurationFile(std::string_view name, + std::string_view fallbackName = {}) const; protected: - std::string resolvePath(const std::string &file) const; + std::string resolvePath(std::string_view file) const; bool valid_; ProxyState state_; diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h index e412d3a0b7e38cd3..1882b9aeb87f533a 100644 --- a/include/libcamera/internal/media_device.h +++ b/include/libcamera/internal/media_device.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -24,7 +25,7 @@ namespace libcamera { class MediaDevice : protected Loggable { public: - MediaDevice(const std::string &deviceNode); + MediaDevice(std::string_view deviceNode); ~MediaDevice(); bool acquire(); @@ -44,10 +45,10 @@ public: unsigned int hwRevision() const { return hwRevision_; } const std::vector &entities() const { return entities_; } - MediaEntity *getEntityByName(const std::string &name) const; + MediaEntity *getEntityByName(std::string_view name) const; - MediaLink *link(const std::string &sourceName, unsigned int sourceIdx, - const std::string &sinkName, unsigned int sinkIdx); + MediaLink *link(std::string_view sourceName, unsigned int sourceIdx, + std::string_view sinkName, unsigned int sinkIdx); MediaLink *link(const MediaEntity *source, unsigned int sourceIdx, const MediaEntity *sink, unsigned int sinkIdx); MediaLink *link(const MediaPad *source, const MediaPad *sink); diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index fb28a18d0f4668ab..f91d1c6cba842f49 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -62,8 +63,8 @@ public: void completeRequest(Request *request); void cancelRequest(Request *request); - std::string configurationFile(const std::string &subdir, - const std::string &name) const; + std::string configurationFile(std::string_view subdir, + std::string_view name) const; const char *name() const { return name_; } @@ -112,7 +113,7 @@ public: const std::string &name() const { return name_; } static std::vector &factories(); - static const PipelineHandlerFactoryBase *getFactoryByName(const std::string &name); + static const PipelineHandlerFactoryBase *getFactoryByName(std::string_view name); private: static void registerType(PipelineHandlerFactoryBase *factory); diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h index d51b03fd6cd71fce..bc4eb36260e93fbc 100644 --- a/include/libcamera/internal/software_isp/software_isp.h +++ b/include/libcamera/internal/software_isp/software_isp.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include @@ -50,7 +50,7 @@ public: ControlInfoMap *ipaControls); ~SoftwareIsp(); - int loadConfiguration([[maybe_unused]] const std::string &filename) { return 0; } + int loadConfiguration([[maybe_unused]] std::string_view filename) { return 0; } bool isValid() const; diff --git a/include/libcamera/internal/sysfs.h b/include/libcamera/internal/sysfs.h index aca60fb6c8ab9a2c..db78d790f3ff23bd 100644 --- a/include/libcamera/internal/sysfs.h +++ b/include/libcamera/internal/sysfs.h @@ -8,6 +8,7 @@ #pragma once #include +#include namespace libcamera { @@ -15,7 +16,7 @@ namespace sysfs { std::string charDevPath(const std::string &deviceNode); -std::string firmwareNodePath(const std::string &device); +std::string firmwareNodePath(std::string_view device); } /* namespace sysfs */ diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index f5aa502482017325..623403dc615ea604 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -50,7 +51,7 @@ public: void updateControlInfo(); protected: - V4L2Device(const std::string &deviceNode); + V4L2Device(std::string_view deviceNode); ~V4L2Device(); int open(unsigned int flags); diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 194382f84d97fbbc..d17365e14a231df3 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -161,7 +162,7 @@ public: const V4L2SubdeviceCapability &caps() const { return caps_; } static std::unique_ptr - fromEntityName(const MediaDevice *media, const std::string &entity); + fromEntityName(const MediaDevice *media, std::string_view entity); protected: std::string logPrefix() const override; diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index f021c2a0177b4512..45443ed716d7f6f2 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -189,7 +190,7 @@ class V4L2VideoDevice : public V4L2Device public: using Formats = std::map>; - explicit V4L2VideoDevice(const std::string &deviceNode); + explicit V4L2VideoDevice(std::string_view deviceNode); explicit V4L2VideoDevice(const MediaEntity *entity); ~V4L2VideoDevice(); @@ -228,7 +229,7 @@ public: Signal<> dequeueTimeout; static std::unique_ptr - fromEntityName(const MediaDevice *media, const std::string &entity); + fromEntityName(const MediaDevice *media, std::string_view entity); V4L2PixelFormat toV4L2PixelFormat(const PixelFormat &pixelFormat) const; @@ -295,7 +296,7 @@ private: class V4L2M2MDevice { public: - V4L2M2MDevice(const std::string &deviceNode); + V4L2M2MDevice(std::string_view deviceNode); ~V4L2M2MDevice(); int open(); diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index ae17862f676310ef..1efc5b33639f6af8 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -67,7 +67,7 @@ LOG_DEFINE_CATEGORY(DeviceEnumerator) * \brief Construct a media device search pattern * \param[in] driver The Linux device driver name that created the media device */ -DeviceMatch::DeviceMatch(const std::string &driver) +DeviceMatch::DeviceMatch(std::string_view driver) : driver_(driver) { } @@ -76,9 +76,9 @@ DeviceMatch::DeviceMatch(const std::string &driver) * \brief Add a media entity name to the search pattern * \param[in] entity The name of the entity in the media graph */ -void DeviceMatch::add(const std::string &entity) +void DeviceMatch::add(std::string_view entity) { - entities_.push_back(entity); + entities_.push_back(std::string(entity)); } /** @@ -215,7 +215,7 @@ DeviceEnumerator::~DeviceEnumerator() * * \return Created media device instance on success, or nullptr otherwise */ -std::unique_ptr DeviceEnumerator::createDevice(const std::string &deviceNode) +std::unique_ptr DeviceEnumerator::createDevice(std::string_view deviceNode) { std::unique_ptr media = std::make_unique(deviceNode); @@ -272,7 +272,7 @@ void DeviceEnumerator::addDevice(std::unique_ptr media) * enumerator with addDevice(). The media device's MediaDevice::disconnected * signal is emitted. */ -void DeviceEnumerator::removeDevice(const std::string &deviceNode) +void DeviceEnumerator::removeDevice(std::string_view deviceNode) { std::shared_ptr media; diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index bfcdfc08960dbbad..112dfe66b4747516 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -1037,7 +1037,7 @@ const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format) * \return The PixelFormatInfo describing the PixelFormat matching the * \a name if known, or an invalid PixelFormatInfo otherwise */ -const PixelFormatInfo &PixelFormatInfo::info(const std::string &name) +const PixelFormatInfo &PixelFormatInfo::info(std::string_view name) { for (const auto &info : pixelFormatInfo) { if (info.second.name == name) diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp index 9ca74be6e100a8fa..90e3148d236f3a3c 100644 --- a/src/libcamera/ipa_module.cpp +++ b/src/libcamera/ipa_module.cpp @@ -254,7 +254,7 @@ Span elfLoadSymbol(Span elf, const char *symbol) * The caller shall call the isValid() function after constructing an * IPAModule instance to verify the validity of the IPAModule. */ -IPAModule::IPAModule(const std::string &libPath) +IPAModule::IPAModule(std::string_view libPath) : libPath_(libPath), valid_(false), loaded_(false), dlHandle_(nullptr), ipaCreate_(nullptr) { diff --git a/src/libcamera/ipa_proxy.cpp b/src/libcamera/ipa_proxy.cpp index 85004737c17100bf..a06bd94ff435021e 100644 --- a/src/libcamera/ipa_proxy.cpp +++ b/src/libcamera/ipa_proxy.cpp @@ -95,8 +95,8 @@ IPAProxy::~IPAProxy() * \return The full path to the IPA configuration file, or an empty string if * no configuration file can be found */ -std::string IPAProxy::configurationFile(const std::string &name, - const std::string &fallbackName) const +std::string IPAProxy::configurationFile(std::string_view name, + std::string_view fallbackName) const { struct stat statbuf; int ret; @@ -178,9 +178,9 @@ std::string IPAProxy::configurationFile(const std::string &name, * \return The full path to the proxy worker executable, or an empty string if * no valid executable path */ -std::string IPAProxy::resolvePath(const std::string &file) const +std::string IPAProxy::resolvePath(std::string_view file) const { - std::string proxyFile = "/" + file; + std::string proxyFile = std::string("/") + file; /* Check env variable first. */ const char *execPaths = utils::secure_getenv("LIBCAMERA_IPA_PROXY_PATH"); diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index d71dad74df70d1fc..34f2a78fcc287066 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -62,7 +62,7 @@ LOG_DEFINE_CATEGORY(MediaDevice) * Once constructed the media device is invalid, and must be populated with * populate() before the media graph can be queried. */ -MediaDevice::MediaDevice(const std::string &deviceNode) +MediaDevice::MediaDevice(std::string_view deviceNode) : deviceNode_(deviceNode), valid_(false), acquired_(false) { } @@ -331,7 +331,7 @@ done: * \param[in] name The entity name * \return The entity with \a name, or nullptr if no such entity is found */ -MediaEntity *MediaDevice::getEntityByName(const std::string &name) const +MediaEntity *MediaDevice::getEntityByName(std::string_view name) const { for (MediaEntity *e : entities_) if (e->name() == name) @@ -359,8 +359,8 @@ MediaEntity *MediaDevice::getEntityByName(const std::string &name) const * \return The link that connects the two pads, or nullptr if no such a link * exists */ -MediaLink *MediaDevice::link(const std::string &sourceName, unsigned int sourceIdx, - const std::string &sinkName, unsigned int sinkIdx) +MediaLink *MediaDevice::link(std::string_view sourceName, unsigned int sourceIdx, + std::string_view sinkName, unsigned int sinkIdx) { const MediaEntity *source = getEntityByName(sourceName); const MediaEntity *sink = getEntityByName(sinkName); @@ -382,8 +382,8 @@ MediaLink *MediaDevice::link(const std::string &sourceName, unsigned int sourceI * entity \a source, to the pad at index \a sinkIdx of the sink entity \a * sink, if any. * - * \sa link(const std::string &sourceName, unsigned int sourceIdx, - * const std::string &sinkName, unsigned int sinkIdx) + * \sa link(std::string_view sourceName, unsigned int sourceIdx, + * std::string_view sinkName, unsigned int sinkIdx) * \sa link(const MediaPad *source, const MediaPad *sink) * * \return The link that connects the two pads, or nullptr if no such a link @@ -406,8 +406,8 @@ MediaLink *MediaDevice::link(const MediaEntity *source, unsigned int sourceIdx, * \param[in] source The source pad * \param[in] sink The sink pad * - * \sa link(const std::string &sourceName, unsigned int sourceIdx, - * const std::string &sinkName, unsigned int sinkIdx) + * \sa link(std::string_view sourceName, unsigned int sourceIdx, + * std::string_view sinkName, unsigned int sinkIdx) * \sa link(const MediaEntity *source, unsigned int sourceIdx, * const MediaEntity *sink, unsigned int sinkIdx) * diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 8c2c6baf35751d64..51a32316b7008790 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -571,7 +572,7 @@ bool UVCCameraData::generateId() /* Create a controller ID from first device described in firmware. */ std::string controllerId; - std::string searchPath = path; + std::string_view searchPath{ path }; while (true) { std::string::size_type pos = searchPath.rfind('/'); if (pos <= 1) { diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index caa5c20e74836956..4cf9e8256503efac 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -595,8 +595,8 @@ void PipelineHandler::cancelRequest(Request *request) * \return The full path to the pipeline handler configuration file, or an empty * string if no configuration file can be found */ -std::string PipelineHandler::configurationFile(const std::string &subdir, - const std::string &name) const +std::string PipelineHandler::configurationFile(std::string_view subdir, + std::string_view name) const { std::string confPath; struct stat statbuf; @@ -852,7 +852,7 @@ std::vector &PipelineHandlerFactoryBase::factories * \param[in] name The pipeline handler name * \return The factory of the pipeline with name \a name, or nullptr if not found */ -const PipelineHandlerFactoryBase *PipelineHandlerFactoryBase::getFactoryByName(const std::string &name) +const PipelineHandlerFactoryBase *PipelineHandlerFactoryBase::getFactoryByName(std::string_view name) { const std::vector &factories = PipelineHandlerFactoryBase::factories(); diff --git a/src/libcamera/sensor/camera_sensor_properties.cpp b/src/libcamera/sensor/camera_sensor_properties.cpp index 2b06c5a1a5d15abd..4283cacfa5e0b44a 100644 --- a/src/libcamera/sensor/camera_sensor_properties.cpp +++ b/src/libcamera/sensor/camera_sensor_properties.cpp @@ -78,9 +78,9 @@ LOG_DEFINE_CATEGORY(CameraSensorProperties) * \return A pointer to the CameraSensorProperties instance associated with a sensor * or nullptr if the sensor is not supported */ -const CameraSensorProperties *CameraSensorProperties::get(const std::string &sensor) +const CameraSensorProperties *CameraSensorProperties::get(std::string_view sensor) { - static const std::map sensorProps = { + static const std::map sensorProps = { { "ar0144", { .unitCellSize = { 3000, 3000 }, .testPatternModes = { diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp index 2bea64d9f9947e09..5ca215ed4d5c6abc 100644 --- a/src/libcamera/software_isp/software_isp.cpp +++ b/src/libcamera/software_isp/software_isp.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -148,7 +149,7 @@ SoftwareIsp::~SoftwareIsp() } /** - * \fn int SoftwareIsp::loadConfiguration([[maybe_unused]] const std::string &filename) + * \fn int SoftwareIsp::loadConfiguration([[maybe_unused]] std::string_view filename) * \brief Load a configuration from a file * \param[in] filename The file to load the configuration data from * diff --git a/src/libcamera/sysfs.cpp b/src/libcamera/sysfs.cpp index cbde72d86fd62b41..c1e2b0494e35d6bb 100644 --- a/src/libcamera/sysfs.cpp +++ b/src/libcamera/sysfs.cpp @@ -15,6 +15,8 @@ #include #include +using namespace std::literals::string_literals; + /** * \file sysfs.h * \brief Miscellaneous utility functions to access sysfs @@ -67,13 +69,13 @@ std::string charDevPath(const std::string &deviceNode) * * \return The firmware node path on success or an empty string on failure */ -std::string firmwareNodePath(const std::string &device) +std::string firmwareNodePath(std::string_view device) { std::string fwPath, node; struct stat st; /* Lookup for DT-based systems */ - node = device + "/of_node"; + node = device + "/of_node"s; if (!stat(node.c_str(), &st)) { char *ofPath = realpath(node.c_str(), nullptr); if (!ofPath) @@ -91,7 +93,7 @@ std::string firmwareNodePath(const std::string &device) } /* Lookup for ACPI-based systems */ - node = device + "/firmware_node/path"; + node = device + "/firmware_node/path"s; if (File::exists(node.c_str())) { std::ifstream file(node); if (!file.is_open()) diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 664b74afe6a12757..a8eda2d84357d355 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -56,7 +56,7 @@ LOG_DEFINE_CATEGORY(V4L2) * Initialize the file descriptor to -1 and store the \a deviceNode to be used * at open() time, and the \a logTag to prefix log messages with. */ -V4L2Device::V4L2Device(const std::string &deviceNode) +V4L2Device::V4L2Device(std::string_view deviceNode) : deviceNode_(deviceNode), fdEventNotifier_(nullptr), frameStartEnabled_(false) { diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 3a0d075f93c457d1..fece69e575b718e1 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -1687,8 +1687,7 @@ const std::string &V4L2Subdevice::model() * \return A newly created V4L2Subdevice on success, nullptr otherwise */ std::unique_ptr -V4L2Subdevice::fromEntityName(const MediaDevice *media, - const std::string &entity) +V4L2Subdevice::fromEntityName(const MediaDevice *media, std::string_view entity) { MediaEntity *mediaEntity = media->getEntityByName(entity); if (!mediaEntity) diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index a5cf67845ce3600b..91891ffb1590d5b0 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -531,7 +531,7 @@ std::ostream &operator<<(std::ostream &out, const V4L2DeviceFormat &f) * \brief Construct a V4L2VideoDevice * \param[in] deviceNode The file-system path to the video device node */ -V4L2VideoDevice::V4L2VideoDevice(const std::string &deviceNode) +V4L2VideoDevice::V4L2VideoDevice(std::string_view deviceNode) : V4L2Device(deviceNode), formatInfo_(nullptr), cache_(nullptr), fdBufferNotifier_(nullptr), state_(State::Stopped), watchdogDuration_(0.0) @@ -2076,8 +2076,7 @@ void V4L2VideoDevice::watchdogExpired() * \return A newly created V4L2VideoDevice on success, nullptr otherwise */ std::unique_ptr -V4L2VideoDevice::fromEntityName(const MediaDevice *media, - const std::string &entity) +V4L2VideoDevice::fromEntityName(const MediaDevice *media, std::string_view entity) { MediaEntity *mediaEntity = media->getEntityByName(entity); if (!mediaEntity) @@ -2160,7 +2159,7 @@ V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelForma * \brief Create a new V4L2M2MDevice from the \a deviceNode * \param[in] deviceNode The file-system path to the video device node */ -V4L2M2MDevice::V4L2M2MDevice(const std::string &deviceNode) +V4L2M2MDevice::V4L2M2MDevice(std::string_view deviceNode) : deviceNode_(deviceNode) { output_ = new V4L2VideoDevice(deviceNode);