From patchwork Thu Oct 28 15:48:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Curtin X-Patchwork-Id: 14407 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 7048CBF415 for ; Thu, 28 Oct 2021 15:48:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2A234600B6; Thu, 28 Oct 2021 17:48:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="YPHNgPfm"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5F163600B5 for ; Thu, 28 Oct 2021 17:48:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635436093; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1VRE4ckrQAjRirLPtz0BnD0NnvOFwFFMyCmcYcFYtwU=; b=YPHNgPfmx0kPJQ5JNpJj8wEo93CmHasQJRxopyRxezs87OileRPDv8XlM/guw43Q31ZkSB PZAZ8AKM0+9CcGetvL+Ftzys/UHDdAoIRn8i2D2RYDYiFZmawh03d4OZyk1jyqIF2tl68A KRuUR4+mfjGF0c6tFCrhHI7CTCjxQus= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-403-F0g7So9qO5S7LuQ7PMb_HA-1; Thu, 28 Oct 2021 11:48:11 -0400 X-MC-Unique: F0g7So9qO5S7LuQ7PMb_HA-1 Received: by mail-wr1-f70.google.com with SMTP id f18-20020a5d58f2000000b001645b92c65bso2281070wrd.6 for ; Thu, 28 Oct 2021 08:48:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1VRE4ckrQAjRirLPtz0BnD0NnvOFwFFMyCmcYcFYtwU=; b=Xy/dMbUtEr4llTyrd0NnUS+RQBAPM2EDoTMIUVlVW9vhZYWqj74tOe8jh5FE6E7UGF MJxkUEsGTdJPKf/kSnfJQ6eCik0dXkRkhzFNNZrkBrP4lV57JUzh98A3YdVBOABZfPzc w9QGOB+0FAN2FzQzNH7vOd8/ec6i+HqbuBmsxxejUsTCYErLspCNLKCYdTRLUAbwjrPX YPaBDgB0uJvv1Umznd2xC8/ZVRo8IJi4e+JZCtYdkuJkkW3waeV5CDNWyRIg1vh116M6 a5/UzQBXo2Yw7D/VUfOfMkDXILpiLCPd+JYoJHKi9ChFrZd1NYVFq1DD687SMUdKBr1a 2/Ig== X-Gm-Message-State: AOAM530xeoENmpLWwuXS+QfByHShSXpTxwvPZSd6A9TFpnylWsoNJl2A joghaj2ip8RUhp79U2LNn7vvqbVNJtZcq9yq7+5zRMC7gMIcsVt3Auq//uU7Rn4VsZxMrdernWC OLeQnG8rBzmIavkfAN4lZA9Pl6s5Rej0LwY6uDue9BmpvUueFBKY3R9Ug1A1p26nve6Xsst7Kno 4zDpYAnlDT X-Received: by 2002:adf:f209:: with SMTP id p9mr4138035wro.191.1635436090431; Thu, 28 Oct 2021 08:48:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4bPeQ8sfmCSjUvLiKcKXZz/76kvVe4RHex/VHfYNa7zYon2nhjQ4z8ruSmqXoJIWW3ek09w== X-Received: by 2002:adf:f209:: with SMTP id p9mr4138000wro.191.1635436090150; Thu, 28 Oct 2021 08:48:10 -0700 (PDT) Received: from curtine-ThinkPad-P1-Gen-3.Home ([2001:8a0:6724:4500:dc68:d331:1862:9fcb]) by smtp.gmail.com with ESMTPSA id s8sm3430627wrr.15.2021.10.28.08.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 08:48:09 -0700 (PDT) From: Eric Curtin To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 16:48:07 +0100 Message-Id: <20211028154807.36128-1-ecurtin@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [libcamera-devel] [PATCH] cam: Add option to list displays 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" So the user does not have to be familiar with internals of /sys/class/drm/. "xrand --query" names aren't consistent with DRM names and depend on an X server running. This --list-displays option will show the names of the available displays and whether each display's status is connected, disconnected or unknown. Signed-off-by: Eric Curtin --- src/cam/drm.cpp | 3 +++ src/cam/drm.h | 2 ++ src/cam/main.cpp | 28 +++++++++++++++++++++++----- src/cam/main.h | 3 +++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/cam/drm.cpp b/src/cam/drm.cpp index f2530091..444d639d 100644 --- a/src/cam/drm.cpp +++ b/src/cam/drm.cpp @@ -190,15 +190,18 @@ Connector::Connector(Device *dev, const drmModeConnector *connector) switch (connector->connection) { case DRM_MODE_CONNECTED: status_ = Status::Connected; + status_str_ = "connected"; break; case DRM_MODE_DISCONNECTED: status_ = Status::Disconnected; + status_str_ = "disconnected"; break; case DRM_MODE_UNKNOWNCONNECTION: default: status_ = Status::Unknown; + status_str_ = "unknown"; break; } diff --git a/src/cam/drm.h b/src/cam/drm.h index 0b88f9a3..92acd826 100644 --- a/src/cam/drm.h +++ b/src/cam/drm.h @@ -187,6 +187,7 @@ public: const std::string &name() const { return name_; } Status status() const { return status_; } + const std::string &status_str() const { return status_str_; } const std::vector &encoders() const { return encoders_; } const std::vector &modes() const { return modes_; } @@ -194,6 +195,7 @@ public: private: uint32_t type_; std::string name_; + std::string status_str_; Status status_; std::vector encoders_; std::vector modes_; diff --git a/src/cam/main.cpp b/src/cam/main.cpp index c7f664b9..cd1ccf2f 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -15,6 +15,11 @@ #include #include "camera_session.h" + +#ifdef HAVE_KMS +#include "drm.h" +#endif + #include "event_loop.h" #include "main.h" #include "options.h" @@ -137,6 +142,7 @@ int CamApp::parseOptions(int argc, char *argv[]) "Display viewfinder through DRM/KMS on specified connector", "display", ArgumentOptional, "connector", false, OptCamera); + parser.addOption(OptListDisplays, OptionNone, "List all displays", "list-displays"); #endif parser.addOption(OptFile, OptionString, "Write captured frames to disk\n" @@ -202,7 +208,19 @@ int CamApp::run() } } - /* 2. Create the camera sessions. */ +#ifdef HAVE_KMS + /* 2. List all displays. */ + if (options_.isSet(OptListDisplays)) { + DRM::Device dev; + if (dev.init() >= 0) { + std::cout << "Available displays:" << std::endl; + for (const DRM::Connector &conn : dev.connectors()) + std::cout << "name: " << conn.name() << " status: " << conn.status_str() << std::endl; + } + } +#endif + + /* 3. Create the camera sessions. */ std::vector> sessions; if (options_.isSet(OptCamera)) { @@ -229,7 +247,7 @@ int CamApp::run() } } - /* 3. Print camera information. */ + /* 4. Print camera information. */ if (options_.isSet(OptListControls) || options_.isSet(OptListProperties) || options_.isSet(OptInfo)) { @@ -243,7 +261,7 @@ int CamApp::run() } } - /* 4. Start capture. */ + /* 5. Start capture. */ for (const auto &session : sessions) { if (!session->options().isSet(OptCapture)) continue; @@ -257,7 +275,7 @@ int CamApp::run() loopUsers_++; } - /* 5. Enable hotplug monitoring. */ + /* 6. Enable hotplug monitoring. */ if (options_.isSet(OptMonitor)) { std::cout << "Monitoring new hotplug and unplug events" << std::endl; std::cout << "Press Ctrl-C to interrupt" << std::endl; @@ -271,7 +289,7 @@ int CamApp::run() if (loopUsers_) loop_.exec(); - /* 6. Stop capture. */ + /* 7. Stop capture. */ for (const auto &session : sessions) { if (!session->options().isSet(OptCapture)) continue; diff --git a/src/cam/main.h b/src/cam/main.h index 1c2fab76..72050d27 100644 --- a/src/cam/main.h +++ b/src/cam/main.h @@ -21,6 +21,9 @@ enum { OptListControls = 256, OptStrictFormats = 257, OptMetadata = 258, +#ifdef HAVE_KMS + OptListDisplays = 259 +#endif }; #endif /* __CAM_MAIN_H__ */