From patchwork Thu May 5 10:41:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15794 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 17081C3271 for ; Thu, 5 May 2022 10:41:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 65A636566F; Thu, 5 May 2022 12:41:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651747297; bh=na9LqJT9Kll4y+N+bUCkl2veymqhxZf7LnOIYxMG3tE=; 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=oDluzx7eH51RY7+IgMbjRBcKd9vV0T7Po5EUdL6ECjxTVrAlpbIL8B8RLu9ZuBCxC UIvAZ4MgFIdsccrxHguaDUJn/5/CliYtwPBrEWfVSdYN7BY1YxKt3dGqtROqCrzAtb Z06ruNuXlGU1O0hvbfF5gs5xWMwmAY+UKCdJKF6bzFWYE40CIUuoJCEqF3yeIGGCDb ywWdv6iIM9pfskLnM17reF7A2+xS6huA0rZMq0Gj78CGkHXgDFAUOyiRhddSOUQmTe EXNaTWiuWQHVdF2db1UWAw+EcjURKA0nEDOqoz0sEJY4rkmBl2XidjutID0tgfDnH4 mNHXKEn2vAEhQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8C22560424 for ; Thu, 5 May 2022 12:41:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tq+jH4ho"; dkim-atps=neutral Received: from deskari.lan (91-156-85-209.elisa-laajakaista.fi [91.156.85.209]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ED9B4492; Thu, 5 May 2022 12:41:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1651747291; bh=na9LqJT9Kll4y+N+bUCkl2veymqhxZf7LnOIYxMG3tE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tq+jH4hoHbGD8fOfI0iqpkIN7en9Yj/rJ4Dfoj2x0ld3j0oVY8v02Di7h764l2XFZ u8OURpVZcuY5s8Aa7d1fjrfZKMo23kBgyJ5XCy7jF0U/VmTDW6/GRveKkfCg1I2kjZ pVzN+a0Hf5wugKLcQSc+NUyh0j/jSAb61+ZMl8+U= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Thu, 5 May 2022 13:41:02 +0300 Message-Id: <20220505104104.70841-12-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220505104104.70841-1-tomi.valkeinen@ideasonboard.com> References: <20220505104104.70841-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 11/13] py: support controls in the start method 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: Tomi Valkeinen via libcamera-devel From: Tomi Valkeinen Reply-To: Tomi Valkeinen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: David Plowman Libcamera has for a while allowed controls to be set in the camera's start method. The Python bindings need to permit this too. Signed-off-by: David Plowman Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- src/py/libcamera/pymain.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/py/libcamera/pymain.cpp b/src/py/libcamera/pymain.cpp index c442ad50..6375e326 100644 --- a/src/py/libcamera/pymain.cpp +++ b/src/py/libcamera/pymain.cpp @@ -250,15 +250,34 @@ PYBIND11_MODULE(_libcamera, m) .def_property_readonly("id", &Camera::id) .def("acquire", &Camera::acquire) .def("release", &Camera::release) - .def("start", [](Camera &self) { + .def("start", [](Camera &self, py::dict controls) { self.requestCompleted.connect(handleRequestCompleted); - int ret = self.start(); + const ControlInfoMap &controlMap = self.controls(); + ControlList controlList(controlMap); + for (const auto& [hkey, hval]: controls) { + auto key = hkey.cast(); + + auto it = find_if(controlMap.begin(), controlMap.end(), + [&key](const auto &kvp) { + return kvp.first->name() == key; }); + + if (it == controlMap.end()) + throw runtime_error("Control " + key + " not found"); + + const auto &id = it->first; + auto obj = py::cast(hval); + + controlList.set(id->id(), PyToControlValue(obj, id->type())); + } + + int ret = self.start(&controlList); if (ret) self.requestCompleted.disconnect(handleRequestCompleted); return ret; - }) + }, + py::arg("controls") = py::dict()) .def("stop", [](Camera &self) { int ret = self.stop();