From patchwork Tue May 19 03:25:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3819 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: 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 776AF603D6 for ; Tue, 19 May 2020 05:25:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="e5xcoQxI"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1F232A1D for ; Tue, 19 May 2020 05:25:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589858721; bh=llEFdOHZMlyTyvwrTy2Iz0NNyRtg8yxj4chub2uUds4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=e5xcoQxIbu//oIJTFm4xazYNbeo71XpEgxI3mM7FzrBDJ5XQOLiSZPzknL7ILl/BQ ntF69DUIqw1Qs4HSFEI1xhbOD1ROmGlkgSsgsBkzzrYNFTzi4li2bixx4i2JrHXk8q C0FNkqZbBHvK3coyGdCYBN/pJ0D6YUZOJ7KqARvk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 19 May 2020 06:25:05 +0300 Message-Id: <20200519032505.17307-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200519032505.17307-1-laurent.pinchart@ideasonboard.com> References: <20200519032505.17307-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 8/8] cam: Add support for viewfinder through DRM/KMS 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: , X-List-Received-Date: Tue, 19 May 2020 03:25:22 -0000 Use the KMSSink class to display the viewfinder stream, if any, through DRM/KMS. The output connector is selected through the new -D/--display argument. Signed-off-by: Laurent Pinchart --- src/cam/capture.cpp | 21 +++++++++++++++++++++ src/cam/main.cpp | 11 +++++++++++ src/cam/main.h | 1 + 3 files changed, 33 insertions(+) diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp index 6982d89fabe7..5b25b2c239f8 100644 --- a/src/cam/capture.cpp +++ b/src/cam/capture.cpp @@ -13,6 +13,9 @@ #include "capture.h" #include "file_sink.h" +#ifdef HAVE_KMS +#include "kms_sink.h" +#endif #include "main.h" using namespace libcamera; @@ -46,6 +49,24 @@ int Capture::run(EventLoop *loop, const OptionsParser::Options &options) camera_->requestCompleted.connect(this, &Capture::requestComplete); +#ifdef HAVE_KMS + if (options.isSet(OptDisplay)) { + if (config_->size() != 1) { + std::cout << "Display doesn't support multiple streams" + << std::endl; + return -EINVAL; + } + + if (roles_[0] != StreamRole::Viewfinder) { + std::cout << "Display requires a viewfinder stream" + << std::endl; + return -EINVAL; + } + + sink_ = new KMSSink(options[OptDisplay].toString()); + } +#endif + if (options.isSet(OptFile)) { if (!options[OptFile].toString().empty()) sink_ = new FileSink(options[OptFile]); diff --git a/src/cam/main.cpp b/src/cam/main.cpp index cdd29d500202..5cd1e929bd88 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -78,6 +78,12 @@ int CamApp::init(int argc, char **argv) if (ret < 0) return ret; + if (options_.isSet(OptDisplay) && options_.isSet(OptFile)) { + std::cout << "--display and --file options are mutually exclusive" + << std::endl; + return -EINVAL; + } + cm_ = new CameraManager(); ret = cm_->start(); @@ -164,6 +170,11 @@ int CamApp::parseOptions(int argc, char *argv[]) ArgumentRequired, "camera"); parser.addOption(OptCapture, OptionNone, "Capture until interrupted by user", "capture"); +#ifdef HAVE_KMS + parser.addOption(OptDisplay, OptionString, + "Display viewfinder through DRM/KMS on specified connector", + "display", ArgumentOptional, "connector"); +#endif parser.addOption(OptFile, OptionString, "Write captured frames to disk\n" "The first '#' character in the file name is expanded to the stream name and frame sequence number.\n" diff --git a/src/cam/main.h b/src/cam/main.h index 4a130d8dd290..57eece507a16 100644 --- a/src/cam/main.h +++ b/src/cam/main.h @@ -10,6 +10,7 @@ enum { OptCamera = 'c', OptCapture = 'C', + OptDisplay = 'D', OptFile = 'F', OptHelp = 'h', OptInfo = 'I',