From patchwork Mon Jun 13 06:03:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 16205 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 C6854C3273 for ; Mon, 13 Jun 2022 06:04:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1B91365638; Mon, 13 Jun 2022 08:04:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655100246; bh=S272PG9khK2UdLsS/+qtNUrA8EW2d0ahIV16iv7o/oA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Aasko7P4FavVZSkZb81+wLfuDCu9id6OVlegHIhugXk8W9AhM+wqaEb+32W7xJOGe q/F7MHxGAkFv5k8mXMpqQ2b2QHMG8id0DzwHH/2KHqmzH97H2yfoAo/UhkkJAHl1dh czlFHk44NvoZvgmfBEruza75XeuIte1WTYvyyaB2mVr3kg42BpHps9e2WfFpsC3QI1 +Z8qobVNXf5B732/kD6EAZgfHavmsSh6Z6bhE4n0KYgrjtTvSSPOTuhvMjCAFSgZtY ItN3DkW5SARvaF29dUYl+Jasc5EJJ5fNaUtC66zZpKOtPPpXu+fwdY4X/oEjnPKAAL RX4lI/aq1sOpg== Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0CAE865631 for ; Mon, 13 Jun 2022 08:04:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gDVgpKVi"; dkim-atps=neutral Received: by mail-pf1-x42a.google.com with SMTP id e11so4871005pfj.5 for ; Sun, 12 Jun 2022 23:04:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wWnX22DgtmEKWHKuXNpIM1KRw7Bkk844LDOVXAf7urQ=; b=gDVgpKVi01ZOggbwltQ1JoJVNGKDqfz1r5moVG+wEq0rQ4jpbGvu8oPwIlMs9K9Wt/ iiQbdhHv4O6VXy4W1iz7OIRGn2DFlnsi2IEd+nmB2Lly0R8oIU7AjR24XgLJ4UJ5ZbRK 9bj42cEWZLnMFtOuFQ4Z9ZU0RPEr5IzKxt225yY/B3f+i+P6fvwLXpRJFUthhgG70iyW ubSt0TI1TnyXb3QYN4kyKoSd2MUryjgvxOPcnyj1w2Z7JJsUx3dSLyByFk00QkZbWqJo taHDZkRRwo4EqUZk0iXZaNtdD2VXCNrYK+zLIzEx6TjhJg2lOWgZmSG0e9yC81MNnB87 E4Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wWnX22DgtmEKWHKuXNpIM1KRw7Bkk844LDOVXAf7urQ=; b=kTGqgGiEG9smhfOnkb/7xEpl9QAaF01xF5xLo09qZD0xTHm0qSGy6X6WOW7osHVOLP 9w06TfSpq5HYkxfibEAgHoIey7WSykh8cYDEzf5LNOylNNuukxBAURvhlMD0lxxKNSdN iCNuAAOZKfpfNrNbsAM8Dw6AFU27j1qRvEK+kDoyt0GWRXlHmU4giAjN6NxNuE7i7LB7 x/ElUMdyWIzmEK3b9vLaerSApD3yRCb4GfvvaMRXBd31j3EHNoP7mTP41ygJmqbKVgSb qU87sMRnIdCPAgEJUfPV5cRWzVyZeT4ShyfIqvrU6EeH+IBAYEGzR0G4dV46ngEmyoao 0O9w== X-Gm-Message-State: AOAM530Fo+an7l9KAWUVJve22AdIk3UMR/27l+FHhIrUrwHxq6fvYez6 mnndupOvoQQBjDCJZjFwYItCTYkxExM= X-Google-Smtp-Source: ABdhPJz2klRjpGNY6wNHUQIDZyAGjEtC02p4eZ9fQ4V6VK+Hk4e1JAie6FtQeSTRqrW1L5B+SqmVUg== X-Received: by 2002:a05:6a00:1307:b0:50d:b02e:11df with SMTP id j7-20020a056a00130700b0050db02e11dfmr59124477pfu.4.1655100242337; Sun, 12 Jun 2022 23:04:02 -0700 (PDT) Received: from localhost.localdomain ([2404:bd00:3:d6be:8959:67fc:32d7:74a0]) by smtp.gmail.com with ESMTPSA id x14-20020a170902a38e00b00161478027f5sm4087908pla.150.2022.06.12.23.04.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 23:04:02 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 13 Jun 2022 11:33:44 +0530 Message-Id: <20220613060345.229191-3-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220613060345.229191-1-utkarsh02t@gmail.com> References: <20220613060345.229191-1-utkarsh02t@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] qcam: Add a GUI way to use capture script 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: Utkarsh Tiwari via libcamera-devel From: Utkarsh Tiwari Reply-To: Utkarsh Tiwari Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Implement an Open Capture Script button which would allow the user to open a Capture Script (*.yaml). When clicked present them with a QFileDialog to allow them to select a single file. Introduce a queueCount_ to keep track of the requests queued. Initialize a Script Parser instance when the user selects a valid capture script. At queueRequest() time if script parser has been initialized, then populate the Request::controls() with it at queueRequest time providing the queueCount_. The queueCount_ is incremented after the getting controls from the parser, so the first request is for frame 0. Signed-off-by: Utkarsh Tiwari --- src/qcam/assets/feathericons/feathericons.qrc | 1 + src/qcam/main_window.cpp | 38 +++++++++++++++++++ src/qcam/main_window.h | 5 +++ src/qcam/meson.build | 2 + 4 files changed, 46 insertions(+) diff --git a/src/qcam/assets/feathericons/feathericons.qrc b/src/qcam/assets/feathericons/feathericons.qrc index c5302040..f0d1e3d0 100644 --- a/src/qcam/assets/feathericons/feathericons.qrc +++ b/src/qcam/assets/feathericons/feathericons.qrc @@ -3,6 +3,7 @@ aperture.svg camera-off.svg + file.svg play-circle.svg save.svg stop-circle.svg diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 5ac31d9a..7cdb1238 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -232,6 +233,12 @@ int MainWindow::createToolbars() saveRaw_ = action; #endif + /* Open Script... action. */ + action = toolbar_->addAction(QIcon::fromTheme("document-open", + QIcon(":file.svg")), + "Open Capture Script"); + connect(action, &QAction::triggered, this, &MainWindow::chooseScript); + return 0; } @@ -255,6 +262,31 @@ void MainWindow::updateTitle() setWindowTitle(title_ + " : " + QString::number(fps, 'f', 2) + " fps"); } +/** + * \brief Load a capture script for handling the capture session. + * + * If already capturing, it would restart the capture. + */ +void MainWindow::chooseScript() +{ + QString scriptFile = QFileDialog::getOpenFileName(this, tr("Open Capture Script"), QDir::currentPath(), + tr("Capture Script (*.yaml)")); + if (scriptFile.isEmpty()) + return; + script_ = std::make_unique(camera_, scriptFile.toStdString()); + if (!script_->valid()) { + script_.reset(); + QMessageBox::critical(this, tr("Invalid Script"), tr("Couldn't execute the capture script")); + return; + } + + //Restart the capture so we can reset every counter + if (isCapturing_) { + toggleCapture(false); + toggleCapture(true); + } +} + /* ----------------------------------------------------------------------------- * Camera Selection */ @@ -510,6 +542,7 @@ int MainWindow::startCapture() previousFrames_ = 0; framesCaptured_ = 0; lastBufferTime_ = 0; + queueCount_ = 0; ret = camera_->start(); if (ret) { @@ -789,5 +822,10 @@ void MainWindow::refillRequest(FrameBuffer *buffer) int MainWindow::queueRequest(Request *request) { + if (script_) + request->controls() = script_->frameControls(queueCount_); + + queueCount_++; + return camera_->queueRequest(request); } diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 251b8335..cde5842f 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -26,6 +26,7 @@ #include #include +#include "../cam/capture_script.h" #include "../cam/stream_options.h" #include "viewfinder.h" @@ -86,6 +87,8 @@ private: void processHotplug(HotplugEvent *e); void processViewfinder(libcamera::FrameBuffer *buffer); + void chooseScript(); + /* UI elements */ QToolBar *toolbar_; QAction *startStopAction_; @@ -124,6 +127,8 @@ private: QElapsedTimer frameRateInterval_; uint32_t previousFrames_; uint32_t framesCaptured_; + uint32_t queueCount_; std::vector> requests_; + std::unique_ptr script_; }; diff --git a/src/qcam/meson.build b/src/qcam/meson.build index c46f4631..67074252 100644 --- a/src/qcam/meson.build +++ b/src/qcam/meson.build @@ -15,6 +15,7 @@ endif qcam_enabled = true qcam_sources = files([ + '../cam/capture_script.cpp', '../cam/image.cpp', '../cam/options.cpp', '../cam/stream_options.cpp', @@ -37,6 +38,7 @@ qcam_resources = files([ qcam_deps = [ libatomic, libcamera_public, + libyaml, qt5_dep, ]