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

Message ID 20250703140631.29979-1-uajain@igalia.com
State Accepted
Headers show
Series
  • apps: cam: Print enum string for camera properties
Related show

Commit Message

Umang Jain July 3, 2025, 2:06 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>
---
 src/apps/cam/camera_session.cpp | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Kieran Bingham July 8, 2025, 12:52 p.m. UTC | #1
Quoting Umang Jain (2025-07-03 15:06:31)
> 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>
> ---
>  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..feef1585 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 (value.type() == ControlTypeInteger32) {
> +                       int32_t val = value.get<int32_t>();
> +                       const auto &iter = id->enumerators().find(val);
> +
> +                       if (iter != id->enumerators().end())
> +                               std::cout << " [ " << iter->second << " ]";
> +               }

kbingham@Monstersaurus:~/iob/libcamera/libcamera$ ./build/gcc/src/apps/cam/cam -c1 -p
[229:51:49.724482741] [993813]  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
[229:51:49.728307982] [993813]  INFO Camera camera_manager.cpp:326 libcamera v0.5.1+52-c25425a4
[229:51:49.793623769] [993816]  INFO Pipeline pipeline_handler.cpp:618 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


Yeah, I like that...

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

> +
> +               std::cout << std::endl;
>         }
>  }
>  
> -- 
> 2.50.0
>
Barnabás Pőcze July 9, 2025, 7:16 a.m. UTC | #2
Hi


2025. 07. 08. 14:52 keltezéssel, Kieran Bingham írta:
> Quoting Umang Jain (2025-07-03 15:06:31)
>> 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>
>> ---
>>   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..feef1585 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 (value.type() == ControlTypeInteger32) {

Maybe `!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 << " ]";
>> +               }
> 
> kbingham@Monstersaurus:~/iob/libcamera/libcamera$ ./build/gcc/src/apps/cam/cam -c1 -p
> [229:51:49.724482741] [993813]  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
> [229:51:49.728307982] [993813]  INFO Camera camera_manager.cpp:326 libcamera v0.5.1+52-c25425a4
> [229:51:49.793623769] [993816]  INFO Pipeline pipeline_handler.cpp:618 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 ]

To me, using "( ... )" instead of "[ ... ]" (which is already used for arrays)
would be a bit clearer.

Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>


Regards,
Barnabás Pőcze


> Property: Model = Logitech BRIO
> 
> 
> Yeah, I like that...
> 
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
>> +
>> +               std::cout << std::endl;
>>          }
>>   }
>>   
>> -- 
>> 2.50.0
>>
Kieran Bingham July 21, 2025, 11:51 a.m. UTC | #3
Umang,

Any feedback on the below? Will you post a v2 or do you want this
version merged?

--
Kieran

Quoting Barnabás Pőcze (2025-07-09 08:16:09)
> Hi
> 
> 
> 2025. 07. 08. 14:52 keltezéssel, Kieran Bingham írta:
> > Quoting Umang Jain (2025-07-03 15:06:31)
> >> 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>
> >> ---
> >>   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..feef1585 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 (value.type() == ControlTypeInteger32) {
> 
> Maybe `!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 << " ]";
> >> +               }
> > 
> > kbingham@Monstersaurus:~/iob/libcamera/libcamera$ ./build/gcc/src/apps/cam/cam -c1 -p
> > [229:51:49.724482741] [993813]  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
> > [229:51:49.728307982] [993813]  INFO Camera camera_manager.cpp:326 libcamera v0.5.1+52-c25425a4
> > [229:51:49.793623769] [993816]  INFO Pipeline pipeline_handler.cpp:618 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 ]
> 
> To me, using "( ... )" instead of "[ ... ]" (which is already used for arrays)
> would be a bit clearer.
> 
> Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> 
> 
> Regards,
> Barnabás Pőcze
> 
> 
> > Property: Model = Logitech BRIO
> > 
> > 
> > Yeah, I like that...
> > 
> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > 
> >> +
> >> +               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..feef1585 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 (value.type() == ControlTypeInteger32) {
+			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;
 	}
 }