From patchwork Wed Mar 15 10:22:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 18403 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 C1FF0C3263 for ; Wed, 15 Mar 2023 10:23:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4F2C762710; Wed, 15 Mar 2023 11:23:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678875790; bh=2cvQaGtnoIqMdmnYnTkS9L5wb/oeWw5111IC9HCyQCA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=g6tORs6W3qF6R3JhFCh8Sfrq5nW5wsKuqLp24nCBeNkA8SxuecRvvm9sm7NFwWssW GcbJMKG3f4EyX9vFm1U3m3r6uDmSUKTp3Z49lKAmOY/0CxDJkpCXiPdKzDOICfoav9 8MT3k6uCldMGWkNjJ0NhT6qCmEEhNMu9AnpFI6Zierwn8Fl3e1AVnjYOHx08gSPYz/ eh+EtgdK4tvZ77XfQW8ESbnmgX93bQ31h/INMHacBUwQskrQJXqWue2KzX39+8kneX cRwVooGK5Nhu4A39J4Nj5ogzhd+AHGGxsOdJIgSL/9d/KTWJQYmJAPPjNnyqd9uKrL DAANMSCS00yNg== Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A562461ED2 for ; Wed, 15 Mar 2023 11:23:08 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="esh382bq"; dkim-atps=neutral Received: by mail-pj1-x102a.google.com with SMTP id om3-20020a17090b3a8300b0023efab0e3bfso1188761pjb.3 for ; Wed, 15 Mar 2023 03:23:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1678875787; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E1+F3oSK6UpV4JEY1nZu+MgbDhGpFB/0GAG68op+4Lo=; b=esh382bqvS5e190fQDlGtZGVM4I49bDmkxztIMc6rR3LCz3/bOzV/AYZVPWGcnZak+ af5EnWagyl4skTJfu5H9Zi0DAIpocpbvL711UFLJTTMMxMo1nGP7rgVkbfV1eEmG8e7E GV4Oj3VMdG/mdhQqfb3viLH1irxkz5CBTiXJY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678875787; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E1+F3oSK6UpV4JEY1nZu+MgbDhGpFB/0GAG68op+4Lo=; b=ZBf5o5lQDXS9msS6d/r885lfWKRpaHtB1/6QbKHEVybBXKi+Q+bt3bUwIUdPB8hO02 yy54IZ3CU02CzfLlKMteYNCjK2JXIVCAadOpIttVFA7J1VWM7vmFRI8s+KRilxNvLwGl ACp4vJisDPM28nfxYSszBWbewDXxV5SVb+4RlKX6sIzrWGBOe8G0V6O6SZ39mnT1T7vJ Bj2EwQyScZ+O6KIuB9sIKgBT9s7Ls+F8X58mabz2eMxDu4WiwxKcsFBWV/hdgHZgwHSa thySCaTcQdkExy8Pm4B0ewXo5RYWCWL3TRHQ0UJpegzRSxROb6BAvD4HINbNIWK0qFrH vaJQ== X-Gm-Message-State: AO0yUKXaHGgIKIzIsB5LAba25mnIdcaWSyTY5ZGW3uELidVAxEGxPjKe +zpUJtrLS29xsry7kb306mubw77+mP6qnrHb7kc= X-Google-Smtp-Source: AK7set9H/aB2AE0onUgoV6Eq4pVg+UhsgLbWzabjMnJDeWusaH3zYY59umpF6JUkIepH0xPatNQGQg== X-Received: by 2002:a17:903:283:b0:1a1:78e6:d600 with SMTP id j3-20020a170903028300b001a178e6d600mr1722493plr.10.1678875787020; Wed, 15 Mar 2023 03:23:07 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (112.157.221.35.bc.googleusercontent.com. [35.221.157.112]) by smtp.gmail.com with ESMTPSA id f11-20020a17090274cb00b001a0450da45csm3262786plt.185.2023.03.15.03.23.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 03:23:06 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Mar 2023 10:22:55 +0000 Message-Id: <20230315102300.2265491-2-chenghaoyang@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230315102300.2265491-1-chenghaoyang@google.com> References: <20230315102300.2265491-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 1/6] libcamera: pipeline: Accept a camera having no MediaDevice 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-Patchwork-Original-From: Harvey Yang via libcamera-devel From: Harvey Yang Reply-To: Harvey Yang Cc: Harvey Yang , Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The Fatal check of having at least one MediaDevice was to prevent pipeline handler implementations searching and owning media devices with custom conventions, instead of using the base function |acquireMediaDevice|. It also has the assumption that there's at least one media device to make a camera work. Now that the assumption will be broken by the virtual pipeline handler added in the following patches, and developers should be aware of the available functions in the base class to handle media devices, the Fatal check is no longer needed. Signed-off-by: Harvey Yang --- src/libcamera/pipeline_handler.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index f72613b8..21979ea5 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -604,10 +604,6 @@ void PipelineHandler::registerCamera(std::shared_ptr camera) { cameras_.push_back(camera); - if (mediaDevices_.empty()) - LOG(Pipeline, Fatal) - << "Registering camera with no media devices!"; - /* * Walk the entity list and map the devnums of all capture video nodes * to the camera. From patchwork Wed Mar 15 10:22:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 18404 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 4204FC329C for ; Wed, 15 Mar 2023 10:23:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AD2A162716; Wed, 15 Mar 2023 11:23:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678875793; bh=iFXqHYoFKWXepKlMDxgEtxPjO8QSRvqtfHHnkO043BQ=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=SaxK07BoDUncoElBv/VNnOa8GkQ6LzR90uO89XucysdhrQaZlUjB1WK6DvnYIYKX9 fz5H0a0VUhj1bCa2vJZ4Gpv/Euf0XGDEDqD37+hvKvB4qpMh8u39ftpQkqeBmOF9lp j6eCC0WhNkVE/fsV/G+1mJ5nu7IBIQaIgCKE3lfAR+DAUpjM8lfqmRM/NDu4VB0Tba dbvSuNJ7xlhIA/pIVVeVUC07YoSTXnAXGcQiGEVi53TnlKO2/yP9V1WC81wuKTh7/d 1mYnOt2xKCERVAoayI367vwqd12tH0bDjv0Qds/jf/6L+0u+QGvIENf+lzpayxx8mx 7MlbkbsbWP1oQ== Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 047CA6270E for ; Wed, 15 Mar 2023 11:23:10 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Ko4SPckh"; dkim-atps=neutral Received: by mail-pl1-x631.google.com with SMTP id k2so11614676pll.8 for ; Wed, 15 Mar 2023 03:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1678875788; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q2hJRJQUm2hdQ8RypAyWYv8oIhLrv4kcdesIXc38Mr4=; b=Ko4SPckhuC8kk4/WosibZx+3B3Oj7jjp2znwfJCqJQ77pubqUc8GTsraw6rcYZmr2J kVWxcNgxLCEEF6Ji/vJFULRC9kuVgVcbIg8XakAOPcGhT7todE13A22NaUyMRvrzgRgU up26wHqkpmhUAf959yFe3LfVn+QtbuLQMedJw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678875788; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q2hJRJQUm2hdQ8RypAyWYv8oIhLrv4kcdesIXc38Mr4=; b=wMwyDFxRV+4qlZDv9ifuM65kEVCyBQUNZSa7m6l2SpUSx/klBrZCIEclSGrdaNRqqo 8HH6fMcOKiMisptSrIlzZc2ixehAt7U0u2dAZVOLm71NflKnPBH2mW/sCCHWwyYva2ps 93RBA6XZv84XydyVq7LSpgnZYrSlydCWjtZ5Re6QkjhmH3KKZflC6cauoB5vn1UEayWT Spn07XYmlc7b4RHt7KcCTesqwmjhW7sne7f6mbP0j3WV/94Qb70WQDspvbfLAxIxevA1 Upt3Lv2z63wZdL6DAJz4d3iYbiIIeTEDpMlXgTolkIQ7VC7PTgMkmAhbQlxudG7utZPE b0iw== X-Gm-Message-State: AO0yUKXD6QHfOR8olF6ti41NhuA5chVZgE/FklKgWZt48fplCKFOmXko O4UDB4BpD7wmPtvX/AsK/NesoKEDjP+gmv50JNs= X-Google-Smtp-Source: AK7set9ABZJ4N2Tl87BYDB2eSixW7XBtpSr9u4Mwx+s6plIhz8PnPOnu/7cy0dmwVNdPvrocy5NtCA== X-Received: by 2002:a17:90b:33c2:b0:23d:30c4:a06 with SMTP id lk2-20020a17090b33c200b0023d30c40a06mr6344948pjb.11.1678875788230; Wed, 15 Mar 2023 03:23:08 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (112.157.221.35.bc.googleusercontent.com. [35.221.157.112]) by smtp.gmail.com with ESMTPSA id f11-20020a17090274cb00b001a0450da45csm3262786plt.185.2023.03.15.03.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 03:23:07 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Mar 2023 10:22:56 +0000 Message-Id: <20230315102300.2265491-3-chenghaoyang@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230315102300.2265491-1-chenghaoyang@google.com> References: <20230315102300.2265491-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/6] libcamera: pipeline: Introduce skeleton Virtual Pipeline 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-Patchwork-Original-From: Harvey Yang via libcamera-devel From: Harvey Yang Reply-To: Harvey Yang Cc: Harvey Yang , Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Provide all of the skeleton stubs to succesfully compile and register the Virtual Pipeline Handler for testing with fake data. Meson must be reconfigured to ensure that this pipeline handler is included in the selected pipelines configuration. Signed-off-by: Harvey Yang --- meson.build | 1 + meson_options.txt | 3 +- src/libcamera/pipeline/virtual/meson.build | 5 + src/libcamera/pipeline/virtual/virtual.cpp | 112 +++++++++++++++++++++ 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/libcamera/pipeline/virtual/meson.build create mode 100644 src/libcamera/pipeline/virtual/virtual.cpp diff --git a/meson.build b/meson.build index 9eee9d39..f00e3daa 100644 --- a/meson.build +++ b/meson.build @@ -176,6 +176,7 @@ pipelines_support = { 'simple': arch_arm, 'uvcvideo': ['any'], 'vimc': ['test'], + 'virtual': ['test'], } if pipelines.contains('all') diff --git a/meson_options.txt b/meson_options.txt index 78a78b72..a0a75e7f 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -47,7 +47,8 @@ option('pipelines', 'rkisp1', 'simple', 'uvcvideo', - 'vimc' + 'vimc', + 'virtual' ], description : 'Select which pipeline handlers to build. If this is set to "auto", all the pipelines applicable to the target architecture will be built. If this is set to "all", all the pipelines will be built. If both are selected then "all" will take precedence.') diff --git a/src/libcamera/pipeline/virtual/meson.build b/src/libcamera/pipeline/virtual/meson.build new file mode 100644 index 00000000..ba7ff754 --- /dev/null +++ b/src/libcamera/pipeline/virtual/meson.build @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: CC0-1.0 + +libcamera_sources += files([ + 'virtual.cpp', +]) diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp new file mode 100644 index 00000000..09583b4e --- /dev/null +++ b/src/libcamera/pipeline/virtual/virtual.cpp @@ -0,0 +1,112 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * fake.cpp - Pipeline handler for fake cameras + */ + +#include + +#include + +#include "libcamera/internal/pipeline_handler.h" + +namespace libcamera { + +LOG_DEFINE_CATEGORY(VIRTUAL) + +class VirtualCameraConfiguration : public CameraConfiguration +{ +public: + VirtualCameraConfiguration(); + + Status validate() override; +}; + +class PipelineHandlerVirtual : public PipelineHandler +{ +public: + PipelineHandlerVirtual(CameraManager *manager); + + std::unique_ptr generateConfiguration(Camera *camera, + const StreamRoles &roles) override; + int configure(Camera *camera, CameraConfiguration *config) override; + + int exportFrameBuffers(Camera *camera, Stream *stream, + std::vector> *buffers) override; + + int start(Camera *camera, const ControlList *controls) override; + void stopDevice(Camera *camera) override; + + int queueRequestDevice(Camera *camera, Request *request) override; + + bool match(DeviceEnumerator *enumerator) override; +}; + +VirtualCameraConfiguration::VirtualCameraConfiguration() + : CameraConfiguration() +{ +} + +CameraConfiguration::Status VirtualCameraConfiguration::validate() +{ + return Invalid; +} + +PipelineHandlerVirtual::PipelineHandlerVirtual(CameraManager *manager) + : PipelineHandler(manager) +{ +} + +std::unique_ptr PipelineHandlerVirtual::generateConfiguration(Camera *camera, + const StreamRoles &roles) +{ + (void)camera; + (void)roles; + return std::unique_ptr(nullptr); +} + +int PipelineHandlerVirtual::configure(Camera *camera, CameraConfiguration *config) +{ + (void)camera; + (void)config; + return -1; +} + +int PipelineHandlerVirtual::exportFrameBuffers(Camera *camera, Stream *stream, + std::vector> *buffers) +{ + (void)camera; + (void)stream; + (void)buffers; + return -1; +} + +int PipelineHandlerVirtual::start(Camera *camera, const ControlList *controls) +{ + (void)camera; + (void)controls; + return -1; +} + +void PipelineHandlerVirtual::stopDevice(Camera *camera) +{ + (void)camera; +} + +int PipelineHandlerVirtual::queueRequestDevice(Camera *camera, Request *request) +{ + (void)camera; + (void)request; + return -1; +} + +bool PipelineHandlerVirtual::match(DeviceEnumerator *enumerator) +{ + (void)enumerator; + return false; +} + +REGISTER_PIPELINE_HANDLER(PipelineHandlerVirtual) + +} /* namespace libcamera */ From patchwork Wed Mar 15 10:22:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 18405 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 B4CDEBD80A for ; Wed, 15 Mar 2023 10:23:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5020262713; Wed, 15 Mar 2023 11:23:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678875796; bh=CentXDF8+nDFGMuylFGBwlDbJfTcAFRpcnll8D9Wb+o=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=DzIJ/DhLrVVh9FbH6ePFpnc9GTJb1P66mRD87/wv9a04Q2SRgQpKWM5muYFxxqS0b i7ae+5PkufKJa4UQ3N5eqyNebO0J/bemyf3jVBfs6geDdQr+Bbr9ouSD3LRHs8NtU8 g49NsZvpxPeSPKRAcyX01Dlrry4t3+US+wrRsOwXM5CcgmiAiuAGgrCTeTvotqz8xC H7wKtkYEqrdSLdsJGVXCao1KKUEq0uUs4Q/UNRLdYoc8CzYJBRcflUVPaqqyyzPC6y Om096cODvjPDC1PiLE0bNjYLkG9YGvsRpsyBJHjrYgdJSFHI4E8CUiEwfnvPc6PGOo PzKdX5+RGpcqQ== Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 272F361ED2 for ; Wed, 15 Mar 2023 11:23:11 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="JDtR1mDw"; dkim-atps=neutral Received: by mail-pl1-x633.google.com with SMTP id k2so11614723pll.8 for ; Wed, 15 Mar 2023 03:23:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1678875789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pAw5c9JTwxEQpNQNeVzTS98+ZCH/QfhvpXbHNCRsR4c=; b=JDtR1mDwaan7B9e71NUX5c5pcGwCLlyaW1WKQeLlflDYkpN1duroB8H0PVQnA7E+n5 fpE3W2bNmDsVsK8MPAUcC+YKnRTPYrbbLmpjEACWbYXWlvR0R4y0JpUClsrqbsF+v99p BhqJULgTd7nYoELOPlIkJz1m0kGgR+sLUdAqI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678875789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pAw5c9JTwxEQpNQNeVzTS98+ZCH/QfhvpXbHNCRsR4c=; b=rUJjL+sVLz47aqyO72jBiWHYR3sm3hb9LD0tRyB3fiMp5NTS8cif2Fip6LoZCW/IME aXeYTMzHtRJUHS3xMFOS+miMEagRCzaKnQO56MwEC7fxbkgl6DVTZqYAc9Uaaw0ayARb rOszNJudZZxze+s66mCl85+cepmL3i7J+iIE+k2ScPp2/IAFz+v/n0XJJY+mKYh7Rdk2 fRpnaVbP3Y3MdtQBOX+S1Qez//LIu8jeRtDVdIDWRQqt9RhmTWKxMpCjA/5e1mBTuEIi A3ccQYIbTF7Pfw7GqHcr0cvXyqJEse/yiCahqLgRyjp2x/59ZObGdXwiDisz3F79T2Om d3pg== X-Gm-Message-State: AO0yUKV8b7pwpnR0Qp0uGWV2/nCLQqmf89bXTUR5HdOkoEBrLPeL9bPk h5RucrP2IV1rv1iTG12XPbhBsxcTF2VishhyWes= X-Google-Smtp-Source: AK7set+p7u5yWRPw11mucEfZMscO9uOzOWiQlFwujhXK/r1sjhMWMF8MB+6n/BG49mlsRhcC+xwd0Q== X-Received: by 2002:a17:90b:17c4:b0:234:e0c:caaa with SMTP id me4-20020a17090b17c400b002340e0ccaaamr42338943pjb.6.1678875789470; Wed, 15 Mar 2023 03:23:09 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (112.157.221.35.bc.googleusercontent.com. [35.221.157.112]) by smtp.gmail.com with ESMTPSA id f11-20020a17090274cb00b001a0450da45csm3262786plt.185.2023.03.15.03.23.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 03:23:09 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Mar 2023 10:22:57 +0000 Message-Id: <20230315102300.2265491-4-chenghaoyang@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230315102300.2265491-1-chenghaoyang@google.com> References: <20230315102300.2265491-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 3/6] libcamera: pipeline: virtual: Create a Camera 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-Patchwork-Original-From: Harvey Yang via libcamera-devel From: Harvey Yang Reply-To: Harvey Yang Cc: Harvey Yang , Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Create a VirtualCameraData inheriting from the CameraData to handle camera specific data, and use it to create and register the camera with the CameraManager. This can now be tested to see that the camera becomes available to applications: """ build/src/apps/cam/cam -l [550:47:04.505850647] [1969734] INFO IPAManager ipa_manager.cpp:143 libcamera is not installed. Adding ... to the IPA search path [550:47:04.509307667] [1969734] INFO Camera camera_manager.cpp:293 libcamera v0.0.1+54-55fecb4d-dirty (2022-12-01T05:47:11+00:00) Available cameras: 1: (Virtual0) """ Signed-off-by: Harvey Yang --- src/libcamera/pipeline/virtual/virtual.cpp | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp index 09583b4e..1d66a60e 100644 --- a/src/libcamera/pipeline/virtual/virtual.cpp +++ b/src/libcamera/pipeline/virtual/virtual.cpp @@ -9,12 +9,26 @@ #include +#include "libcamera/internal/camera.h" #include "libcamera/internal/pipeline_handler.h" namespace libcamera { LOG_DEFINE_CATEGORY(VIRTUAL) +class VirtualCameraData : public Camera::Private +{ +public: + VirtualCameraData(PipelineHandler *pipe) + : Camera::Private(pipe) + { + } + + ~VirtualCameraData() = default; + + Stream stream_; +}; + class VirtualCameraConfiguration : public CameraConfiguration { public: @@ -104,7 +118,15 @@ int PipelineHandlerVirtual::queueRequestDevice(Camera *camera, Request *request) bool PipelineHandlerVirtual::match(DeviceEnumerator *enumerator) { (void)enumerator; - return false; + + std::unique_ptr data = std::make_unique(this); + /* Create and register the camera. */ + std::set streams{ &data->stream_ }; + const std::string id = "Virtual0"; + std::shared_ptr camera = Camera::create(std::move(data), id, streams); + registerCamera(std::move(camera)); + + return false; // Prevent infinite loops for now } REGISTER_PIPELINE_HANDLER(PipelineHandlerVirtual) From patchwork Wed Mar 15 10:22:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 18406 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 892D5C329D for ; Wed, 15 Mar 2023 10:23:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 34B8B62717; Wed, 15 Mar 2023 11:23:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678875797; bh=HUipLLAsOu56sfyzx2B4T69Uh/inoCt+MZJMElAJvFU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Xhvhune9v+pmKouFAK53auzYrAsCFgoPJdWgFRLYf3tfk+GpMVTDmyImEQZ9nT5Ml F5rfqcJ9tyfFifLBR4NN4L+RKRmlN6Wbzf3LhNuKsv6yRau3ljMeEbWCFEhHrUv1hh SB433WgdajxDshr4zh6zhGSwwmfrOJ7Ol6DnkVm8sqQdkPh57cSRpy6S60MoFY+9sq M8KoXmCxSJxrPpPCMll+T2XR7oJama1ZCtXE9PyYYAVk8GxVPXju85INeqD1VHT9J6 dKncUJszGbOpGPGKtCbmfJHyiZ+dMM0fVR0Sq9/qal3zoLAi0MFCIdrI66/bVK6RxB YMNXuvxSbHe1w== Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5D6F86270A for ; Wed, 15 Mar 2023 11:23:12 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="eCCOWHrI"; dkim-atps=neutral Received: by mail-pj1-x1036.google.com with SMTP id j3-20020a17090adc8300b0023d09aea4a6so1307923pjv.5 for ; Wed, 15 Mar 2023 03:23:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1678875791; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7qQMFEtbq07W1ElR7VQSKGYfnRAtU6ZCdE527E1pQg8=; b=eCCOWHrI1DLPvw6F0WHO/eQWFVNpULTR/dT4v7kkgfcGnbGpnGr6G1DC5YzKOTQ87G IVAd1s/fl7+B2soUCzsD9o17Az7DmopgqVtWgd13hCl8Rx8YwBn2ArhgyF9pFpZzGYkY BzkD9nG0KGIANU6F37BKUe2CDRTWoXBm/wQuY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678875791; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7qQMFEtbq07W1ElR7VQSKGYfnRAtU6ZCdE527E1pQg8=; b=uHx1ozjlMiMk2KXzdWxJgmTrUxS9ZW+TsYsAjwPC/Zp4eyvRcBpAsYStMs05w+Fiwl A0FxPpswVRvK5cOMK0Z28R+Zw/b/ee3KayFsNEfgGcDJCPz4LOqWJfyjXit3l8/lxUq7 udIoVdJ7N2QtuADxHjou9+BTiqr+sCQHGnpRCqIfyCszpOasdvo+uGTLNk0heG/S3A8q NxUFFidRuKUPpcec8mt/NMUXwF2vvOYNGV1CMtBbPcs4AgaMdBTHclipAfzlupqfP7aS rfBWus7yL/9gguhxwpUUBGXObYGe5E5SbttZapbQOA4Me2nrBoVqTQdiAu9dFMZfaeSO mYqA== X-Gm-Message-State: AO0yUKXy6RcxwP46+CStNHcIgJZW42Ut1VK2TYaXoDafrsLm1NQDWy0/ 8tBxpJQW54ObI5VEmSS0uyi4kwH1HT7zRxoAvh0= X-Google-Smtp-Source: AK7set8VGkp66r87LETsvWbU9qXx9XNAwjNzBZBpyxmmlLIKkkQDbsv9qatDiu7CbuyRUiejFVH3vA== X-Received: by 2002:a17:903:1106:b0:19d:7a4:4063 with SMTP id n6-20020a170903110600b0019d07a44063mr2659643plh.46.1678875790682; Wed, 15 Mar 2023 03:23:10 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (112.157.221.35.bc.googleusercontent.com. [35.221.157.112]) by smtp.gmail.com with ESMTPSA id f11-20020a17090274cb00b001a0450da45csm3262786plt.185.2023.03.15.03.23.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 03:23:10 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Mar 2023 10:22:58 +0000 Message-Id: <20230315102300.2265491-5-chenghaoyang@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230315102300.2265491-1-chenghaoyang@google.com> References: <20230315102300.2265491-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 4/6] libcamera: pipeline: virtual: Generate and validate StreamConfigurations 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-Patchwork-Original-From: Harvey Yang via libcamera-devel From: Harvey Yang Reply-To: Harvey Yang Cc: Harvey Yang , Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Implement the support for Generating and Validating the streams the Camera can provide. Currently use only one camera with fixed configuration. Will add a configuration file to specify virtual cameras. In |PipelineHandlerVirtual::configure|, nothing needs to be done. Test the configurations can be generated and reported with cam -I: """ build/src/apps/cam/cam -c 1 -I [45:19:28.901456135] [2611530] INFO IPAManager ipa_manager.cpp:143 libcamera is not installed. Adding '/usr/local/google/home/chenghaoyang/cros2/src/third_party/libcamera/build/src /ipa' to the IPA search path [45:19:28.904364465] [2611530] INFO Camera camera_manager.cpp:293 libcamera v0.0.1+56-4f4554fa-dirty (2022-12-07T06:55:04+00:00) Using camera Virtual0 as cam0 0: 1920x1080-NV12 * Pixelformat: NV12 (1280x720)-(1920x1080)/(+1,+1) - 1280x720 - 1280x800 - 1360x768 - 1366x768 - 1440x900 - 1280x1024 - 1536x864 - 1280x1080 - 1600x900 - 1400x1050 - 1680x1050 - 1920x1080 """ Signed-off-by: Harvey Yang --- src/libcamera/pipeline/virtual/virtual.cpp | 141 +++++++++++++++++++-- 1 file changed, 133 insertions(+), 8 deletions(-) diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp index 1d66a60e..b0e6de20 100644 --- a/src/libcamera/pipeline/virtual/virtual.cpp +++ b/src/libcamera/pipeline/virtual/virtual.cpp @@ -8,6 +8,7 @@ #include #include +#include #include "libcamera/internal/camera.h" #include "libcamera/internal/pipeline_handler.h" @@ -19,6 +20,11 @@ LOG_DEFINE_CATEGORY(VIRTUAL) class VirtualCameraData : public Camera::Private { public: + struct Resolution { + Size size; + std::vector frame_rates; + std::vector formats; + }; VirtualCameraData(PipelineHandler *pipe) : Camera::Private(pipe) { @@ -26,15 +32,22 @@ public: ~VirtualCameraData() = default; + std::vector supportedResolutions_; + Stream stream_; }; class VirtualCameraConfiguration : public CameraConfiguration { public: - VirtualCameraConfiguration(); + static constexpr unsigned int kBufferCount = 4; // 4~6 + + VirtualCameraConfiguration(VirtualCameraData *data); Status validate() override; + +private: + const VirtualCameraData *data_; }; class PipelineHandlerVirtual : public PipelineHandler @@ -55,16 +68,56 @@ public: int queueRequestDevice(Camera *camera, Request *request) override; bool match(DeviceEnumerator *enumerator) override; + +private: + VirtualCameraData *cameraData(Camera *camera) + { + return static_cast(camera->_d()); + } }; -VirtualCameraConfiguration::VirtualCameraConfiguration() - : CameraConfiguration() +VirtualCameraConfiguration::VirtualCameraConfiguration(VirtualCameraData *data) + : CameraConfiguration(), data_(data) { } CameraConfiguration::Status VirtualCameraConfiguration::validate() { - return Invalid; + Status status = Valid; + + if (config_.empty()) { + LOG(VIRTUAL, Error) << "Empty config"; + return Invalid; + } + + // TODO: check if we should limit |config_.size()| + + Size maxSize; + for (const auto &resolution : data_->supportedResolutions_) + maxSize = std::max(maxSize, resolution.size); + + for (StreamConfiguration &cfg : config_) { + // TODO: check |cfg.pixelFormat|. + + bool found = false; + for (const auto &resolution : data_->supportedResolutions_) { + if (resolution.size.width >= cfg.size.width && resolution.size.height >= cfg.size.height) { + found = true; + break; + } + } + + if (!found) { + cfg.size = maxSize; + status = Adjusted; + } + + cfg.setStream(const_cast(&data_->stream_)); + + cfg.bufferCount = VirtualCameraConfiguration::kBufferCount; + } + + return status; } PipelineHandlerVirtual::PipelineHandlerVirtual(CameraManager *manager) @@ -75,16 +128,81 @@ PipelineHandlerVirtual::PipelineHandlerVirtual(CameraManager *manager) std::unique_ptr PipelineHandlerVirtual::generateConfiguration(Camera *camera, const StreamRoles &roles) { - (void)camera; - (void)roles; - return std::unique_ptr(nullptr); + VirtualCameraData *data = cameraData(camera); + auto config = + std::make_unique(data); + + if (roles.empty()) + return config; + + Size minSize, sensorResolution; + for (const auto &resolution : data->supportedResolutions_) { + if (minSize.isNull() || minSize > resolution.size) + minSize = resolution.size; + + sensorResolution = std::max(sensorResolution, resolution.size); + } + + for (const StreamRole role : roles) { + std::map> streamFormats; + unsigned int bufferCount; + PixelFormat pixelFormat; + + switch (role) { + case StreamRole::StillCapture: + pixelFormat = formats::NV12; + bufferCount = VirtualCameraConfiguration::kBufferCount; + streamFormats[pixelFormat] = { { minSize, sensorResolution } }; + + break; + + case StreamRole::Raw: { + // TODO: check + pixelFormat = formats::SBGGR10; + bufferCount = VirtualCameraConfiguration::kBufferCount; + streamFormats[pixelFormat] = { { minSize, sensorResolution } }; + + break; + } + + case StreamRole::Viewfinder: + case StreamRole::VideoRecording: { + pixelFormat = formats::NV12; + bufferCount = VirtualCameraConfiguration::kBufferCount; + streamFormats[pixelFormat] = { { minSize, sensorResolution } }; + + break; + } + + default: + LOG(VIRTUAL, Error) + << "Requested stream role not supported: " << role; + config.reset(); + return config; + } + + StreamFormats formats(streamFormats); + StreamConfiguration cfg(formats); + cfg.size = sensorResolution; + cfg.pixelFormat = pixelFormat; + cfg.bufferCount = bufferCount; + config->addConfiguration(cfg); + } + + if (config->validate() == CameraConfiguration::Invalid) { + config.reset(); + return config; + } + + return config; } int PipelineHandlerVirtual::configure(Camera *camera, CameraConfiguration *config) { (void)camera; (void)config; - return -1; + // Nothing to be done. + return 0; } int PipelineHandlerVirtual::exportFrameBuffers(Camera *camera, Stream *stream, @@ -119,7 +237,14 @@ bool PipelineHandlerVirtual::match(DeviceEnumerator *enumerator) { (void)enumerator; + // TODO: Add virtual cameras according to a config file. + std::unique_ptr data = std::make_unique(this); + + data->supportedResolutions_.resize(2); + data->supportedResolutions_[0] = { .size = Size(1920, 1080), .frame_rates = { 30 }, .formats = { "YCbCr_420_888" } }; + data->supportedResolutions_[1] = { .size = Size(1280, 720), .frame_rates = { 30, 60 }, .formats = { "YCbCr_420_888" } }; + /* Create and register the camera. */ std::set streams{ &data->stream_ }; const std::string id = "Virtual0"; From patchwork Wed Mar 15 10:22:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 18407 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 5A50FC329E for ; Wed, 15 Mar 2023 10:23:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C6BF762720; Wed, 15 Mar 2023 11:23:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678875797; bh=ppahLEFxghQOZXjso3nMbvU03EQJIwl/rSdRn2e8Btw=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=SNoWQ7Og0OXApHl1YatLhgRgDnCn22NruOZIqvZRbfn+PKL2rSB8fvkS8Zn8fOdJJ +SD91ZBYAPyiwuUHffu180YLqH68xxtnDFUHFbCTPaBV1dLVDrZgAuvVRxJj9JPNfB VQpJ7IGgCyUwo84+X6pCs1B0+p6/QqZH/W6HcLHrGjkRA7jJ9brZ6l2m2ZsgroMM5M IKKiLHYl5e64f1+/nxEROOfl1KBQ6ATTK2jdgq8kq9itJrw4XIm4YKY7KjNZTDGzQY 5t6u74yhiVDZT8/iv9uRWhvPK3uARxTUZ0E5P/nMy7zbWJP4TYQMumTV4iw3ehVEAK 8RtL3G5km9Caw== Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A7F8E62715 for ; Wed, 15 Mar 2023 11:23:13 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="QGRalPTk"; dkim-atps=neutral Received: by mail-pj1-x102a.google.com with SMTP id 6-20020a17090a190600b00237c5b6ecd7so1310483pjg.4 for ; Wed, 15 Mar 2023 03:23:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1678875792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T6nNXjaAf2/txHwK1qVPMwGGVG0jr+2dbEowFjzsCkA=; b=QGRalPTkRdaWfgtra+D6xRe/7eL4boQBDI/Qf9idpZZdcjb8jzphUr0C3cSJkPO/RK uuOa8Y8JKmGnN5+eoAUhTBM3qVCE9CtwW0rlXCdFtPB+P3bJcNzKR4m53f3Xo43clxQc +NFjYlpNuCBYS8kaZtlnPYiUPRhlMoXKFcjVg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678875792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T6nNXjaAf2/txHwK1qVPMwGGVG0jr+2dbEowFjzsCkA=; b=0eUWp4nniwS4Bo4vtQW87oo6kmfhWJ1jNshPfJ1KHs8ogsUwIJKlx9hwIapTdR0dZh EWdIJ5oLR71m1v5Q43ugiV+G7Z4MSUtiVEmBiO2oLEpop515vipJDqsnsEPJbjtQSPC/ utHfxqEKkNM+pZaqm2s0jKU90BSrByEYEvRK4JM7imIMRezS2PofFbFO1OX5X52qQFNj 94doqSjAbgZxkyECGr/4+SvbddntYIdlnJtAmZ77qebec1OZapj5D2ChkNDHNWC2FE0X WqUfuNLXbrClZgF2M4yTT8r1NzjJ7xm03mNbJRYgPvvgNKxRO+qvGVo/+xm3M5IWGJhd HS3Q== X-Gm-Message-State: AO0yUKXun1B3XFazfR/+nqC+ogNkyKCEUKPLVzpHGkDXVKLBmqd69cxT H8Sdvv702PHM6OFPsyCNuLe2zLKk+Q9xGi5eHm8= X-Google-Smtp-Source: AK7set8d+8zMtqqBstcaMF9K4tW144Fxc5GkQ1th2QO1LBCA1f7vH0nwecNRke7l1l/JwPiCa41Dng== X-Received: by 2002:a17:90b:3ce:b0:23b:2f4f:1a9b with SMTP id go14-20020a17090b03ce00b0023b2f4f1a9bmr14867155pjb.37.1678875792010; Wed, 15 Mar 2023 03:23:12 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (112.157.221.35.bc.googleusercontent.com. [35.221.157.112]) by smtp.gmail.com with ESMTPSA id f11-20020a17090274cb00b001a0450da45csm3262786plt.185.2023.03.15.03.23.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 03:23:11 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Mar 2023 10:22:59 +0000 Message-Id: <20230315102300.2265491-6-chenghaoyang@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230315102300.2265491-1-chenghaoyang@google.com> References: <20230315102300.2265491-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 5/6] libcamera: pipeline: virtual: Queue requests 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-Patchwork-Original-From: Harvey Yang via libcamera-devel From: Harvey Yang Reply-To: Harvey Yang Cc: Harvey Yang , Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" [todo Read frames from the virtual video if any] Currently we only use external buffers and complete them immediately with green frames. Signed-off-by: Harvey Yang --- src/libcamera/pipeline/virtual/virtual.cpp | 39 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp index b0e6de20..b91e7000 100644 --- a/src/libcamera/pipeline/virtual/virtual.cpp +++ b/src/libcamera/pipeline/virtual/virtual.cpp @@ -8,7 +8,10 @@ #include #include +#include +#include #include +#include #include "libcamera/internal/camera.h" #include "libcamera/internal/pipeline_handler.h" @@ -17,6 +20,17 @@ namespace libcamera { LOG_DEFINE_CATEGORY(VIRTUAL) +uint64_t CurrentTimestamp() +{ + struct timespec ts; + if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) { + LOG(VIRTUAL, Error) << "Get clock time fails"; + return 0; + } + + return ts.tv_sec * 1'000'000'000LL + ts.tv_nsec; +} + class VirtualCameraData : public Camera::Private { public: @@ -74,6 +88,8 @@ private: { return static_cast(camera->_d()); } + + HeapAllocator heapAllocator_; }; VirtualCameraConfiguration::VirtualCameraConfiguration(VirtualCameraData *data) @@ -208,29 +224,38 @@ int PipelineHandlerVirtual::configure(Camera *camera, CameraConfiguration *confi int PipelineHandlerVirtual::exportFrameBuffers(Camera *camera, Stream *stream, std::vector> *buffers) { - (void)camera; - (void)stream; - (void)buffers; - return -1; + if (!heapAllocator_.isValid()) + return -ENOBUFS; + + return heapAllocator_.exportFrameBuffers(camera, stream, buffers); } int PipelineHandlerVirtual::start(Camera *camera, const ControlList *controls) { (void)camera; (void)controls; - return -1; + // TODO: Start reading the virtual video if any. + return 0; } void PipelineHandlerVirtual::stopDevice(Camera *camera) { (void)camera; + // TODO: Reset the virtual video if any. } int PipelineHandlerVirtual::queueRequestDevice(Camera *camera, Request *request) { (void)camera; - (void)request; - return -1; + + // TODO: Read from the virtual video if any. + for (auto it : request->buffers()) + completeBuffer(request, it.second); + + request->metadata().set(controls::SensorTimestamp, CurrentTimestamp()); + completeRequest(request); + + return 0; } bool PipelineHandlerVirtual::match(DeviceEnumerator *enumerator) From patchwork Wed Mar 15 10:23:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 18408 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 D295AC329F for ; Wed, 15 Mar 2023 10:23:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5D1F861ED2; Wed, 15 Mar 2023 11:23:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678875798; bh=JEB6AEVbGLqmtfC7pHhxD1DmxhBO5vycHkx8UtpTrBI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=UbCtjJujLx2xY0RdZTY1S5Gssji3CrAES+WWaRxQt6DvCDuUdHVgTvdyoKJkaqTSE CPItN60qzPLh896Tr0+7kVP5S4DSDR0pHff6Qj+STnAF6kog5X0k53wQqwAJ/csjQ3 jev2oM/E9PcEIVqYsR6Zwbs6gGkxfuj1s5qrp+k/sC1sLl6ZFVAZwQhyHzhS7Rpfiv wPZifx6xSiqeISpgfyAWz7kFXtQAZSt+wgHKlcRqlYmbYZAWjoGLIvHTmiwpjHwmMJ gIGOPypKGsQzcvwLCo6EW0kH1UsEVTHHoEuH7M51SiWcYdI3L/tM5wmCm/AMM40MhS MysmhCNN24wlA== Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E6F4D62709 for ; Wed, 15 Mar 2023 11:23:14 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="YIm0P+im"; dkim-atps=neutral Received: by mail-pl1-x631.google.com with SMTP id iw3so2655177plb.6 for ; Wed, 15 Mar 2023 03:23:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1678875793; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=F4wCzmkWS8rqH2a3GVhAhLoS0CEQmFOtFrF1j9+6M9I=; b=YIm0P+imiQvHQ4hDZcXfgt8SwlzBUp7X9aEFNpnogxVss9nPmBUPmjypOLjFzgCQP6 P9IatL7aPFqBO6UtqVEtInLuC2OmkgKSYeLhX8FhfA/xku6NgYuxfOCOrMrRTqoGu5JK a1UYvAUs5DNjoACKrBMJt0DG8oY1QXpwpSnhA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678875793; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F4wCzmkWS8rqH2a3GVhAhLoS0CEQmFOtFrF1j9+6M9I=; b=GNAefjdEiE1GTlqhxHbBBRW3WyaUITVvA4IhPq/0uE8tHbcQwPUuWtHJSquuMjUVW/ VaSsTsIUEwZN5Myx3Wb6xOWYwrsEKdiRlDXIZq/M3ZxcsWs+xKjLQjFecj0sbe3/807p BhpxZY1hmQv0dcv/VzTCtnl/1XPcN1u33F8GKiQKqp7C2sKaMojj2RqVyk7MH7rrmJLK 64+1k3sjnuMQUomDdlbjadCy5IjbKwW9wMxSxLzoW7Yho4PJWLFr/gAkz5VQMO8lINAQ ncyJ+8yMKgm4+xHoQc/UgSK4n+uKwsxbtgi0yfI2sOzogLILakMkC84BtSKF7etKbYcC m9bQ== X-Gm-Message-State: AO0yUKURRVZfxi2qUAZGy/pn+GWiWDCJJayZIgn4EoC2aXfTBoB9fq15 xfWkE9Ts10cSXr9bjqmTwPHjYFKUSLodiBaGGN4= X-Google-Smtp-Source: AK7set9qWcrgogAUOzbaZwf6FG4x0tOeBOyEsM7Gp8O2VRD8/rexPkQadxIrR1to45Xjy+G5PJ/vrw== X-Received: by 2002:a17:902:fa87:b0:19e:2eb5:712d with SMTP id lc7-20020a170902fa8700b0019e2eb5712dmr1683070plb.25.1678875793217; Wed, 15 Mar 2023 03:23:13 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (112.157.221.35.bc.googleusercontent.com. [35.221.157.112]) by smtp.gmail.com with ESMTPSA id f11-20020a17090274cb00b001a0450da45csm3262786plt.185.2023.03.15.03.23.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 03:23:13 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Mar 2023 10:23:00 +0000 Message-Id: <20230315102300.2265491-7-chenghaoyang@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230315102300.2265491-1-chenghaoyang@google.com> References: <20230315102300.2265491-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 6/6] libcamera: pipeline: virtual: Set camera properties & controls 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-Patchwork-Original-From: Harvey Yang via libcamera-devel From: Harvey Yang Reply-To: Harvey Yang Cc: Harvey Yang , Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Initialize the CameraData properties with Location, Model, and PixelArrayActiveAreas, and the control attribute: FrameDurationLimits. Updating `/etc/camera/libcamera/camera_hal.yaml` on a chromebook DUT is required to find the virtual camera with id `Virtual0`. Signed-off-by: Harvey Yang --- src/libcamera/pipeline/virtual/virtual.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp index b91e7000..f858ed1e 100644 --- a/src/libcamera/pipeline/virtual/virtual.cpp +++ b/src/libcamera/pipeline/virtual/virtual.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "libcamera/internal/camera.h" #include "libcamera/internal/pipeline_handler.h" @@ -20,6 +21,10 @@ namespace libcamera { LOG_DEFINE_CATEGORY(VIRTUAL) +static const ControlInfoMap::Map VirtualControls = { + { &controls::draft::PipelineDepth, ControlInfo(2, 3) }, +}; + uint64_t CurrentTimestamp() { struct timespec ts; @@ -270,6 +275,16 @@ bool PipelineHandlerVirtual::match(DeviceEnumerator *enumerator) data->supportedResolutions_[0] = { .size = Size(1920, 1080), .frame_rates = { 30 }, .formats = { "YCbCr_420_888" } }; data->supportedResolutions_[1] = { .size = Size(1280, 720), .frame_rates = { 30, 60 }, .formats = { "YCbCr_420_888" } }; + data->properties_.set(properties::Location, properties::CameraLocationFront); + data->properties_.set(properties::Model, "Virtual Video Device"); + data->properties_.set(properties::PixelArrayActiveAreas, { Rectangle(Size(1920, 1080)) }); + + // TODO: Set FrameDurationLimits based on config. + ControlInfoMap::Map controls = VirtualControls; + int64_t min_frame_duration = 30, max_frame_duration = 60; + controls[&controls::FrameDurationLimits] = ControlInfo(min_frame_duration, max_frame_duration); + data->controlInfo_ = ControlInfoMap(std::move(controls), controls::controls); + /* Create and register the camera. */ std::set streams{ &data->stream_ }; const std::string id = "Virtual0";