[libcamera-devel,v3,1/7] delayed_controls: Template the ControlRingBuffer class
diff mbox series

Message ID 20220926095737.30506-2-naush@raspberrypi.com
State Superseded
Headers show
Series
  • Raspberry Pi AGC digital gain fixes
Related show

Commit Message

Naushir Patuck Sept. 26, 2022, 9:57 a.m. UTC
Convert ControlRingBuffer to a templated class to allow arbitrary ring buffer
array types to be defined. Rename ControlRingBuffer to RingBuffer to indicate
this.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Tested-by: David Plowman <david.plowman@raspberrypi.com>
---
 include/libcamera/internal/delayed_controls.h | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

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

Thank you for the patch.

On Mon, Sep 26, 2022 at 10:57:31AM +0100, Naushir Patuck via libcamera-devel wrote:
> Convert ControlRingBuffer to a templated class to allow arbitrary ring buffer
> array types to be defined. Rename ControlRingBuffer to RingBuffer to indicate
> this.
> 
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
> Tested-by: David Plowman <david.plowman@raspberrypi.com>

This patch looks fine, so

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

I'll now look at how it's used :-)

> ---
>  include/libcamera/internal/delayed_controls.h | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/include/libcamera/internal/delayed_controls.h b/include/libcamera/internal/delayed_controls.h
> index aef37077103c..de8026e3e4f0 100644
> --- a/include/libcamera/internal/delayed_controls.h
> +++ b/include/libcamera/internal/delayed_controls.h
> @@ -53,17 +53,18 @@ private:
>  
>  	/* \todo Make the listSize configurable at instance creation time. */
>  	static constexpr int listSize = 16;
> -	class ControlRingBuffer : public std::array<Info, listSize>
> +	template<typename T>
> +	class RingBuffer : public std::array<T, listSize>
>  	{
>  	public:
> -		Info &operator[](unsigned int index)
> +		T &operator[](unsigned int index)
>  		{
> -			return std::array<Info, listSize>::operator[](index % listSize);
> +			return std::array<T, listSize>::operator[](index % listSize);
>  		}
>  
> -		const Info &operator[](unsigned int index) const
> +		const T &operator[](unsigned int index) const
>  		{
> -			return std::array<Info, listSize>::operator[](index % listSize);
> +			return std::array<T, listSize>::operator[](index % listSize);
>  		}
>  	};
>  
> @@ -75,7 +76,7 @@ private:
>  	uint32_t queueCount_;
>  	uint32_t writeCount_;
>  	/* \todo Evaluate if we should index on ControlId * or unsigned int */
> -	std::unordered_map<const ControlId *, ControlRingBuffer> values_;
> +	std::unordered_map<const ControlId *, RingBuffer<Info>> values_;
>  };
>  
>  } /* namespace libcamera */

Patch
diff mbox series

diff --git a/include/libcamera/internal/delayed_controls.h b/include/libcamera/internal/delayed_controls.h
index aef37077103c..de8026e3e4f0 100644
--- a/include/libcamera/internal/delayed_controls.h
+++ b/include/libcamera/internal/delayed_controls.h
@@ -53,17 +53,18 @@  private:
 
 	/* \todo Make the listSize configurable at instance creation time. */
 	static constexpr int listSize = 16;
-	class ControlRingBuffer : public std::array<Info, listSize>
+	template<typename T>
+	class RingBuffer : public std::array<T, listSize>
 	{
 	public:
-		Info &operator[](unsigned int index)
+		T &operator[](unsigned int index)
 		{
-			return std::array<Info, listSize>::operator[](index % listSize);
+			return std::array<T, listSize>::operator[](index % listSize);
 		}
 
-		const Info &operator[](unsigned int index) const
+		const T &operator[](unsigned int index) const
 		{
-			return std::array<Info, listSize>::operator[](index % listSize);
+			return std::array<T, listSize>::operator[](index % listSize);
 		}
 	};
 
@@ -75,7 +76,7 @@  private:
 	uint32_t queueCount_;
 	uint32_t writeCount_;
 	/* \todo Evaluate if we should index on ControlId * or unsigned int */
-	std::unordered_map<const ControlId *, ControlRingBuffer> values_;
+	std::unordered_map<const ControlId *, RingBuffer<Info>> values_;
 };
 
 } /* namespace libcamera */