From aab49f903e858a2ea9765514bcc26bbd18edd13c Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Fri, 19 Mar 2021 13:48:28 +0100 Subject: cam: Do not assume Location is available In preparation to register the Location property only if the firware interface provides it, do not assume it is available and build the camera name using the camera sensor model as a fallback. Reviewed-by: Paul Elder Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/cam/main.cpp | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'src/cam') diff --git a/src/cam/main.cpp b/src/cam/main.cpp index e01be63a..994fbb34 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -377,23 +377,38 @@ int CamApp::run() std::string const CamApp::cameraName(const Camera *camera) { const ControlList &props = camera->properties(); + bool addModel = true; 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; + /* + * Construct the name from the camera location, model and ID. The model + * is only used if the location isn't present or is set to External. + */ + if (props.contains(properties::Location)) { + switch (props.get(properties::Location)) { + case properties::CameraLocationFront: + addModel = false; + name = "Internal front camera "; + break; + case properties::CameraLocationBack: + addModel = false; + name = "Internal back camera "; + break; + case properties::CameraLocationExternal: + name = "External camera "; + break; + } + } + + if (addModel && props.contains(properties::Model)) { + /* + * If the camera location is not availble use the camera model + * to build the camera name. + */ + name = "'" + props.get(properties::Model) + "' "; } - name += " (" + camera->id() + ")"; + name += "(" + camera->id() + ")"; return name; } -- cgit v1.2.1