From patchwork Fri Jun 24 13:05:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16368 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 694A9BE173 for ; Fri, 24 Jun 2022 13:05:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1226A65638; Fri, 24 Jun 2022 15:05:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656075934; bh=mL2GIIl2nI+t0hBRePdSEvhCg7DsQ3bc8M4AvUQ1Csc=; 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=eatp6eXtjwuYxApJZkvbjV6PbfJq0eV89BdPlow4pJCjL4nK9IkSxGOWl1gnWLrZG wXkq9qGV3wIswWgdZr1LsJiz1D6//mR9WoqB1rBVB6MNhMML/E5bQ9USz2d83rFA7B DC+Gjh8I15HsJ29qVfwsOkHBCqJ+KvdN3C2UaTLOwv6iY8FLK7Fi45hB2r5gn8EB1I YoNUI2jTA/iNGZu0bN3uNnarTkIzLh9Ki9+UWvdyTLoxI8XU60YNtpvtGFWNa+WdT9 2tLwVNCsyqiYv4pd83x+UGwrhNjMtoxudP+kDuI0EhVdPwSxSOSojujJkyTVZ/4qgX HWHnz0uqPnegw== Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B1C47600EC for ; Fri, 24 Jun 2022 15:05:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=thaumatec-com.20210112.gappssmtp.com header.i=@thaumatec-com.20210112.gappssmtp.com header.b="BPPoOkFy"; dkim-atps=neutral Received: by mail-wr1-x42b.google.com with SMTP id o16so3076725wra.4 for ; Fri, 24 Jun 2022 06:05:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LBLYdcs1v00veNkngHKefOHuUxWmmPL1iLmxWUnpo7c=; b=BPPoOkFyEMEOk2pQZHw85/XXNJNLwyZnnqFiuraQEKfE4uH9aa8twgXQJm+XDTMtEO pqZ17yBho05lCvZIT/t5MtwkkaTskrywYuNRoPHyZsV2bV06tMs7d6+YBXlDzRcKDKkT /f7yoMqCFi0OILkRtmfsWVQlDx+7q8Df1kc+MGBk71XaKWu7WKesaHb/6D1sj3fg3tMj ezzwcfLVpHEGKw2xXOsM5y2vl4VMHdeSqMqj7GrVkgRDxuYbehJ0tuAe0fftFk90Fh8c 6CLWekvYuwjdFoqjNSPikj+Je8rrF3DwDJiFSeQH7e5YGktRCY5Gqd/Uwq+tVvdLQIjD wN+Q== 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=LBLYdcs1v00veNkngHKefOHuUxWmmPL1iLmxWUnpo7c=; b=zqYzpIKxl/LJ9wxu8SL1xYrOpfzYqHjEuRS2yq/RVt4qSH1RrRgvfS4MV8ZcVfeXyr ThBLcRWEAoJLPOCbMFFQ0M7RrGuookylTnt+/y1UGcPOlX16nL/JMMLFdYxKw6BiERW2 0qUEU74R//VZ+WdvZ99iPreLi9GclnsYfCNDw7m4wDFhrFfzBTN1P6orG/Ho/lC5vUtb NDDW7XctSB63gOQjxuX7s/2FzYy45GQy9jzQYvtc1rhmDi5MZi1B1swZ7o7ZDXqw36iL oA1q9Ygqbwicy5GdQPfqvBArFvrxnrdm2c9vxpOBfXhvWgOOF4ZCu9e03/TxzhBwBuon sx9A== X-Gm-Message-State: AJIora81UoIOluUyA40Y+ZMfc7khG3X8hB1keYrBmZnbYA5q44sH2dNH No7SW2yftakhL/IgX8r9UuuijRyLvoSsxacV X-Google-Smtp-Source: AGRyM1tFVcn4Td73z2s0MuzT+wzkKDhXhyrvfnNfnbirJQhsqCNrZ65rkE7Iqc+1au10y14glPXKjw== X-Received: by 2002:a05:6000:10c5:b0:21b:9aed:47e3 with SMTP id b5-20020a05600010c500b0021b9aed47e3mr13496370wrx.570.1656075931289; Fri, 24 Jun 2022 06:05:31 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id m20-20020a05600c4f5400b0039747cf8354sm2889703wmq.39.2022.06.24.06.05.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jun 2022 06:05:30 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Jun 2022 15:05:22 +0200 Message-Id: <20220624130523.41535-2-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220624130523.41535-1-dse@thaumatec.com> References: <20220624130523.41535-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/2] cam: Add Rectangle type parsing in 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: Daniel Semkowicz via libcamera-devel From: Daniel Semkowicz Reply-To: Daniel Semkowicz Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This change is required for AfWindows control from capture script. Parser expects array of arrays of parameters, so it is possible to specify multiple rectangles. Signed-off-by: Daniel Semkowicz --- src/cam/capture_script.cpp | 109 +++++++++++++++++++++++++++++++++---- src/cam/capture_script.h | 6 +- 2 files changed, 102 insertions(+), 13 deletions(-) diff --git a/src/cam/capture_script.cpp b/src/cam/capture_script.cpp index 9f22d5f7..5812b122 100644 --- a/src/cam/capture_script.cpp +++ b/src/cam/capture_script.cpp @@ -232,12 +232,15 @@ int CaptureScript::parseControl(EventPtr event, ControlList &controls) return -EINVAL; } - std::string value = parseScalar(); - if (value.empty()) + const ControlId *controlId = it->second; + + ControlValue val = unpackControl(controlId); + if (val.isNone()) { + std::cerr << "Error unpacking control '" << name << "'" + << std::endl; return -EINVAL; + } - const ControlId *controlId = it->second; - ControlValue val = unpackControl(controlId, value); controls.set(controlId->id(), val); return 0; @@ -252,6 +255,68 @@ std::string CaptureScript::parseScalar() return eventScalarValue(event); } +ControlValue CaptureScript::parseRectangles() +{ + EventPtr event = nextEvent(YAML_SEQUENCE_START_EVENT); + if (!event) + return {}; + + std::vector rectangles; + + while (1) { + event = nextEvent(); + if (!event) + return {}; + + switch (event->type) { + case YAML_SEQUENCE_START_EVENT: { + std::vector values = parseArray(); + if (values.size() != 4) { + std::cerr << "Error parsing Rectangle: expected " + "array with 4 parameters" << std::endl; + return {}; + } + + Rectangle rect = unpackRectangle(values); + rectangles.push_back(rect); + break; + } + case YAML_SEQUENCE_END_EVENT: { + ControlValue controlValue; + controlValue.set(Span(rectangles)); + return controlValue; + } + default: + return {}; + } + } +} + +std::vector CaptureScript::parseArray() +{ + std::vector values; + + while (1) { + EventPtr event = nextEvent(); + if (!event) + return {}; + + switch (event->type) { + case YAML_SCALAR_EVENT: { + std::string value = eventScalarValue(event); + if (value.empty()) + return {}; + values.push_back(value); + break; + } + case YAML_SEQUENCE_END_EVENT: + return values; + default: + return {}; + } + } +} + void CaptureScript::unpackFailure(const ControlId *id, const std::string &repr) { static const std::map typeNames = { @@ -277,9 +342,24 @@ void CaptureScript::unpackFailure(const ControlId *id, const std::string &repr) << typeName << " control " << id->name() << std::endl; } -ControlValue CaptureScript::unpackControl(const ControlId *id, - const std::string &repr) +ControlValue CaptureScript::unpackControl(const ControlId *id) { + /* Parse complex types */ + switch (id->type()) { + case ControlTypeRectangle: + return parseRectangles(); + case ControlTypeSize: + /* \todo Parse Sizes. */ + return {}; + default: + break; + } + + /* Parse basic types represented by a single scalar */ + const std::string repr = parseScalar(); + if (repr.empty()) + return {}; + ControlValue value{}; switch (id->type()) { @@ -324,13 +404,20 @@ ControlValue CaptureScript::unpackControl(const ControlId *id, value.set(repr); break; } - case ControlTypeRectangle: - /* \todo Parse rectangles. */ - break; - case ControlTypeSize: - /* \todo Parse Sizes. */ + default: + std::cerr << "Unsupported control type" << std::endl; break; } return value; } + +libcamera::Rectangle CaptureScript::unpackRectangle(const std::vector &strVec) +{ + int x = strtol(strVec[0].c_str(), NULL, 10); + int y = strtol(strVec[1].c_str(), NULL, 10); + unsigned int width = strtoul(strVec[2].c_str(), NULL, 10); + unsigned int height = strtoul(strVec[3].c_str(), NULL, 10); + + return Rectangle(x, y, width, height); +} diff --git a/src/cam/capture_script.h b/src/cam/capture_script.h index 8b4f8f62..130872b4 100644 --- a/src/cam/capture_script.h +++ b/src/cam/capture_script.h @@ -54,9 +54,11 @@ private: int parseControl(EventPtr event, libcamera::ControlList &controls); std::string parseScalar(); + libcamera::ControlValue parseRectangles(); + std::vector parseArray(); void unpackFailure(const libcamera::ControlId *id, const std::string &repr); - libcamera::ControlValue unpackControl(const libcamera::ControlId *id, - const std::string &repr); + libcamera::ControlValue unpackControl(const libcamera::ControlId *id); + libcamera::Rectangle unpackRectangle(const std::vector &strVec); }; From patchwork Fri Jun 24 13:05:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16369 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 23CD3BE173 for ; Fri, 24 Jun 2022 13:05:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B88C86563B; Fri, 24 Jun 2022 15:05:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656075935; bh=d95mMs6hm6GgG5cjWABdkLrLZGey2LNeU7PLMnvySqA=; 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=GetJ0fiPNwSndayOPp0Fbu0Rk1KkrWMKv+dkJMY5KqoBZ9GPxlXJwsIjsTvXio3Ok u4MQhmR/ScXSyJ6BOV/g8ELAWkRLfimHLPQ1YYgXJv+tFPEBcMqMH+6XRhgIHQDevy adsDO0AO2QkvlRw84kRgBNZONBEpRxia22QPdEp9z30N2BLYd3c1TZE5lC7j/eaMjd 18dOfgRVf2dKyRB5QsLWdg2fG8oH/SDvCPkX6VwLWNXtBkkFyBSYbV04maUYTsoPAV IPT87DXD8mF+hAR6XE3snwj5iHtqVJYfSf4ByRj25SDUw2/+b2j9pvR84L++lb1bys RZQ1j+jI4vcDA== Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 30FA365639 for ; Fri, 24 Jun 2022 15:05:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=thaumatec-com.20210112.gappssmtp.com header.i=@thaumatec-com.20210112.gappssmtp.com header.b="akLZDA74"; dkim-atps=neutral Received: by mail-wr1-x433.google.com with SMTP id e10so3027282wra.11 for ; Fri, 24 Jun 2022 06:05:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thaumatec-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jRQokZ1ijv8UYkszDObakGRM38Bj5VK5Dq47DLgN7Yc=; b=akLZDA74aoBdnjXvlx5DyLVBO3iVZKjEJCOSsNmQx9wldV/XiPNbPfA8PBlQVc2XKL QNkFASTUCQ3DTlDmSjFy9nUKyIIX5pVltOrmwDjkSVs+cwQtXuH3gPCZ/sI6Jf0TOmEZ ur0915cUxIw9poujeg+y9MPglF0N46Yfux43gNj2OJQ/j0fKPf4qgOMTUG0SWI8RWV8k 71KpA0tXyQx/rEXua8dD9Kr1B24+Df7dERghjmPP1JFVqdLdNCiinj3hUZXlylFf0s99 nfFgC8UQDA5PXbd70EO7H0Z69bKvUrK65mOoBkIORqRLKL3YHiJCH666L7H9mTProeGK MuoQ== 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=jRQokZ1ijv8UYkszDObakGRM38Bj5VK5Dq47DLgN7Yc=; b=jjkZ2H1l64pImT2YD6WN0IlG79TI7RyHrk5vlm/7wY7F3i7UYBeeqcLhsQcC+jtFSN CBdjwVCqIczLY8u3e8lFy3SHGZxJBzah7aKmGFbGrCy0sYajyXu7YUO+hhhzmkyBlmIP uMK8IRxqIYiQTJjAgfY8Ic/BzWDbO1HDL6fPH6Cz1RlAdWtTV4l/5dMPIQx2+SHw50D5 uOiatkPwFxnF7P1+ZFdESM1sgXzPzWsNBGLWukYxvMZq/xD9gbU91cVa1UkkermFXT9J WznyZFFuvt0gThwBTIGWvgTN7OzfuYVZTcG0QkMI+u9N8kAFSFKVcjhTWeEq1EsnK2+a 0Tvg== X-Gm-Message-State: AJIora/tAz8H+0Gz6Oo+pmKfXTJE6CDYELYNCP/Ii8TiVFmj41CXEbvw F1kUMQTflg5U7luI7QtffvMdy/0lBoAA7gRR X-Google-Smtp-Source: AGRyM1uvH5Znq4N03NbmOehpbvXHb1ccAXJjPrGkrLjWlZtb4IK7kBSduaCcFDxUCXWADJpq1TtUHQ== X-Received: by 2002:a05:6000:1541:b0:219:c470:186c with SMTP id 1-20020a056000154100b00219c470186cmr13367321wry.34.1656075933681; Fri, 24 Jun 2022 06:05:33 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id m20-20020a05600c4f5400b0039747cf8354sm2889703wmq.39.2022.06.24.06.05.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jun 2022 06:05:33 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Jun 2022 15:05:23 +0200 Message-Id: <20220624130523.41535-3-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220624130523.41535-1-dse@thaumatec.com> References: <20220624130523.41535-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/2] cam: capture_script: Check parseFrames() return value for errors 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: Daniel Semkowicz via libcamera-devel From: Daniel Semkowicz Reply-To: Daniel Semkowicz Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" parseFrames() return value was ignored. If there was an error during frame parsing, parsing was not stopped correctly. Signed-off-by: Daniel Semkowicz Reviewed-by: Laurent Pinchart --- src/cam/capture_script.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cam/capture_script.cpp b/src/cam/capture_script.cpp index 5812b122..9f7ab2af 100644 --- a/src/cam/capture_script.cpp +++ b/src/cam/capture_script.cpp @@ -150,7 +150,9 @@ int CaptureScript::parseScript(FILE *script) std::string section = eventScalarValue(event); if (section == "frames") { - parseFrames(); + ret = parseFrames(); + if (ret) + return ret; } else { std::cerr << "Unsupported section '" << section << "'" << std::endl;