[libcamera-devel] [PATCH 3/7] android: camera_metadata: Add appendEntry helper

Kieran Bingham kieran.bingham at ideasonboard.com
Thu Nov 25 12:05:13 CET 2021


Quoting Paul Elder (2021-11-23 10:40:38)
> Add appendEntry() helper, that automatically detects if updateEntry() or
> addEntry() should be used.
> 
> For now only implement it for enums and arithmetic values, as they will
> mainly be used in populating templates, where the preview template
> generator may or may not have (based on capabilities) already added a
> key.

I'm curious, should this always be the case? or is it better to be
explicit to only use update when we know it could already be there to
ensure efficiencies.

Otherwise it might be simpler to add this check into addEntry()
directly?

I assume we never want a tag to be added multiple times?

If this is explicitly separated for efficiency reasons then:


Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>

> 
> Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
> ---
>  src/android/camera_metadata.h | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/src/android/camera_metadata.h b/src/android/camera_metadata.h
> index 8555c7c3..cca14d6c 100644
> --- a/src/android/camera_metadata.h
> +++ b/src/android/camera_metadata.h
> @@ -33,6 +33,17 @@ public:
>  
>         bool hasEntry(uint32_t tag) const;
>  
> +       template<typename T,
> +                std::enable_if_t<std::is_arithmetic_v<T> ||
> +                                 std::is_enum_v<T>> * = nullptr>
> +       bool appendEntry(uint32_t tag, const T &data)
> +       {
> +               if (hasEntry(tag))
> +                       return updateEntry(tag, &data, 1, sizeof(T));
> +               else
> +                       return addEntry(tag, &data, 1, sizeof(T));
> +       }
> +
>         template<typename T,
>                  std::enable_if_t<std::is_arithmetic_v<T> ||
>                                   std::is_enum_v<T>> * = nullptr>
> -- 
> 2.27.0
>


More information about the libcamera-devel mailing list