From patchwork Wed Aug 4 12:43:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13202 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 46D33C323A for ; Wed, 4 Aug 2021 12:43:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 62B0568822; Wed, 4 Aug 2021 14:43:37 +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="gvBmz8P2"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 914BD6880F for ; Wed, 4 Aug 2021 14:43:32 +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 2FE5924F for ; Wed, 4 Aug 2021 14:43:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1628081012; bh=ejIfo7arl18wTGGZFQZHf5jQUpwRp/KPZAjU2qhMDjM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gvBmz8P2PiuKz7rgh5YzA3SjUy6GxldmQ59jnBoz+aeD6039wnw2TOo8JLMbPuy3z NVthPYunsOPM9x/wVrDMBhah1Pph+nTCWK9PnImxI3ddWmD/Cw5AaR/jHZZuM64DEy eRbJ+FeNrTeqR+FjvF6NGeMRlbEPR321qlZMfTXA= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Aug 2021 15:43:14 +0300 Message-Id: <20210804124314.8044-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210804124314.8044-1-laurent.pinchart@ideasonboard.com> References: <20210804124314.8044-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Reviewed-by: Paul Elder Reviewed-by: Umang Jain Reviewed-by: Kieran Bingham --- Changes since v2: - Add compile guard around option check Changes since v1: - Validate display option in CamApp::init() --- src/cam/camera_session.cpp | 30 ++++++++++++++++++++++++++++++ src/cam/main.cpp | 6 ++++++ src/cam/main.h | 1 + 3 files changed, 37 insertions(+) diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp index f34a6ed55ad7..60d640f2b15c 100644 --- a/src/cam/camera_session.cpp +++ b/src/cam/camera_session.cpp @@ -16,6 +16,9 @@ #include "camera_session.h" #include "event_loop.h" #include "file_sink.h" +#ifdef HAVE_KMS +#include "kms_sink.h" +#endif #include "main.h" #include "stream_options.h" @@ -66,6 +69,28 @@ CameraSession::CameraSession(CameraManager *cm, bool strictFormats = options_.isSet(OptStrictFormats); +#ifdef HAVE_KMS + if (options_.isSet(OptDisplay)) { + if (options_.isSet(OptFile)) { + std::cerr << "--display and --file options are mutually exclusive" + << std::endl; + return; + } + + if (roles.size() != 1) { + std::cerr << "Display doesn't support multiple streams" + << std::endl; + return; + } + + if (roles[0] != StreamRole::Viewfinder) { + std::cerr << "Display requires a viewfinder stream" + << std::endl; + return; + } + } +#endif + switch (config->validate()) { case CameraConfiguration::Valid: break; @@ -161,6 +186,11 @@ int CameraSession::start() camera_->requestCompleted.connect(this, &CameraSession::requestComplete); +#ifdef HAVE_KMS + if (options_.isSet(OptDisplay)) + sink_ = std::make_unique(options_[OptDisplay].toString()); +#endif + if (options_.isSet(OptFile)) { if (!options_[OptFile].toString().empty()) sink_ = std::make_unique(options_[OptFile]); diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 34cbc3229563..c7f664b903e0 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -132,6 +132,12 @@ int CamApp::parseOptions(int argc, char *argv[]) "Capture until interrupted by user or until frames captured", "capture", ArgumentOptional, "count", false, OptCamera); +#ifdef HAVE_KMS + parser.addOption(OptDisplay, OptionString, + "Display viewfinder through DRM/KMS on specified connector", + "display", ArgumentOptional, "connector", false, + OptCamera); +#endif parser.addOption(OptFile, OptionString, "Write captured frames to disk\n" "If the file name ends with a '/', it sets the directory in which\n" diff --git a/src/cam/main.h b/src/cam/main.h index d22451f59817..1c2fab763698 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',