diff options
Diffstat (limited to 'src/libcamera/v4l2_subdevice.cpp')
-rw-r--r-- | src/libcamera/v4l2_subdevice.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 023e2328..61e15b69 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -9,6 +9,7 @@ #include <fcntl.h> #include <iomanip> +#include <regex> #include <sstream> #include <string.h> #include <sys/ioctl.h> @@ -443,6 +444,58 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, } /** + * \brief Retrieve the model name of the device + * + * The model name allows identification of the specific device model. This can + * be used to infer device characteristics, for instance to determine the + * analogue gain model of a camera sensor based on the sensor model name. + * + * Neither the V4L2 API nor the Media Controller API expose an explicit model + * name. This function implements a heuristics to extract the model name from + * the subdevice's entity name. This should produce accurate results for + * I2C-based devices. If the heuristics can't match a known naming pattern, + * the function returns the full entity name. + * + * \return The model name of the device + */ +const std::string &V4L2Subdevice::model() +{ + if (!model_.empty()) + return model_; + + /* + * Extract model name from the media entity name. + * + * There is no standardized naming scheme for sensor or other entities + * in the Linux kernel at the moment. + * + * - The most common rule, used by I2C sensors, associates the model + * name with the I2C bus number and address (e.g. 'imx219 0-0010'). + * + * - When the sensor exposes multiple subdevs, the model name is + * usually followed by a function name, as in the smiapp driver (e.g. + * 'jt8ew9 pixel_array 0-0010'). + * + * - The vimc driver names its sensors 'Sensor A' and 'Sensor B'. + * + * Other schemes probably exist. As a best effort heuristic, use the + * part of the entity name before the first space if the name contains + * an I2C address, and use the full entity name otherwise. + */ + std::string entityName = entity_->name(); + std::regex i2cRegex{ " [0-9]+-[0-9a-f]{4}" }; + std::smatch match; + + std::string model; + if (std::regex_search(entityName, match, i2cRegex)) + model_ = entityName.substr(0, entityName.find(' ')); + else + model_ = entityName; + + return model_; +} + +/** * \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 |