diff options
author | Kieran Bingham <kieran.bingham@ideasonboard.com> | 2020-10-21 22:05:39 +0100 |
---|---|---|
committer | Kieran Bingham <kieran.bingham@ideasonboard.com> | 2020-12-04 10:33:09 +0000 |
commit | c37fbef9c8d35badd784c874cc78c83aeafd2dc5 (patch) | |
tree | fc3f7ec5fb63f462073592f698b710a889188081 | |
parent | b79a04afa753d5cfda47faee9bb4fc7b46c78b01 (diff) |
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 <jacopo@jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
-rw-r--r-- | simple-cam.cpp | 47 |
1 files 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; /* * -------------------------------------------------------------------- |