From c37fbef9c8d35badd784c874cc78c83aeafd2dc5 Mon Sep 17 00:00:00 2001 From: Kieran Bingham Date: Wed, 21 Oct 2020 22:05:39 +0100 Subject: simple-cam: Use friendly camera names Take the example code for generating a camera name from 'cam' and use it when reporting cameras within the simple-cam application. Reviewed-by: Jacopo Mondi Signed-off-by: Kieran Bingham --- simple-cam.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/simple-cam.cpp b/simple-cam.cpp index 6d1d84f..8f7012b 100644 --- a/simple-cam.cpp +++ b/simple-cam.cpp @@ -78,6 +78,47 @@ static void processRequest(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(Camera *camera) +{ + 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() { /* @@ -95,11 +136,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; /* * -------------------------------------------------------------------- -- cgit v1.2.1