[v2,2/2] libcamera: Add Unsigned 16-bits Control Type
diff mbox series

Message ID 20241022095737.4127210-3-chenghaoyang@chromium.org
State Superseded
Headers show
Series
  • Add U16 & U32 support in controls
Related show

Commit Message

Harvey Yang Oct. 22, 2024, 9:56 a.m. UTC
From: Yudhistira Erlandinata <yerlandinata@chromium.org>

Some camera metadata is of length 16-bits,
for example JPEG metadata headers.

Signed-off-by: Yudhistira Erlandinata <yerlandinata@chromium.org>
Co-developed-by: Harvey Yang <chenghaoyang@chromium.org>
Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>
---
 include/libcamera/controls.h  | 7 +++++++
 src/libcamera/controls.cpp    | 8 ++++++++
 src/libcamera/v4l2_device.cpp | 9 +++++++++
 3 files changed, 24 insertions(+)

Comments

Kieran Bingham Oct. 24, 2024, 11:01 p.m. UTC | #1
Quoting Harvey Yang (2024-10-22 10:56:05)
> From: Yudhistira Erlandinata <yerlandinata@chromium.org>
> 
> Some camera metadata is of length 16-bits,
> for example JPEG metadata headers.
> 

Commit message could be improved, but it's probably useful to still say
that you need this type for supporting JPEG headers from V4L2...



> Signed-off-by: Yudhistira Erlandinata <yerlandinata@chromium.org>
> Co-developed-by: Harvey Yang <chenghaoyang@chromium.org>
> Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>
> ---
>  include/libcamera/controls.h  | 7 +++++++
>  src/libcamera/controls.cpp    | 8 ++++++++
>  src/libcamera/v4l2_device.cpp | 9 +++++++++

Also lacking the corresponding tests in test/controls/control_value.cpp

But once that's added, I'd look forward to merging this.
--
Kieran

>  3 files changed, 24 insertions(+)
> 
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index 6da8ad2c3..162115bb5 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -29,6 +29,7 @@ enum ControlType {
>         ControlTypeNone,
>         ControlTypeBool,
>         ControlTypeByte,
> +       ControlTypeUnsigned16,
>         ControlTypeUnsigned32,
>         ControlTypeInteger32,
>         ControlTypeInteger64,
> @@ -63,6 +64,12 @@ struct control_type<uint8_t> {
>         static constexpr std::size_t size = 0;
>  };
>  
> +template<>
> +struct control_type<uint16_t> {
> +       static constexpr ControlType value = ControlTypeUnsigned16;
> +       static constexpr std::size_t size = 0;
> +};
> +
>  template<>
>  struct control_type<uint32_t> {
>         static constexpr ControlType value = ControlTypeUnsigned32;
> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> index 8ae295191..3a840bb22 100644
> --- a/src/libcamera/controls.cpp
> +++ b/src/libcamera/controls.cpp
> @@ -54,6 +54,7 @@ static constexpr size_t ControlValueSize[] = {
>         [ControlTypeNone]               = 0,
>         [ControlTypeBool]               = sizeof(bool),
>         [ControlTypeByte]               = sizeof(uint8_t),
> +       [ControlTypeUnsigned16]         = sizeof(uint16_t),
>         [ControlTypeUnsigned32]         = sizeof(uint32_t),
>         [ControlTypeInteger32]          = sizeof(int32_t),
>         [ControlTypeInteger64]          = sizeof(int64_t),
> @@ -75,6 +76,8 @@ static constexpr size_t ControlValueSize[] = {
>   * The control stores a boolean value
>   * \var ControlTypeByte
>   * The control stores a byte value as an unsigned 8-bit integer
> + * \var ControlTypeUnsigned16
> + * The control stores an unsigned 16-bit integer value
>   * \var ControlTypeUnsigned32
>   * The control stores an unsigned 32-bit integer value
>   * \var ControlTypeInteger32
> @@ -233,6 +236,11 @@ std::string ControlValue::toString() const
>                         str += std::to_string(*value);
>                         break;
>                 }
> +               case ControlTypeUnsigned16: {
> +                       const uint16_t *value = reinterpret_cast<const uint16_t *>(data);
> +                       str += std::to_string(*value);
> +                       break;
> +               }
>                 case ControlTypeUnsigned32: {
>                         const uint32_t *value = reinterpret_cast<const uint32_t *>(data);
>                         str += std::to_string(*value);
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 0ba8dcfa0..f1b5a25a0 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -492,6 +492,9 @@ ControlType V4L2Device::v4l2CtrlType(uint32_t ctrlType)
>         case V4L2_CTRL_TYPE_BOOLEAN:
>                 return ControlTypeBool;
>  
> +       case V4L2_CTRL_TYPE_U16:
> +               return ControlTypeUnsigned16;
> +
>         case V4L2_CTRL_TYPE_U32:
>                 return ControlTypeUnsigned32;
>  
> @@ -543,6 +546,11 @@ std::optional<ControlInfo> V4L2Device::v4l2ControlInfo(const v4l2_query_ext_ctrl
>                                    static_cast<uint8_t>(ctrl.maximum),
>                                    static_cast<uint8_t>(ctrl.default_value));
>  
> +       case V4L2_CTRL_TYPE_U16:
> +               return ControlInfo(static_cast<uint16_t>(ctrl.minimum),
> +                                  static_cast<uint16_t>(ctrl.maximum),
> +                                  static_cast<uint16_t>(ctrl.default_value));
> +
>         case V4L2_CTRL_TYPE_U32:
>                 return ControlInfo(static_cast<uint32_t>(ctrl.minimum),
>                                    static_cast<uint32_t>(ctrl.maximum),
> @@ -634,6 +642,7 @@ void V4L2Device::listControls()
>                 case V4L2_CTRL_TYPE_BITMASK:
>                 case V4L2_CTRL_TYPE_INTEGER_MENU:
>                 case V4L2_CTRL_TYPE_U8:
> +               case V4L2_CTRL_TYPE_U16:
>                 case V4L2_CTRL_TYPE_U32:
>                         break;
>                 /* \todo Support other control types. */
> -- 
> 2.47.0.105.g07ac214952-goog
>
Harvey Yang Oct. 25, 2024, 5:33 a.m. UTC | #2
Hi Kieran,

On Fri, Oct 25, 2024 at 7:01 AM Kieran Bingham
<kieran.bingham@ideasonboard.com> wrote:
>
> Quoting Harvey Yang (2024-10-22 10:56:05)
> > From: Yudhistira Erlandinata <yerlandinata@chromium.org>
> >
> > Some camera metadata is of length 16-bits,
> > for example JPEG metadata headers.
> >
>
> Commit message could be improved, but it's probably useful to still say
> that you need this type for supporting JPEG headers from V4L2...

Updated.

>
>
>
> > Signed-off-by: Yudhistira Erlandinata <yerlandinata@chromium.org>
> > Co-developed-by: Harvey Yang <chenghaoyang@chromium.org>
> > Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>
> > ---
> >  include/libcamera/controls.h  | 7 +++++++
> >  src/libcamera/controls.cpp    | 8 ++++++++
> >  src/libcamera/v4l2_device.cpp | 9 +++++++++
>
> Also lacking the corresponding tests in test/controls/control_value.cpp
>
> But once that's added, I'd look forward to merging this.

Added and tested.

BR,
Harvey

> --
> Kieran
>
> >  3 files changed, 24 insertions(+)
> >
> > diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> > index 6da8ad2c3..162115bb5 100644
> > --- a/include/libcamera/controls.h
> > +++ b/include/libcamera/controls.h
> > @@ -29,6 +29,7 @@ enum ControlType {
> >         ControlTypeNone,
> >         ControlTypeBool,
> >         ControlTypeByte,
> > +       ControlTypeUnsigned16,
> >         ControlTypeUnsigned32,
> >         ControlTypeInteger32,
> >         ControlTypeInteger64,
> > @@ -63,6 +64,12 @@ struct control_type<uint8_t> {
> >         static constexpr std::size_t size = 0;
> >  };
> >
> > +template<>
> > +struct control_type<uint16_t> {
> > +       static constexpr ControlType value = ControlTypeUnsigned16;
> > +       static constexpr std::size_t size = 0;
> > +};
> > +
> >  template<>
> >  struct control_type<uint32_t> {
> >         static constexpr ControlType value = ControlTypeUnsigned32;
> > diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
> > index 8ae295191..3a840bb22 100644
> > --- a/src/libcamera/controls.cpp
> > +++ b/src/libcamera/controls.cpp
> > @@ -54,6 +54,7 @@ static constexpr size_t ControlValueSize[] = {
> >         [ControlTypeNone]               = 0,
> >         [ControlTypeBool]               = sizeof(bool),
> >         [ControlTypeByte]               = sizeof(uint8_t),
> > +       [ControlTypeUnsigned16]         = sizeof(uint16_t),
> >         [ControlTypeUnsigned32]         = sizeof(uint32_t),
> >         [ControlTypeInteger32]          = sizeof(int32_t),
> >         [ControlTypeInteger64]          = sizeof(int64_t),
> > @@ -75,6 +76,8 @@ static constexpr size_t ControlValueSize[] = {
> >   * The control stores a boolean value
> >   * \var ControlTypeByte
> >   * The control stores a byte value as an unsigned 8-bit integer
> > + * \var ControlTypeUnsigned16
> > + * The control stores an unsigned 16-bit integer value
> >   * \var ControlTypeUnsigned32
> >   * The control stores an unsigned 32-bit integer value
> >   * \var ControlTypeInteger32
> > @@ -233,6 +236,11 @@ std::string ControlValue::toString() const
> >                         str += std::to_string(*value);
> >                         break;
> >                 }
> > +               case ControlTypeUnsigned16: {
> > +                       const uint16_t *value = reinterpret_cast<const uint16_t *>(data);
> > +                       str += std::to_string(*value);
> > +                       break;
> > +               }
> >                 case ControlTypeUnsigned32: {
> >                         const uint32_t *value = reinterpret_cast<const uint32_t *>(data);
> >                         str += std::to_string(*value);
> > diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> > index 0ba8dcfa0..f1b5a25a0 100644
> > --- a/src/libcamera/v4l2_device.cpp
> > +++ b/src/libcamera/v4l2_device.cpp
> > @@ -492,6 +492,9 @@ ControlType V4L2Device::v4l2CtrlType(uint32_t ctrlType)
> >         case V4L2_CTRL_TYPE_BOOLEAN:
> >                 return ControlTypeBool;
> >
> > +       case V4L2_CTRL_TYPE_U16:
> > +               return ControlTypeUnsigned16;
> > +
> >         case V4L2_CTRL_TYPE_U32:
> >                 return ControlTypeUnsigned32;
> >
> > @@ -543,6 +546,11 @@ std::optional<ControlInfo> V4L2Device::v4l2ControlInfo(const v4l2_query_ext_ctrl
> >                                    static_cast<uint8_t>(ctrl.maximum),
> >                                    static_cast<uint8_t>(ctrl.default_value));
> >
> > +       case V4L2_CTRL_TYPE_U16:
> > +               return ControlInfo(static_cast<uint16_t>(ctrl.minimum),
> > +                                  static_cast<uint16_t>(ctrl.maximum),
> > +                                  static_cast<uint16_t>(ctrl.default_value));
> > +
> >         case V4L2_CTRL_TYPE_U32:
> >                 return ControlInfo(static_cast<uint32_t>(ctrl.minimum),
> >                                    static_cast<uint32_t>(ctrl.maximum),
> > @@ -634,6 +642,7 @@ void V4L2Device::listControls()
> >                 case V4L2_CTRL_TYPE_BITMASK:
> >                 case V4L2_CTRL_TYPE_INTEGER_MENU:
> >                 case V4L2_CTRL_TYPE_U8:
> > +               case V4L2_CTRL_TYPE_U16:
> >                 case V4L2_CTRL_TYPE_U32:
> >                         break;
> >                 /* \todo Support other control types. */
> > --
> > 2.47.0.105.g07ac214952-goog
> >

Patch
diff mbox series

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 6da8ad2c3..162115bb5 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -29,6 +29,7 @@  enum ControlType {
 	ControlTypeNone,
 	ControlTypeBool,
 	ControlTypeByte,
+	ControlTypeUnsigned16,
 	ControlTypeUnsigned32,
 	ControlTypeInteger32,
 	ControlTypeInteger64,
@@ -63,6 +64,12 @@  struct control_type<uint8_t> {
 	static constexpr std::size_t size = 0;
 };
 
+template<>
+struct control_type<uint16_t> {
+	static constexpr ControlType value = ControlTypeUnsigned16;
+	static constexpr std::size_t size = 0;
+};
+
 template<>
 struct control_type<uint32_t> {
 	static constexpr ControlType value = ControlTypeUnsigned32;
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index 8ae295191..3a840bb22 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -54,6 +54,7 @@  static constexpr size_t ControlValueSize[] = {
 	[ControlTypeNone]		= 0,
 	[ControlTypeBool]		= sizeof(bool),
 	[ControlTypeByte]		= sizeof(uint8_t),
+	[ControlTypeUnsigned16]		= sizeof(uint16_t),
 	[ControlTypeUnsigned32]		= sizeof(uint32_t),
 	[ControlTypeInteger32]		= sizeof(int32_t),
 	[ControlTypeInteger64]		= sizeof(int64_t),
@@ -75,6 +76,8 @@  static constexpr size_t ControlValueSize[] = {
  * The control stores a boolean value
  * \var ControlTypeByte
  * The control stores a byte value as an unsigned 8-bit integer
+ * \var ControlTypeUnsigned16
+ * The control stores an unsigned 16-bit integer value
  * \var ControlTypeUnsigned32
  * The control stores an unsigned 32-bit integer value
  * \var ControlTypeInteger32
@@ -233,6 +236,11 @@  std::string ControlValue::toString() const
 			str += std::to_string(*value);
 			break;
 		}
+		case ControlTypeUnsigned16: {
+			const uint16_t *value = reinterpret_cast<const uint16_t *>(data);
+			str += std::to_string(*value);
+			break;
+		}
 		case ControlTypeUnsigned32: {
 			const uint32_t *value = reinterpret_cast<const uint32_t *>(data);
 			str += std::to_string(*value);
diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 0ba8dcfa0..f1b5a25a0 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -492,6 +492,9 @@  ControlType V4L2Device::v4l2CtrlType(uint32_t ctrlType)
 	case V4L2_CTRL_TYPE_BOOLEAN:
 		return ControlTypeBool;
 
+	case V4L2_CTRL_TYPE_U16:
+		return ControlTypeUnsigned16;
+
 	case V4L2_CTRL_TYPE_U32:
 		return ControlTypeUnsigned32;
 
@@ -543,6 +546,11 @@  std::optional<ControlInfo> V4L2Device::v4l2ControlInfo(const v4l2_query_ext_ctrl
 				   static_cast<uint8_t>(ctrl.maximum),
 				   static_cast<uint8_t>(ctrl.default_value));
 
+	case V4L2_CTRL_TYPE_U16:
+		return ControlInfo(static_cast<uint16_t>(ctrl.minimum),
+				   static_cast<uint16_t>(ctrl.maximum),
+				   static_cast<uint16_t>(ctrl.default_value));
+
 	case V4L2_CTRL_TYPE_U32:
 		return ControlInfo(static_cast<uint32_t>(ctrl.minimum),
 				   static_cast<uint32_t>(ctrl.maximum),
@@ -634,6 +642,7 @@  void V4L2Device::listControls()
 		case V4L2_CTRL_TYPE_BITMASK:
 		case V4L2_CTRL_TYPE_INTEGER_MENU:
 		case V4L2_CTRL_TYPE_U8:
+		case V4L2_CTRL_TYPE_U16:
 		case V4L2_CTRL_TYPE_U32:
 			break;
 		/* \todo Support other control types. */