@@ -9,7 +9,7 @@
#include <map>
#include <stdint.h>
-#include <string>
+#include <string_view>
#include <libcamera/control_ids.h>
#include <libcamera/geometry.h>
@@ -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<controls::draft::TestPatternModeEnum, int32_t> testPatternModes;
@@ -13,6 +13,7 @@
#include <map>
#include <memory>
#include <string>
+#include <string_view>
#include <tuple>
#include <utility>
#include <vector>
@@ -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;
@@ -11,7 +11,6 @@
#include <functional>
#include <map>
#include <memory>
-#include <string>
#include <tuple>
#include <vector>
@@ -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<PixelFormat> formats(PixelFormat input);
@@ -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<MediaDevice> createDevice(const std::string &deviceNode);
+ std::unique_ptr<MediaDevice> createDevice(std::string_view deviceNode);
void addDevice(std::unique_ptr<MediaDevice> media);
- void removeDevice(const std::string &deviceNode);
+ void removeDevice(std::string_view deviceNode);
private:
std::vector<std::shared_ptr<MediaDevice>> devices_;
@@ -8,6 +8,7 @@
#pragma once
#include <array>
+#include <string_view>
#include <vector>
#include <libcamera/geometry.h>
@@ -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;
@@ -9,6 +9,7 @@
#include <stdint.h>
#include <string>
+#include <string_view>
#include <vector>
#include <libcamera/base/log.h>
@@ -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;
@@ -8,6 +8,7 @@
#pragma once
#include <string>
+#include <string_view>
#include <libcamera/ipa/ipa_interface.h>
@@ -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_;
@@ -9,6 +9,7 @@
#include <map>
#include <string>
+#include <string_view>
#include <vector>
#include <linux/media.h>
@@ -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<MediaEntity *> &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);
@@ -10,6 +10,7 @@
#include <memory>
#include <queue>
#include <string>
+#include <string_view>
#include <sys/types.h>
#include <vector>
@@ -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<PipelineHandlerFactoryBase *> &factories();
- static const PipelineHandlerFactoryBase *getFactoryByName(const std::string &name);
+ static const PipelineHandlerFactoryBase *getFactoryByName(std::string_view name);
private:
static void registerType(PipelineHandlerFactoryBase *factory);
@@ -12,7 +12,7 @@
#include <map>
#include <memory>
#include <stdint.h>
-#include <string>
+#include <string_view>
#include <tuple>
#include <vector>
@@ -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;
@@ -8,6 +8,7 @@
#pragma once
#include <string>
+#include <string_view>
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 */
@@ -10,6 +10,7 @@
#include <map>
#include <memory>
#include <optional>
+#include <string_view>
#include <vector>
#include <linux/videodev2.h>
@@ -50,7 +51,7 @@ public:
void updateControlInfo();
protected:
- V4L2Device(const std::string &deviceNode);
+ V4L2Device(std::string_view deviceNode);
~V4L2Device();
int open(unsigned int flags);
@@ -11,6 +11,7 @@
#include <optional>
#include <ostream>
#include <string>
+#include <string_view>
#include <vector>
#include <linux/v4l2-subdev.h>
@@ -161,7 +162,7 @@ public:
const V4L2SubdeviceCapability &caps() const { return caps_; }
static std::unique_ptr<V4L2Subdevice>
- fromEntityName(const MediaDevice *media, const std::string &entity);
+ fromEntityName(const MediaDevice *media, std::string_view entity);
protected:
std::string logPrefix() const override;
@@ -14,6 +14,7 @@
#include <ostream>
#include <stdint.h>
#include <string>
+#include <string_view>
#include <unordered_set>
#include <vector>
@@ -189,7 +190,7 @@ class V4L2VideoDevice : public V4L2Device
public:
using Formats = std::map<V4L2PixelFormat, std::vector<SizeRange>>;
- 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<V4L2VideoDevice>
- 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();
@@ -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<MediaDevice> DeviceEnumerator::createDevice(const std::string &deviceNode)
+std::unique_ptr<MediaDevice> DeviceEnumerator::createDevice(std::string_view deviceNode)
{
std::unique_ptr<MediaDevice> media = std::make_unique<MediaDevice>(deviceNode);
@@ -272,7 +272,7 @@ void DeviceEnumerator::addDevice(std::unique_ptr<MediaDevice> 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<MediaDevice> media;
@@ -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)
@@ -254,7 +254,7 @@ Span<const uint8_t> elfLoadSymbol(Span<const uint8_t> 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)
{
@@ -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");
@@ -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)
*
@@ -12,6 +12,7 @@
#include <memory>
#include <set>
#include <string>
+#include <string_view>
#include <vector>
#include <libcamera/base/log.h>
@@ -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) {
@@ -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 *> &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<PipelineHandlerFactoryBase *> &factories =
PipelineHandlerFactoryBase::factories();
@@ -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<std::string, const CameraSensorProperties> sensorProps = {
+ static const std::map<std::string_view, const CameraSensorProperties> sensorProps = {
{ "ar0144", {
.unitCellSize = { 3000, 3000 },
.testPatternModes = {
@@ -9,6 +9,7 @@
#include <cmath>
#include <stdint.h>
+#include <string>
#include <sys/mman.h>
#include <sys/types.h>
#include <unistd.h>
@@ -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
*
@@ -15,6 +15,8 @@
#include <libcamera/base/file.h>
#include <libcamera/base/log.h>
+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())
@@ -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)
{
@@ -1687,8 +1687,7 @@ const std::string &V4L2Subdevice::model()
* \return A newly created V4L2Subdevice on success, nullptr otherwise
*/
std::unique_ptr<V4L2Subdevice>
-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)
@@ -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>
-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);
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 <laurent.pinchart@ideasonboard.com> --- .../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(-)