@@ -27,6 +27,9 @@ namespace libcamera {
class BayerFormat;
class MediaEntity;
+class Request;
+
+struct CameraSensorProperties;
class CameraSensor : protected Loggable
{
@@ -78,10 +81,14 @@ private:
&testPatternModeMap);
int initProperties();
+ int setTestPatternMode(controls::draft::TestPatternModeEnum testPatternMode);
+
const MediaEntity *entity_;
std::unique_ptr<V4L2Subdevice> subdev_;
unsigned int pad_;
+ const CameraSensorProperties *staticProps_;
+
std::string model_;
std::string id_;
@@ -89,6 +96,7 @@ private:
std::vector<unsigned int> mbusCodes_;
std::vector<Size> sizes_;
std::vector<controls::draft::TestPatternModeEnum> testPatternModes_;
+ controls::draft::TestPatternModeEnum testPatternMode_;
Size pixelArraySize_;
Rectangle activeArea_;
@@ -17,6 +17,7 @@
#include <string.h>
#include <libcamera/property_ids.h>
+#include <libcamera/request.h>
#include <libcamera/base/utils.h>
@@ -54,8 +55,9 @@ 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), staticProps_(nullptr),
+ testPatternMode_(controls::draft::TestPatternModeUnset),
+ bayerFormat_(nullptr), properties_(properties::properties)
{
}
@@ -161,6 +163,10 @@ int CameraSensor::init()
if (ret)
return ret;
+ ret = setTestPatternMode(controls::draft::TestPatternModeOff);
+ if (ret)
+ return ret;
+
return 0;
}
@@ -300,14 +306,14 @@ void CameraSensor::initVimcDefaultProperties()
void CameraSensor::initStaticProperties()
{
- const CameraSensorProperties *props = CameraSensorProperties::get(model_);
- if (!props)
+ staticProps_ = CameraSensorProperties::get(model_);
+ if (!staticProps_)
return;
/* Register the properties retrieved from the sensor database. */
- properties_.set(properties::UnitCellSize, props->unitCellSize);
+ properties_.set(properties::UnitCellSize, staticProps_->unitCellSize);
- initTestPatternModes(props->testPatternModes);
+ initTestPatternModes(staticProps_->testPatternModes);
}
void CameraSensor::initTestPatternModes(
@@ -315,7 +321,15 @@ void CameraSensor::initTestPatternModes(
{
const auto &v4l2TestPattern = controls().find(V4L2_CID_TEST_PATTERN);
if (v4l2TestPattern == controls().end()) {
- LOG(CameraSensor, Debug) << "No static test pattern map for \'"
+ LOG(CameraSensor, Debug)
+ << "V4L2_CID_TEST_PATTERN is not supported";
+ return;
+ }
+
+ if (testPatternModes.empty()) {
+ // The camera sensor supports test patterns but we don't know
+ // how to map them so this should be fixed.
+ LOG(CameraSensor, Error) << "No static test pattern map for \'"
<< model() << "\'";
return;
}
@@ -531,6 +545,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(controls::draft::TestPatternModeEnum testPatternMode)
+{
+ if (testPatternMode_ == testPatternMode)
+ return 0;
+
+ if (!staticProps_ || testPatternModes_.empty())
+ return 0;
+
+ auto it = std::find(testPatternModes_.begin(), testPatternModes_.end(),
+ testPatternMode);
+ if (it != testPatternModes_.end()) {
+ LOG(CameraSensor, Error) << "Unsupported test pattern mode "
+ << testPatternMode;
+ return -EINVAL;
+ }
+
+ int32_t index = staticProps_->testPatternModes.at(testPatternMode);
+ ControlList ctrls{ controls() };
+ ctrls.set(V4L2_CID_TEST_PATTERN, index);
+
+ 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
@@ -639,6 +639,11 @@ controls:
Control to select the test pattern mode. Currently identical to
ANDROID_SENSOR_TEST_PATTERN_MODE.
enum:
+ - name: TestPatternModeUnset
+ value: -1
+ description: |
+ No test pattern is set. Returned frames by the camera device are
+ undefined.
- name: TestPatternModeOff
value: 0
description: |