[libcamera-devel,v1,9/9] ipa: raspberrypi: Extract line length from the embedded data parser
diff mbox series

Message ID 20221003083934.31629-10-naush@raspberrypi.com
State Changes Requested
Headers show
Series
  • Raspberry Pi: Horizontal blanking control
Related show

Commit Message

Naushir Patuck Oct. 3, 2022, 8:39 a.m. UTC
Update the imx219, imx477 and imx519 parsers to extract the line length values
from the embedded data stream and use these values in the deviceStatus metadata,
replacing the DelayedControls provided values.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
---
 src/ipa/raspberrypi/cam_helper.cpp        | 3 ++-
 src/ipa/raspberrypi/cam_helper_imx219.cpp | 9 +++++++--
 src/ipa/raspberrypi/cam_helper_imx477.cpp | 9 +++++++--
 src/ipa/raspberrypi/cam_helper_imx519.cpp | 9 +++++++--
 4 files changed, 23 insertions(+), 7 deletions(-)

Comments

Laurent Pinchart Oct. 4, 2022, 5:13 p.m. UTC | #1
Hi Naush,

Thank you for the patch.

On Mon, Oct 03, 2022 at 09:39:35AM +0100, Naushir Patuck via libcamera-devel wrote:
> Update the imx219, imx477 and imx519 parsers to extract the line length values
> from the embedded data stream and use these values in the deviceStatus metadata,
> replacing the DelayedControls provided values.
> 
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/ipa/raspberrypi/cam_helper.cpp        | 3 ++-
>  src/ipa/raspberrypi/cam_helper_imx219.cpp | 9 +++++++--
>  src/ipa/raspberrypi/cam_helper_imx477.cpp | 9 +++++++--
>  src/ipa/raspberrypi/cam_helper_imx519.cpp | 9 +++++++--
>  4 files changed, 23 insertions(+), 7 deletions(-)
> 
> diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp
> index f5f034ece711..1811d231ad40 100644
> --- a/src/ipa/raspberrypi/cam_helper.cpp
> +++ b/src/ipa/raspberrypi/cam_helper.cpp
> @@ -228,7 +228,7 @@ void CamHelper::parseEmbeddedData(Span<const uint8_t> buffer,
>  	metadata.merge(parsedMetadata);
>  
>  	/*
> -	 * Overwrite the exposure/gain, frame length and sensor temperature values
> +	 * Overwrite the exposure/gain, line/frame length and sensor temperature values
>  	 * in the existing DeviceStatus with values from the parsed embedded buffer.
>  	 * Fetch it first in case any other fields were set meaningfully.
>  	 */
> @@ -242,6 +242,7 @@ void CamHelper::parseEmbeddedData(Span<const uint8_t> buffer,
>  	deviceStatus.shutterSpeed = parsedDeviceStatus.shutterSpeed;
>  	deviceStatus.analogueGain = parsedDeviceStatus.analogueGain;
>  	deviceStatus.frameLength = parsedDeviceStatus.frameLength;
> +	deviceStatus.lineLength = parsedDeviceStatus.lineLength;
>  	if (parsedDeviceStatus.sensorTemperature)
>  		deviceStatus.sensorTemperature = parsedDeviceStatus.sensorTemperature;
>  
> diff --git a/src/ipa/raspberrypi/cam_helper_imx219.cpp b/src/ipa/raspberrypi/cam_helper_imx219.cpp
> index 98a3b31956ec..c3337ed08466 100644
> --- a/src/ipa/raspberrypi/cam_helper_imx219.cpp
> +++ b/src/ipa/raspberrypi/cam_helper_imx219.cpp
> @@ -32,8 +32,11 @@ constexpr uint32_t expHiReg = 0x15a;
>  constexpr uint32_t expLoReg = 0x15b;
>  constexpr uint32_t frameLengthHiReg = 0x160;
>  constexpr uint32_t frameLengthLoReg = 0x161;
> +constexpr uint32_t lineLengthHiReg = 0x162;
> +constexpr uint32_t lineLengthLoReg = 0x163;
>  constexpr std::initializer_list<uint32_t> registerList [[maybe_unused]]
> -	= { expHiReg, expLoReg, gainReg, frameLengthHiReg, frameLengthLoReg };
> +	= { expHiReg, expLoReg, gainReg, frameLengthHiReg, frameLengthLoReg,
> +	    lineLengthHiReg, lineLengthLoReg };
>  
>  class CamHelperImx219 : public CamHelper
>  {
> @@ -94,8 +97,10 @@ void CamHelperImx219::populateMetadata(const MdParser::RegisterMap &registers,
>  {
>  	DeviceStatus deviceStatus;
>  
> +	deviceStatus.lineLength = lineLengthPckToDuration(registers.at(lineLengthHiReg) * 256 +
> +							  registers.at(lineLengthLoReg));
>  	deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg),
> -					     mode_.minLineLength);
> +					     deviceStatus.lineLength);
>  	deviceStatus.analogueGain = gain(registers.at(gainReg));
>  	deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg);
>  
> diff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp
> index 19a5e471c27e..bc769ca75baa 100644
> --- a/src/ipa/raspberrypi/cam_helper_imx477.cpp
> +++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp
> @@ -35,9 +35,12 @@ constexpr uint32_t gainHiReg = 0x0204;
>  constexpr uint32_t gainLoReg = 0x0205;
>  constexpr uint32_t frameLengthHiReg = 0x0340;
>  constexpr uint32_t frameLengthLoReg = 0x0341;
> +constexpr uint32_t lineLengthHiReg = 0x0342;
> +constexpr uint32_t lineLengthLoReg = 0x0343;
>  constexpr uint32_t temperatureReg = 0x013a;
>  constexpr std::initializer_list<uint32_t> registerList =
> -	{ expHiReg, expLoReg, gainHiReg, gainLoReg, frameLengthHiReg, frameLengthLoReg, temperatureReg  };
> +	{ expHiReg, expLoReg, gainHiReg, gainLoReg, frameLengthHiReg, frameLengthLoReg,
> +	  lineLengthHiReg, lineLengthLoReg, temperatureReg };
>  
>  class CamHelperImx477 : public CamHelper
>  {
> @@ -175,8 +178,10 @@ void CamHelperImx477::populateMetadata(const MdParser::RegisterMap &registers,
>  {
>  	DeviceStatus deviceStatus;
>  
> +	deviceStatus.lineLength = lineLengthPckToDuration(registers.at(lineLengthHiReg) * 256 +
> +							  registers.at(lineLengthLoReg));
>  	deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg),
> -					     mode_.minLineLength);
> +					     deviceStatus.lineLength);
>  	deviceStatus.analogueGain = gain(registers.at(gainHiReg) * 256 + registers.at(gainLoReg));
>  	deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg);
>  	deviceStatus.sensorTemperature = std::clamp<int8_t>(registers.at(temperatureReg), -20, 80);
> diff --git a/src/ipa/raspberrypi/cam_helper_imx519.cpp b/src/ipa/raspberrypi/cam_helper_imx519.cpp
> index d2eb171912da..c7262aa0b6e6 100644
> --- a/src/ipa/raspberrypi/cam_helper_imx519.cpp
> +++ b/src/ipa/raspberrypi/cam_helper_imx519.cpp
> @@ -36,8 +36,11 @@ constexpr uint32_t gainHiReg = 0x0204;
>  constexpr uint32_t gainLoReg = 0x0205;
>  constexpr uint32_t frameLengthHiReg = 0x0340;
>  constexpr uint32_t frameLengthLoReg = 0x0341;
> +constexpr uint32_t lineLengthHiReg = 0x0342;
> +constexpr uint32_t lineLengthLoReg = 0x0343;
>  constexpr std::initializer_list<uint32_t> registerList =
> -	{ expHiReg, expLoReg, gainHiReg, gainLoReg, frameLengthHiReg, frameLengthLoReg  };
> +	{ expHiReg, expLoReg, gainHiReg, gainLoReg, frameLengthHiReg, frameLengthLoReg,
> +	  lineLengthHiReg, lineLengthLoReg };
>  
>  class CamHelperImx519 : public CamHelper
>  {
> @@ -175,8 +178,10 @@ void CamHelperImx519::populateMetadata(const MdParser::RegisterMap &registers,
>  {
>  	DeviceStatus deviceStatus;
>  
> +	deviceStatus.lineLength = lineLengthPckToDuration(registers.at(lineLengthHiReg) * 256 +
> +							  registers.at(lineLengthLoReg));
>  	deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg),
> -					     mode_.minLineLength);
> +					     deviceStatus.lineLength);
>  	deviceStatus.analogueGain = gain(registers.at(gainHiReg) * 256 + registers.at(gainLoReg));
>  	deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg);
>

Patch
diff mbox series

diff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp
index f5f034ece711..1811d231ad40 100644
--- a/src/ipa/raspberrypi/cam_helper.cpp
+++ b/src/ipa/raspberrypi/cam_helper.cpp
@@ -228,7 +228,7 @@  void CamHelper::parseEmbeddedData(Span<const uint8_t> buffer,
 	metadata.merge(parsedMetadata);
 
 	/*
-	 * Overwrite the exposure/gain, frame length and sensor temperature values
+	 * Overwrite the exposure/gain, line/frame length and sensor temperature values
 	 * in the existing DeviceStatus with values from the parsed embedded buffer.
 	 * Fetch it first in case any other fields were set meaningfully.
 	 */
@@ -242,6 +242,7 @@  void CamHelper::parseEmbeddedData(Span<const uint8_t> buffer,
 	deviceStatus.shutterSpeed = parsedDeviceStatus.shutterSpeed;
 	deviceStatus.analogueGain = parsedDeviceStatus.analogueGain;
 	deviceStatus.frameLength = parsedDeviceStatus.frameLength;
+	deviceStatus.lineLength = parsedDeviceStatus.lineLength;
 	if (parsedDeviceStatus.sensorTemperature)
 		deviceStatus.sensorTemperature = parsedDeviceStatus.sensorTemperature;
 
diff --git a/src/ipa/raspberrypi/cam_helper_imx219.cpp b/src/ipa/raspberrypi/cam_helper_imx219.cpp
index 98a3b31956ec..c3337ed08466 100644
--- a/src/ipa/raspberrypi/cam_helper_imx219.cpp
+++ b/src/ipa/raspberrypi/cam_helper_imx219.cpp
@@ -32,8 +32,11 @@  constexpr uint32_t expHiReg = 0x15a;
 constexpr uint32_t expLoReg = 0x15b;
 constexpr uint32_t frameLengthHiReg = 0x160;
 constexpr uint32_t frameLengthLoReg = 0x161;
+constexpr uint32_t lineLengthHiReg = 0x162;
+constexpr uint32_t lineLengthLoReg = 0x163;
 constexpr std::initializer_list<uint32_t> registerList [[maybe_unused]]
-	= { expHiReg, expLoReg, gainReg, frameLengthHiReg, frameLengthLoReg };
+	= { expHiReg, expLoReg, gainReg, frameLengthHiReg, frameLengthLoReg,
+	    lineLengthHiReg, lineLengthLoReg };
 
 class CamHelperImx219 : public CamHelper
 {
@@ -94,8 +97,10 @@  void CamHelperImx219::populateMetadata(const MdParser::RegisterMap &registers,
 {
 	DeviceStatus deviceStatus;
 
+	deviceStatus.lineLength = lineLengthPckToDuration(registers.at(lineLengthHiReg) * 256 +
+							  registers.at(lineLengthLoReg));
 	deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg),
-					     mode_.minLineLength);
+					     deviceStatus.lineLength);
 	deviceStatus.analogueGain = gain(registers.at(gainReg));
 	deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg);
 
diff --git a/src/ipa/raspberrypi/cam_helper_imx477.cpp b/src/ipa/raspberrypi/cam_helper_imx477.cpp
index 19a5e471c27e..bc769ca75baa 100644
--- a/src/ipa/raspberrypi/cam_helper_imx477.cpp
+++ b/src/ipa/raspberrypi/cam_helper_imx477.cpp
@@ -35,9 +35,12 @@  constexpr uint32_t gainHiReg = 0x0204;
 constexpr uint32_t gainLoReg = 0x0205;
 constexpr uint32_t frameLengthHiReg = 0x0340;
 constexpr uint32_t frameLengthLoReg = 0x0341;
+constexpr uint32_t lineLengthHiReg = 0x0342;
+constexpr uint32_t lineLengthLoReg = 0x0343;
 constexpr uint32_t temperatureReg = 0x013a;
 constexpr std::initializer_list<uint32_t> registerList =
-	{ expHiReg, expLoReg, gainHiReg, gainLoReg, frameLengthHiReg, frameLengthLoReg, temperatureReg  };
+	{ expHiReg, expLoReg, gainHiReg, gainLoReg, frameLengthHiReg, frameLengthLoReg,
+	  lineLengthHiReg, lineLengthLoReg, temperatureReg };
 
 class CamHelperImx477 : public CamHelper
 {
@@ -175,8 +178,10 @@  void CamHelperImx477::populateMetadata(const MdParser::RegisterMap &registers,
 {
 	DeviceStatus deviceStatus;
 
+	deviceStatus.lineLength = lineLengthPckToDuration(registers.at(lineLengthHiReg) * 256 +
+							  registers.at(lineLengthLoReg));
 	deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg),
-					     mode_.minLineLength);
+					     deviceStatus.lineLength);
 	deviceStatus.analogueGain = gain(registers.at(gainHiReg) * 256 + registers.at(gainLoReg));
 	deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg);
 	deviceStatus.sensorTemperature = std::clamp<int8_t>(registers.at(temperatureReg), -20, 80);
diff --git a/src/ipa/raspberrypi/cam_helper_imx519.cpp b/src/ipa/raspberrypi/cam_helper_imx519.cpp
index d2eb171912da..c7262aa0b6e6 100644
--- a/src/ipa/raspberrypi/cam_helper_imx519.cpp
+++ b/src/ipa/raspberrypi/cam_helper_imx519.cpp
@@ -36,8 +36,11 @@  constexpr uint32_t gainHiReg = 0x0204;
 constexpr uint32_t gainLoReg = 0x0205;
 constexpr uint32_t frameLengthHiReg = 0x0340;
 constexpr uint32_t frameLengthLoReg = 0x0341;
+constexpr uint32_t lineLengthHiReg = 0x0342;
+constexpr uint32_t lineLengthLoReg = 0x0343;
 constexpr std::initializer_list<uint32_t> registerList =
-	{ expHiReg, expLoReg, gainHiReg, gainLoReg, frameLengthHiReg, frameLengthLoReg  };
+	{ expHiReg, expLoReg, gainHiReg, gainLoReg, frameLengthHiReg, frameLengthLoReg,
+	  lineLengthHiReg, lineLengthLoReg };
 
 class CamHelperImx519 : public CamHelper
 {
@@ -175,8 +178,10 @@  void CamHelperImx519::populateMetadata(const MdParser::RegisterMap &registers,
 {
 	DeviceStatus deviceStatus;
 
+	deviceStatus.lineLength = lineLengthPckToDuration(registers.at(lineLengthHiReg) * 256 +
+							  registers.at(lineLengthLoReg));
 	deviceStatus.shutterSpeed = exposure(registers.at(expHiReg) * 256 + registers.at(expLoReg),
-					     mode_.minLineLength);
+					     deviceStatus.lineLength);
 	deviceStatus.analogueGain = gain(registers.at(gainHiReg) * 256 + registers.at(gainLoReg));
 	deviceStatus.frameLength = registers.at(frameLengthHiReg) * 256 + registers.at(frameLengthLoReg);