From patchwork Fri May 27 14:44:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 16077 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 DF276C3256 for ; Fri, 27 May 2022 14:45:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D5CEB65652; Fri, 27 May 2022 16:45:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653662713; bh=GrOP/OlQSS6f85g7v8fdN0LyeTNIso0TXXdoVOivEro=; 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=nfSLscfAIxUKlHYesqCCqQNZWEI9WguK7zLesqOn3xiX4YEthwOuY0yoAeYyZEVKO e0/GlK2P/88oxppwJsuBBdkOo/F1/7VpGUsGRTYTsbrHag+dko2yS7DPVOcDEBjM1S 0s6Wk6BBxAilka+6MW1TOonTA8F4JDyrcj5S6rk8JxES9Bh7/iN5IVD0KKLwAe32d3 tr+O050JPuYM+LHTvo7rdwta4+DQTLN7B20cn2wYgi74v2WGbfDmRk0QzEvA95MjPk Jgu6DJbnYJ/Mnx2LflxTZwBiVoNsqdST31mpwJdwsfrCRFcQfZIhooYlt5cuJO3QRM 8DxNN8UfEVvQQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8E4EB65638 for ; Fri, 27 May 2022 16:45:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XiBouHCs"; 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 102D8FE0; Fri, 27 May 2022 16:45:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653662707; bh=GrOP/OlQSS6f85g7v8fdN0LyeTNIso0TXXdoVOivEro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XiBouHCsLOtymTd64JtfZUZt6VJBlSdW0imhR1U2dkIBHxPBx/q1uCJ/J2Rw+c/j8 RnrtJT5JpPOaN6u8x7x3k/t5N+prshAm64Kl4hXHCwQnDcAqFxjrYg6ukc8rgf112O JDeTOroOCeVg7sNsKhtf3vGlHH3pIbS+HTgVt3dM= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Fri, 27 May 2022 17:44:23 +0300 Message-Id: <20220527144447.94891-7-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220527144447.94891-1-tomi.valkeinen@ideasonboard.com> References: <20220527144447.94891-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 06/30] py: Add CameraManager.read_event() 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" Add CameraManager.read_event() so that the user does not need to call os.read(). We use eventfd, and we must always read 8 bytes. Hiding that inside read_event() makes sense. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- src/py/cam/cam.py | 3 +-- src/py/libcamera/py_main.cpp | 8 ++++++++ test/py/unittests.py | 3 +-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py index e2bc78da..66df18bf 100755 --- a/src/py/cam/cam.py +++ b/src/py/cam/cam.py @@ -9,7 +9,6 @@ import argparse import binascii import libcamera as libcam -import os import sys import traceback @@ -294,7 +293,7 @@ def event_handler(state): cm = state['cm'] contexts = state['contexts'] - os.read(cm.efd, 8) + cm.read_event() reqs = cm.get_ready_requests() diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index e7066841..5d389942 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -212,6 +212,14 @@ PYBIND11_MODULE(_libcamera, m) return gEventfd; }) + .def("read_event", [](CameraManager &) { + uint8_t buf[8]; + + int ret = read(gEventfd, buf, 8); + if (ret != 8) + throw std::system_error(errno, std::generic_category()); + }) + .def("get_ready_requests", [](CameraManager &) { std::vector v; diff --git a/test/py/unittests.py b/test/py/unittests.py index 7dede33b..8c445bc9 100755 --- a/test/py/unittests.py +++ b/test/py/unittests.py @@ -7,7 +7,6 @@ from collections import defaultdict import errno import gc import libcamera as libcam -import os import selectors import time import typing @@ -278,7 +277,7 @@ class SimpleCaptureMethods(CameraTesterBase): while running: events = sel.select() for key, _ in events: - os.read(key.fd, 8) + cm.read_event() ready_reqs = cm.get_ready_requests()