[libcamera-devel] [PATCH v2] simple-cam: Use friendly camera names
Kieran Bingham
kieran.bingham at ideasonboard.com
Wed Oct 21 23:07:46 CEST 2020
Hi Kieran,
On 21/10/2020 22:05, Kieran Bingham wrote:
> Take the example code for generating a camera name from 'cam' and use
> it when reporting cameras within the simple-cam application.
>
> Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> ---
> simple-cam.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 44 insertions(+), 3 deletions(-)
>
> diff --git a/simple-cam.cpp b/simple-cam.cpp
> index 727bb6d86480..e62eddf0c8c9 100644
> --- a/simple-cam.cpp
> +++ b/simple-cam.cpp
> @@ -60,6 +60,47 @@ static void requestComplete(Request *request)
> camera->queueRequest(request);
> }
>
> +/*
> + * ----------------------------------------------------------------------------
> + * Camera Naming.
> + *
> + * Applications are responsible for deciding how to name cameras, and present
> + * that information to the users. Every camera has a unique identifier, though
> + * this string is not designed to be friendly for a human reader.
> + *
> + * To support human consumable names, libcamera provides camera properties
> + * that allow an application to determine a naming scheme based on its needs.
> + *
> + * In this example, we focus on the location property, but also detail the
> + * model string for external cameras, as this is more likely to be visible
> + * information to the user of an externally connected device.
> + *
> + * The unique camera ID is appended for informative purposes.
> + */
> +std::string cameraName(libcamera::Camera *camera)
No need for libcamera:: namespace of course, as there is already a using
namespace libcamera; statement in this file.
> +{
> + const ControlList &props = camera->properties();
> + std::string name;
> +
> + switch (props.get(properties::Location)) {
> + case properties::CameraLocationFront:
> + name = "Internal front camera";
> + break;
> + case properties::CameraLocationBack:
> + name = "Internal back camera";
> + break;
> + case properties::CameraLocationExternal:
> + name = "External camera";
> + if (props.contains(properties::Model))
> + name += " '" + props.get(properties::Model) + "'";
> + break;
> + }
> +
> + name += " (" + camera->id() + ")";
> +
> + return name;
> +}
> +
> int main()
> {
> /*
> @@ -77,11 +118,11 @@ int main()
> cm->start();
>
> /*
> - * Just as a test, list all id's of the Camera registered in the
> - * system. They are indexed by name by the CameraManager.
> + * Just as a test, generate names of the Cameras registered in the
> + * system, and list them.
> */
> for (auto const &camera : cm->cameras())
> - std::cout << camera->id() << std::endl;
> + std::cout << " - " << cameraName(camera.get()) << std::endl;
>
> /*
> * --------------------------------------------------------------------
>
--
Regards
--
Kieran
More information about the libcamera-devel
mailing list