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)