From patchwork Wed Oct 21 21:05:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 10193 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E0610BDB13 for ; Wed, 21 Oct 2020 21:05:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6D59460530; Wed, 21 Oct 2020 23:05:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="uc16x8/O"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D86EE60357 for ; Wed, 21 Oct 2020 23:05:42 +0200 (CEST) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5848EBB5; Wed, 21 Oct 2020 23:05:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1603314342; bh=DMgPPDOMCbMb8dYq5+8P9cvjhhHE5lRWc3KUpT+10UY=; h=From:To:Cc:Subject:Date:From; b=uc16x8/OqbObaynfnXGH8o/BGN/V+sYkKzovJa3aBuN5UkKesmZjK8NzFkeDQJ0OG f+ttryztek5y0FrJf7GAIV/9xxva/hobGwedxEbKYjXtCr3vf9KpPv/H2rEZJKdSJ2 5hV/h+NOzlEISptWmkoo8U7bJK10emSFBL/U2SNM= From: Kieran Bingham To: libcamera devel Date: Wed, 21 Oct 2020 22:05:39 +0100 Message-Id: <20201021210539.536155-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] simple-cam: Use friendly camera names X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 --- 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) +{ + 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; /* * --------------------------------------------------------------------