From patchwork Thu Jul 15 21:14:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12997 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 556B6C322D for ; Thu, 15 Jul 2021 21:15:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E67D46855F; Thu, 15 Jul 2021 23:15:31 +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="H3Yp+WCF"; 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 CB9066856D for ; Thu, 15 Jul 2021 23:15:13 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 62CF1A24 for ; Thu, 15 Jul 2021 23:15:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1626383713; bh=x2sME4CORzDgpwCutiGghjX8AhrlquBZAo+UqWguuAM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=H3Yp+WCFCQmFqM+PlbZ5wh1pKCCKEkJYrwQkp0+JZ3WppW0zoEtHfv82vxZG6hm1I 2tyHGd0Q9WEAQNotZI0lEK279ZsJBPxZeRMEez7uRlJai+O2fFWVguI6l+/oRJTIgT NJ5jV9fyeC10GH9k2ATbPnbIdJTHXJyuw8LI3gV8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 16 Jul 2021 00:14:53 +0300 Message-Id: <20210715211459.19373-28-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210715211459.19373-1-laurent.pinchart@ideasonboard.com> References: <20210715211459.19373-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 27/33] cam: Move printing of camera information to CameraSession class 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" The three CamApp functions listControls(), listProperties() and infoConfiguration() operate on a camera. They would thus be better placed in the CameraSession class. Move them there. As they now have no error to return anymore, make them void functions. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/cam/camera_session.cpp | 45 +++++++++++++++++ src/cam/camera_session.h | 4 ++ src/cam/main.cpp | 101 ++++++++----------------------------- 3 files changed, 70 insertions(+), 80 deletions(-) diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp index 10e66446ee67..ceb2c3ab3a92 100644 --- a/src/cam/camera_session.cpp +++ b/src/cam/camera_session.cpp @@ -11,6 +11,7 @@ #include #include +#include #include "camera_session.h" #include "event_loop.h" @@ -89,6 +90,50 @@ CameraSession::~CameraSession() camera_->release(); } +void CameraSession::listControls() const +{ + for (const auto &ctrl : camera_->controls()) { + const ControlId *id = ctrl.first; + const ControlInfo &info = ctrl.second; + + std::cout << "Control: " << id->name() << ": " + << info.toString() << std::endl; + } +} + +void CameraSession::listProperties() const +{ + for (const auto &prop : camera_->properties()) { + const ControlId *id = properties::properties.at(prop.first); + const ControlValue &value = prop.second; + + std::cout << "Property: " << id->name() << " = " + << value.toString() << std::endl; + } +} + +void CameraSession::infoConfiguration() const +{ + unsigned int index = 0; + for (const StreamConfiguration &cfg : *config_) { + std::cout << index << ": " << cfg.toString() << std::endl; + + const StreamFormats &formats = cfg.formats(); + for (PixelFormat pixelformat : formats.pixelformats()) { + std::cout << " * Pixelformat: " + << pixelformat.toString() << " " + << formats.range(pixelformat).toString() + << std::endl; + + for (const Size &size : formats.sizes(pixelformat)) + std::cout << " - " << size.toString() + << std::endl; + } + + index++; + } +} + int CameraSession::start(const OptionsParser::Options &options) { int ret; diff --git a/src/cam/camera_session.h b/src/cam/camera_session.h index 88baf9061629..6221aadadf90 100644 --- a/src/cam/camera_session.h +++ b/src/cam/camera_session.h @@ -35,6 +35,10 @@ public: libcamera::Camera *camera() { return camera_.get(); } libcamera::CameraConfiguration *config() { return config_.get(); } + void listControls() const; + void listProperties() const; + void infoConfiguration() const; + int start(const OptionsParser::Options &options); void stop(); diff --git a/src/cam/main.cpp b/src/cam/main.cpp index cba0793ac39b..4fe0c4c368d1 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -39,9 +39,6 @@ private: void cameraRemoved(std::shared_ptr cam); void captureDone(); int parseOptions(int argc, char *argv[]); - int listControls(); - int listProperties(); - int infoConfiguration(); int run(); static std::string cameraName(const Camera *camera); @@ -158,74 +155,6 @@ int CamApp::parseOptions(int argc, char *argv[]) return 0; } -int CamApp::listControls() -{ - if (!session_) { - std::cout << "Cannot list controls without a camera" - << std::endl; - return -EINVAL; - } - - for (const auto &ctrl : session_->camera()->controls()) { - const ControlId *id = ctrl.first; - const ControlInfo &info = ctrl.second; - - std::cout << "Control: " << id->name() << ": " - << info.toString() << std::endl; - } - - return 0; -} - -int CamApp::listProperties() -{ - if (!session_) { - std::cout << "Cannot list properties without a camera" - << std::endl; - return -EINVAL; - } - - for (const auto &prop : session_->camera()->properties()) { - const ControlId *id = properties::properties.at(prop.first); - const ControlValue &value = prop.second; - - std::cout << "Property: " << id->name() << " = " - << value.toString() << std::endl; - } - - return 0; -} - -int CamApp::infoConfiguration() -{ - if (!session_) { - std::cout << "Cannot print stream information without a camera" - << std::endl; - return -EINVAL; - } - - unsigned int index = 0; - for (const StreamConfiguration &cfg : *session_->config()) { - std::cout << index << ": " << cfg.toString() << std::endl; - - const StreamFormats &formats = cfg.formats(); - for (PixelFormat pixelformat : formats.pixelformats()) { - std::cout << " * Pixelformat: " - << pixelformat.toString() << " " - << formats.range(pixelformat).toString() - << std::endl; - - for (const Size &size : formats.sizes(pixelformat)) - std::cout << " - " << size.toString() - << std::endl; - } - - index++; - } - - return 0; -} - void CamApp::cameraAdded(std::shared_ptr cam) { std::cout << "Camera Added: " << cam->id() << std::endl; @@ -269,21 +198,33 @@ int CamApp::run() } if (options_.isSet(OptListControls)) { - ret = listControls(); - if (ret) - return ret; + if (!session_) { + std::cout << "Cannot list controls without a camera" + << std::endl; + return -EINVAL; + } + + session_->listControls(); } if (options_.isSet(OptListProperties)) { - ret = listProperties(); - if (ret) - return ret; + if (!session_) { + std::cout << "Cannot list properties without a camera" + << std::endl; + return -EINVAL; + } + + session_->listProperties(); } if (options_.isSet(OptInfo)) { - ret = infoConfiguration(); - if (ret) - return ret; + if (!session_) { + std::cout << "Cannot print stream information without a camera" + << std::endl; + return -EINVAL; + } + + session_->infoConfiguration(); } if (options_.isSet(OptCapture)) {