[v2] apps: cam: Print enum string for camera properties
diff mbox series

Message ID 20250721124826.8584-1-uajain@igalia.com
State Accepted
Commit c7c40ed1a35e67e9e87c81ae6648594520b0fa1d
Headers show
Series
  • [v2] apps: cam: Print enum string for camera properties
Related show

Commit Message

Umang Jain July 21, 2025, 12:48 p.m. UTC
Some camera properties might be set as a enumeration for e.g.
properties::Location. Instead of printing the int32_t values
for the enumeration, print the enum string as well. This will
enhance the readability for the user.

Signed-off-by: Umang Jain <uajain@igalia.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
Changes in v2:
- Comestic changes 
- Use id->enumerators() to detect controlID has enum values
---
 src/apps/cam/camera_session.cpp | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Kieran Bingham July 21, 2025, 3:52 p.m. UTC | #1
Quoting Umang Jain (2025-07-21 13:48:26)
> Some camera properties might be set as a enumeration for e.g.
> properties::Location. Instead of printing the int32_t values
> for the enumeration, print the enum string as well. This will
> enhance the readability for the user.
> 
> Signed-off-by: Umang Jain <uajain@igalia.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Re-tested:

kbingham@Monstersaurus:~/iob/libcamera/libcamera$ ./build/gcc/src/apps/cam/cam -c1 -p
[175:23:22.197634345] [329642]  INFO IPAManager ipa_manager.cpp:137 libcamera is not installed. Adding '/home/kbingham/iob/libcamera/libcamera/build/gcc/src/ipa' to the IPA search path
[175:23:22.200890094] [329642]  INFO Camera camera_manager.cpp:326 libcamera v0.5.1+89-c7c40ed1
[175:23:22.263920994] [329646]  INFO Pipeline pipeline_handler.cpp:646 libcamera is not installed. Loading platform configuration file from '/home/kbingham/iob/libcamera/libcamera/src/libcamera/pipeline/virtual/data/virtual.yaml'
Using camera \_SB_.PCI0.GP13.XHC0.RHUB.PRT3-3.4:1.0-046d:085e as cam0
Property: SystemDevices = [ 20736 ]
Property: PixelArrayActiveAreas = [ (0, 0)/1920x1080 ]
Property: PixelArraySize = 1920x1080
Property: Location = 2 (CameraLocationExternal)
Property: Model = Logitech BRIO


Looks good to me.

Merging.

--
Kieran


> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> ---
> Changes in v2:
> - Comestic changes 
> - Use id->enumerators() to detect controlID has enum values
> ---
>  src/apps/cam/camera_session.cpp | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/src/apps/cam/camera_session.cpp b/src/apps/cam/camera_session.cpp
> index f63fcb22..1596a25a 100644
> --- a/src/apps/cam/camera_session.cpp
> +++ b/src/apps/cam/camera_session.cpp
> @@ -236,7 +236,17 @@ void CameraSession::listProperties() const
>                 const ControlId *id = properties::properties.at(key);
>  
>                 std::cout << "Property: " << id->name() << " = "
> -                         << value.toString() << std::endl;
> +                         << value.toString();
> +
> +               if (!id->enumerators().empty()) {
> +                       int32_t val = value.get<int32_t>();
> +                       const auto &iter = id->enumerators().find(val);
> +
> +                       if (iter != id->enumerators().end())
> +                               std::cout << " (" << iter->second << ")";
> +               }
> +
> +               std::cout << std::endl;
>         }
>  }
>  
> -- 
> 2.50.0
>

Patch
diff mbox series

diff --git a/src/apps/cam/camera_session.cpp b/src/apps/cam/camera_session.cpp
index f63fcb22..1596a25a 100644
--- a/src/apps/cam/camera_session.cpp
+++ b/src/apps/cam/camera_session.cpp
@@ -236,7 +236,17 @@  void CameraSession::listProperties() const
 		const ControlId *id = properties::properties.at(key);
 
 		std::cout << "Property: " << id->name() << " = "
-			  << value.toString() << std::endl;
+			  << value.toString();
+
+		if (!id->enumerators().empty()) {
+			int32_t val = value.get<int32_t>();
+			const auto &iter = id->enumerators().find(val);
+
+			if (iter != id->enumerators().end())
+				std::cout << " (" << iter->second << ")";
+		}
+
+		std::cout << std::endl;
 	}
 }