summaryrefslogtreecommitdiff
path: root/src/ipa/raspberrypi/cam_helper.cpp
diff options
context:
space:
mode:
authorDavid Plowman <david.plowman@raspberrypi.com>2021-05-07 12:37:28 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-05-08 02:49:13 +0300
commit5fda81e1f441670796b81095595b98af7719779c (patch)
tree091b188e877dc5c1398d9e0c07253a7695241287 /src/ipa/raspberrypi/cam_helper.cpp
parentdf36fb4abb37c216d1eaf60a1772047b5205d0b7 (diff)
ipa: raspberrypi: Use CamHelpers to generalise sensor embedded data parsing
CamHelpers get virtual Prepare() and Process() methods, running just before and just after the ISP, just like Raspberry Pi Algorithms. The Prepare() method is able to parse the register dumps in embedded data buffers, and can be specialised to perform custom processing when necessary. The IPA itself only needs to call the new Prepare() and Process() methods. It must fill in the DeviceStatus from the controls first, in case the Prepare() method does not supply its own values. Signed-off-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/ipa/raspberrypi/cam_helper.cpp')
-rw-r--r--src/ipa/raspberrypi/cam_helper.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp
index 0ae0baa0..09917f3c 100644
--- a/src/ipa/raspberrypi/cam_helper.cpp
+++ b/src/ipa/raspberrypi/cam_helper.cpp
@@ -17,6 +17,11 @@
#include "md_parser.hpp"
using namespace RPiController;
+using namespace libcamera;
+
+namespace libcamera {
+LOG_DECLARE_CATEGORY(IPARPI)
+}
static std::map<std::string, CamHelperCreateFunc> cam_helpers;
@@ -45,6 +50,17 @@ CamHelper::~CamHelper()
delete parser_;
}
+void CamHelper::Prepare(Span<const uint8_t> buffer,
+ Metadata &metadata)
+{
+ parseEmbeddedData(buffer, metadata);
+}
+
+void CamHelper::Process([[maybe_unused]] StatisticsPtr &stats,
+ [[maybe_unused]] Metadata &metadata)
+{
+}
+
uint32_t CamHelper::ExposureLines(double exposure_us) const
{
assert(initialized_);
@@ -139,6 +155,44 @@ unsigned int CamHelper::MistrustFramesModeSwitch() const
return 0;
}
+void CamHelper::parseEmbeddedData(Span<const uint8_t> buffer,
+ Metadata &metadata)
+{
+ if (buffer.empty())
+ return;
+
+ uint32_t exposureLines, gainCode;
+
+ if (parser_->Parse(buffer) != MdParser::Status::OK ||
+ parser_->GetExposureLines(exposureLines) != MdParser::Status::OK ||
+ parser_->GetGainCode(gainCode) != MdParser::Status::OK) {
+ LOG(IPARPI, Error) << "Embedded data buffer parsing failed";
+ return;
+ }
+
+ /*
+ * Overwrite the exposure/gain values in the DeviceStatus, as
+ * we know better. Fetch it first in case any other fields were
+ * set meaningfully.
+ */
+ DeviceStatus deviceStatus;
+
+ if (metadata.Get("device.status", deviceStatus) != 0) {
+ LOG(IPARPI, Error) << "DeviceStatus not found";
+ return;
+ }
+
+ deviceStatus.shutter_speed = Exposure(exposureLines);
+ deviceStatus.analogue_gain = Gain(gainCode);
+
+ LOG(IPARPI, Debug) << "Metadata updated - Exposure : "
+ << deviceStatus.shutter_speed
+ << " Gain : "
+ << deviceStatus.analogue_gain;
+
+ metadata.Set("device.status", deviceStatus);
+}
+
RegisterCamHelper::RegisterCamHelper(char const *cam_name,
CamHelperCreateFunc create_func)
{