summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2020-12-30 17:02:36 +0100
committerJacopo Mondi <jacopo@jmondi.org>2021-01-18 10:39:13 +0100
commit125ee6ddd6136b76aa8ea4652fb2ccba79923475 (patch)
tree4f9f4eb3125a0d32eddb16332ccfc5546d38cedb
parent8502d4c52d191a03e866411044e34b1f02183b99 (diff)
libcamera: camera_sensor: Provide fall-back for sensor properties
Support for the V4L2 selection API is currently optional in the CameraSensor class. Properties registered by using values read through that API are defaulted in several different places (the Android camera HAL or the CameraSensor class). In the future support for the selection API will be made mandatory, but to give time to sensor drivers in all test platforms to be updated, use sensor resolution as fallback values for sensor pixel array properties and cache them as class member variables. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
-rw-r--r--include/libcamera/internal/camera_sensor.h3
-rw-r--r--src/libcamera/camera_sensor.cpp57
2 files changed, 24 insertions, 36 deletions
diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h
index aee10aa6..86902b85 100644
--- a/include/libcamera/internal/camera_sensor.h
+++ b/include/libcamera/internal/camera_sensor.h
@@ -84,6 +84,9 @@ private:
std::vector<unsigned int> mbusCodes_;
std::vector<Size> sizes_;
+ Size pixelArraySize_;
+ Rectangle activeArea_;
+
ControlList properties_;
};
diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp
index 048fcd6a..0c9bd4f5 100644
--- a/src/libcamera/camera_sensor.cpp
+++ b/src/libcamera/camera_sensor.cpp
@@ -269,15 +269,21 @@ int CameraSensor::validateSensorDriver()
Rectangle rect;
int ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP_BOUNDS, &rect);
if (ret) {
+ rect = Rectangle(resolution());
LOG(CameraSensor, Warning)
- << "Failed to retrieve the readable pixel array size";
+ << "The PixelArraySize property has been defaulted to "
+ << rect.toString();
err = -EINVAL;
}
+ pixelArraySize_.width = rect.width;
+ pixelArraySize_.height = rect.height;
- ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP_DEFAULT, &rect);
+ ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP_DEFAULT, &activeArea_);
if (ret) {
+ activeArea_ = Rectangle(pixelArraySize_);
LOG(CameraSensor, Warning)
- << "Failed to retrieve the active pixel array size";
+ << "The PixelArrayActiveAreas property has been defaulted to "
+ << activeArea_.toString();
err = -EINVAL;
}
@@ -373,24 +379,8 @@ int CameraSensor::initProperties()
propertyValue = 0;
properties_.set(properties::Rotation, propertyValue);
- Rectangle bounds;
- ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP_BOUNDS, &bounds);
- if (!ret)
- properties_.set(properties::PixelArraySize, bounds.size());
-
- Rectangle crop;
- ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP_DEFAULT, &crop);
- if (!ret) {
- /*
- * V4L2_SEL_TGT_CROP_DEFAULT and V4L2_SEL_TGT_CROP_BOUNDS are
- * defined relatively to the sensor full pixel array size,
- * while properties::PixelArrayActiveAreas is defined relatively
- * to properties::PixelArraySize. Adjust it.
- */
- crop.x -= bounds.x;
- crop.y -= bounds.y;
- properties_.set(properties::PixelArrayActiveAreas, { crop });
- }
+ properties_.set(properties::PixelArraySize, pixelArraySize_);
+ properties_.set(properties::PixelArrayActiveAreas, { activeArea_ });
/* Color filter array pattern, register only for RAW sensors. */
for (const auto &format : formats_) {
@@ -646,20 +636,15 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const
{
info->model = model();
- /* Get the active area size. */
- Rectangle rect;
- int ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP_DEFAULT, &rect);
- if (ret) {
- LOG(CameraSensor, Error)
- << "Failed to construct camera sensor info: "
- << "the camera sensor does not report the active area";
-
- return ret;
- }
- info->activeAreaSize = { rect.width, rect.height };
+ /*
+ * The active area size is a static property, while the crop
+ * rectangle needs to be re-read as it depends on the sensor
+ * configuration.
+ */
+ info->activeAreaSize = { activeArea_.width, activeArea_.height };
/* It's mandatory for the subdevice to report its crop rectangle. */
- ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP, &info->analogCrop);
+ int ret = subdev_->getSelection(pad_, V4L2_SEL_TGT_CROP, &info->analogCrop);
if (ret) {
LOG(CameraSensor, Error)
<< "Failed to construct camera sensor info: "
@@ -672,10 +657,10 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const
* are defined relatively to the active pixel area, while V4L2's
* TGT_CROP target is defined in respect to the full pixel array.
*
- * Compensate it by subtracting the active areas offset.
+ * Compensate it by subtracting the active area offset.
*/
- info->analogCrop.x -= rect.x;
- info->analogCrop.y -= rect.y;
+ info->analogCrop.x -= activeArea_.x;
+ info->analogCrop.y -= activeArea_.y;
/* The bit depth and image size depend on the currently applied format. */
V4L2SubdeviceFormat format{};
>vector<std::string> results; for (const auto &path : paths) results.push_back(utils::dirname(path)); if (results != expected) { cerr << "utils::dirname() tests failed" << endl; cerr << "expected: " << endl; for (const auto &path : expected) cerr << "\t" << path << endl; cerr << "results: " << endl; for (const auto &path : results) cerr << "\t" << path << endl; return TestFail; } return TestPass; } int testEnumerate() { std::vector<int> integers{ 1, 2, 3, 4, 5 }; int i = 0; for (auto [index, value] : utils::enumerate(integers)) { if (index != i || value != i + 1) { cerr << "utils::enumerate(<vector>) test failed: i=" << i << ", index=" << index << ", value=" << value << std::endl; return TestFail; } /* Verify that we can modify the value. */ --value; ++i; } if (integers != std::vector<int>{ 0, 1, 2, 3, 4 }) { cerr << "Failed to modify container in enumerated range loop" << endl; return TestFail; } Span<const int> span{ integers }; i = 0; for (auto [index, value] : utils::enumerate(span)) { if (index != i || value != i) { cerr << "utils::enumerate(<span>) test failed: i=" << i << ", index=" << index << ", value=" << value << std::endl; return TestFail; } ++i; } const int array[] = { 0, 2, 4, 6, 8 }; i = 0; for (auto [index, value] : utils::enumerate(array)) { if (index != i || value != i * 2) { cerr << "utils::enumerate(<array>) test failed: i=" << i << ", index=" << index << ", value=" << value << std::endl; return TestFail; } ++i; } return TestPass; } int testDuration() { std::ostringstream os; utils::Duration exposure; double ratio; exposure = 25ms + 25ms; if (exposure.get<std::micro>() != 50000.0) { cerr << "utils::Duration failed to return microsecond count"; return TestFail; } exposure = 1.0s / 4; if (exposure != 250ms) { cerr << "utils::Duration failed scalar divide test"; return TestFail; } exposure = 5000.5us; if (!exposure) { cerr << "utils::Duration failed boolean test"; return TestFail; } os << exposure; if (os.str() != "5000.50us") { cerr << "utils::Duration operator << failed"; return TestFail; } exposure = 100ms; ratio = exposure / 25ms; if (ratio != 4.0) { cerr << "utils::Duration failed ratio test"; return TestFail; } return TestPass; } int run() { /* utils::hex() test. */ std::ostringstream os; std::string ref; os << utils::hex(static_cast<int32_t>(0x42)) << " "; ref += "0x00000042 "; os << utils::hex(static_cast<uint32_t>(0x42)) << " "; ref += "0x00000042 "; os << utils::hex(static_cast<int64_t>(0x42)) << " "; ref += "0x0000000000000042 "; os << utils::hex(static_cast<uint64_t>(0x42)) << " "; ref += "0x0000000000000042 "; os << utils::hex(static_cast<int32_t>(0x42), 4) << " "; ref += "0x0042 "; os << utils::hex(static_cast<uint32_t>(0x42), 1) << " "; ref += "0x42 "; os << utils::hex(static_cast<int64_t>(0x42), 4) << " "; ref += "0x0042 "; os << utils::hex(static_cast<uint64_t>(0x42), 1) << " "; ref += "0x42 "; std::string s = os.str(); if (s != ref) { cerr << "utils::hex() test failed, expected '" << ref << "', got '" << s << "'"; return TestFail; } /* utils::join() and utils::split() test. */ std::vector<std::string> elements = { "/bin", "/usr/bin", "", "", }; std::string path; for (const auto &element : elements) path += (path.empty() ? "" : ":") + element; if (path != utils::join(elements, ":")) { cerr << "utils::join() test failed" << endl; return TestFail; } std::vector<std::string> dirs; for (const auto &dir : utils::split(path, ":")) dirs.push_back(dir); if (dirs != elements) { cerr << "utils::split() test failed" << endl; return TestFail; } /* utils::join() with conversion function test. */ std::vector<Size> sizes = { { 0, 0 }, { 100, 100 } }; s = utils::join(sizes, "/", [](const Size &size) { return size.toString(); }); if (s != "0x0/100x100") { cerr << "utils::join() with conversion test failed" << endl; return TestFail; } /* utils::dirname() tests. */ if (TestPass != testDirname()) return TestFail; /* utils::map_keys() test. */ const std::map<std::string, unsigned int> map{ { "zero", 0 }, { "one", 1 }, { "two", 2 }, }; std::vector<std::string> expectedKeys{ "zero", "one", "two", }; std::sort(expectedKeys.begin(), expectedKeys.end()); const std::vector<std::string> keys = utils::map_keys(map); if (keys != expectedKeys) { cerr << "utils::map_keys() test failed" << endl; return TestFail; } /* utils::alignUp() and utils::alignDown() tests. */ if (utils::alignDown(6, 3) != 6 || utils::alignDown(7, 3) != 6) { cerr << "utils::alignDown test failed" << endl; return TestFail; } if (utils::alignUp(6, 3) != 6 || utils::alignUp(7, 3) != 9) { cerr << "utils::alignUp test failed" << endl; return TestFail; }