@@ -26,6 +26,8 @@ namespace libcamera {
class BayerFormat;
class MediaEntity;
+struct CameraSensorProperties;
+
class CameraSensor : protected Loggable
{
public:
@@ -44,6 +46,7 @@ public:
{
return testPatternModes_;
}
+ int setTestPatternMode(int32_t testPatternMode);
V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
const Size &size) const;
@@ -78,6 +81,8 @@ private:
std::unique_ptr<V4L2Subdevice> subdev_;
unsigned int pad_;
+ const CameraSensorProperties *props_;
+
std::string model_;
std::string id_;
@@ -85,6 +90,7 @@ private:
std::vector<unsigned int> mbusCodes_;
std::vector<Size> sizes_;
std::vector<int32_t> testPatternModes_;
+ int32_t testPatternMode_;
Size pixelArraySize_;
Rectangle activeArea_;
@@ -54,8 +54,8 @@ LOG_DEFINE_CATEGORY(CameraSensor)
* Once constructed the instance must be initialized with init().
*/
CameraSensor::CameraSensor(const MediaEntity *entity)
- : entity_(entity), pad_(UINT_MAX), bayerFormat_(nullptr),
- properties_(properties::properties)
+ : entity_(entity), pad_(UINT_MAX), testPatternMode_(-1),
+ bayerFormat_(nullptr), properties_(properties::properties)
{
}
@@ -300,14 +300,16 @@ void CameraSensor::initVimcDefaultProperties()
void CameraSensor::initStaticProperties()
{
- const CameraSensorProperties *props = CameraSensorProperties::get(model_);
- if (!props)
+ props_ = CameraSensorProperties::get(model_);
+ if (!props_) {
+ LOG(CameraSensor, Debug) << "No properties for " << model_;
return;
+ }
/* Register the properties retrieved from the sensor database. */
- properties_.set(properties::UnitCellSize, props->unitCellSize);
+ properties_.set(properties::UnitCellSize, props_->unitCellSize);
- initTestPatternModes(props->testPatternModes);
+ initTestPatternModes(props_->testPatternModes);
}
void CameraSensor::initTestPatternModes(
@@ -531,6 +533,42 @@ Size CameraSensor::resolution() const
* \return The list of test pattern modes
*/
+/**
+ * \brief Set the test pattern mode for the camera sensor
+ * \param[in] testPatternMode Test pattern mode control value to set the camera
+ * sensor
+ *
+ * \return 0 on success or a negative error code otherwise
+ */
+int CameraSensor::setTestPatternMode(int32_t testPatternMode)
+{
+ if (testPatternMode_ == testPatternMode)
+ return 0;
+
+ if (!props_) {
+ LOG(CameraSensor, Error) << "No properties are found";
+ return -EINVAL;
+ }
+
+ auto it = props_->testPatternModes.find(testPatternMode);
+ if (it == props_->testPatternModes.end()) {
+ LOG(CameraSensor, Error) << "Unsupported test pattern mode "
+ << testPatternMode;
+ return -EINVAL;
+ }
+
+ ControlList ctrls{ controls() };
+ ctrls.set(V4L2_CID_TEST_PATTERN, it->second);
+
+ int ret = setControls(&ctrls);
+ if (ret)
+ return ret;
+
+ testPatternMode_ = testPatternMode;
+
+ return 0;
+}
+
/**
* \brief Retrieve the best sensor format for a desired output
* \param[in] mbusCodes The list of acceptable media bus codes