ipa: raspberrypi: Switch ipa and cam_helper to use utils::Duration

Switch the ipa and cam_helper code to use libcamera::utils::Duration for
all time based variables. This improves code readability and avoids
possible errors when converting between time bases.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Naushir Patuck
2021-06-08 12:03:33 +01:00
committed by Laurent Pinchart
parent 5055ca747c
commit caa753179c
4 changed files with 53 additions and 45 deletions
+11 -9
View File
@@ -18,6 +18,7 @@
using namespace RPiController;
using namespace libcamera;
using libcamera::utils::Duration;
namespace libcamera {
LOG_DECLARE_CATEGORY(IPARPI)
@@ -61,20 +62,21 @@ void CamHelper::Process([[maybe_unused]] StatisticsPtr &stats,
{
}
uint32_t CamHelper::ExposureLines(double exposure_us) const
uint32_t CamHelper::ExposureLines(const Duration exposure) const
{
assert(initialized_);
return exposure_us * 1000.0 / mode_.line_length;
return exposure / mode_.line_length;
}
double CamHelper::Exposure(uint32_t exposure_lines) const
Duration CamHelper::Exposure(uint32_t exposure_lines) const
{
assert(initialized_);
return exposure_lines * mode_.line_length / 1000.0;
return exposure_lines * mode_.line_length;
}
uint32_t CamHelper::GetVBlanking(double &exposure, double minFrameDuration,
double maxFrameDuration) const
uint32_t CamHelper::GetVBlanking(Duration &exposure,
Duration minFrameDuration,
Duration maxFrameDuration) const
{
uint32_t frameLengthMin, frameLengthMax, vblank;
uint32_t exposureLines = ExposureLines(exposure);
@@ -85,8 +87,8 @@ uint32_t CamHelper::GetVBlanking(double &exposure, double minFrameDuration,
* minFrameDuration and maxFrameDuration are clamped by the caller
* based on the limits for the active sensor mode.
*/
frameLengthMin = 1e3 * minFrameDuration / mode_.line_length;
frameLengthMax = 1e3 * maxFrameDuration / mode_.line_length;
frameLengthMin = minFrameDuration / mode_.line_length;
frameLengthMax = maxFrameDuration / mode_.line_length;
/*
* Limit the exposure to the maximum frame duration requested, and
@@ -182,7 +184,7 @@ void CamHelper::parseEmbeddedData(Span<const uint8_t> buffer,
return;
}
deviceStatus.shutter_speed = Exposure(exposureLines);
deviceStatus.shutter_speed = Exposure(exposureLines).get<std::micro>();
deviceStatus.analogue_gain = Gain(gainCode);
LOG(IPARPI, Debug) << "Metadata updated - Exposure : "