{"id":15997,"url":"https://patchwork.libcamera.org/api/1.1/patches/15997/?format=json","web_url":"https://patchwork.libcamera.org/patch/15997/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220520190106.425386-3-ecurtin@redhat.com>","date":"2022-05-20T19:01:04","name":"[libcamera-devel,v9,2/4] cam: event_loop: Add timer events to event loop","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"87f3535ab996676a8be22fded43d591b921adeda","submitter":{"id":101,"url":"https://patchwork.libcamera.org/api/1.1/people/101/?format=json","name":"Eric Curtin","email":"ecurtin@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15997/mbox/","series":[{"id":3132,"url":"https://patchwork.libcamera.org/api/1.1/series/3132/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3132","date":"2022-05-20T19:01:02","name":"Add SDL Sink","version":9,"mbox":"https://patchwork.libcamera.org/series/3132/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15997/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15997/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id D4ECAC0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 20 May 2022 19:02:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8DD5E65667;\n\tFri, 20 May 2022 21:02:09 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0D94C65663\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 May 2022 21:02:07 +0200 (CEST)","from mail-wm1-f71.google.com (mail-wm1-f71.google.com\n\t[209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n\tus-mta-412-J-vghI-bNA24ml8s7UIQ8A-1; Fri, 20 May 2022 15:02:05 -0400","by mail-wm1-f71.google.com with SMTP id\n\th206-20020a1c21d7000000b003972daa86deso964145wmh.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 May 2022 12:02:05 -0700 (PDT)","from p1.Home ([2001:8a0:6724:4500:a69c:e66f:828e:b340])\n\tby smtp.gmail.com with ESMTPSA id\n\tu30-20020adfa19e000000b0020d10a249eesm3337016wru.13.2022.05.20.12.02.02\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 20 May 2022 12:02:02 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1653073329;\n\tbh=B8VTTXCFUQ2Gnd4inRf4FehAdih3Zg1nyx6zprQwKYY=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=mr5x/uRbDiUp8o9RTmspcxTcNhKhKQCsSx0ApSmqVXsc3w5rbwZKStzlIId73du97\n\tSsISnvWt5mbuIX5quzjfmhU3ACepcT9/zIuhb4HdxbrfkaUq0dpcQRv0CghV7y6MZd\n\tH5Jxcu/YrntEhr12J6dNweEMb6EPAhFkEawYKMk4i18oK887JykFfevfMl3o/k9Y2o\n\t6ODtNyNL6jEusyS+391Ty12/ReQzgAFETSyd0+zJ/1oJPtObqSyxQ2bZXvbgyws3tH\n\tGB8rRtcCkwzXbCJm/BYIzepbgg0dIkCk4K/Akwh0hzePyTMawgF6R4RE7vOpqQUgVJ\n\taYsYEzQ6NJHbA==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1653073326;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=FzSpgTqmVJ20LOMPTuGRhBF3U13P52ivipiCwXFCx5w=;\n\tb=Soe6ZoVxA0HI4bNSC+cboB9oad0vTpFkT1Twz0E0SsqzUyi+iCKhoeEBLXnxhNXE0BzOFO\n\tS9wiVslEuHphdc2qk5C54SOVe9gPd7opfw5Pw6VFuf72PSqRG/nbYZWV7R2DNEPFe8OBPQ\n\txy+Ray7k2wDen/w+gPBUgUZpaAWVOjk="],"Authentication-Results":["lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"Soe6ZoVx\"; \n\tdkim-atps=neutral","relay.mimecast.com;\n\tauth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com"],"X-MC-Unique":"J-vghI-bNA24ml8s7UIQ8A-1","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=FzSpgTqmVJ20LOMPTuGRhBF3U13P52ivipiCwXFCx5w=;\n\tb=YItMKVu+LDGV4Bdipu750xZAZDZDoEDz9LF+AmFsOBj8oCZdfQZbTj8AX4kWdLxoUW\n\tV9pAWfgkR53qM+kaR8Ro06GOlEb8NXI1DrqWKnJ9vLrISYL837Y5ou5t3JbEHEz0rLMb\n\tbA0eDaccMxaNdZ+ySBfF8FzD5p9h0RXpmP5C5ZHsXV6ZbVsjE5oRhvVA4GIPO+ZS0CUI\n\tplXN8ZZv7o0C6MqZt8gbK9oXghxwWwMCaKYWRbmIWq/C1hUhXhB1m3ScpQrTagt9Vf7g\n\ty5Y/0uT0obPW96hk0Le5DC/gTX/tvUijkJi8CQhODO4WQo4E0OkRB+1beiR+b941XIKI\n\t1uiw==","X-Gm-Message-State":"AOAM530gvrA1HaiHk73tyhBm35rwyJOBs/gOy1Q9AuE8lOFFL4/GEpPV\n\tc6qtKAk9lm4iiLAMRScBJJ6OFHHmuhhrynH/UtEG9I/bhRgOz7mn3bBqEiYdX/k9Aeuq9rpSr3/\n\tR/9uc2DnuBJ9Pq53izlJSadvetPvxLnSUMsPUyxswbpDN8kNZWJnFELS3XgzdqF6mtZQWggKPVC\n\tf0YcqOn/yq","X-Received":["by 2002:a7b:c5d1:0:b0:37f:a8a3:9e17 with SMTP id\n\tn17-20020a7bc5d1000000b0037fa8a39e17mr9661229wmk.109.1653073324140; \n\tFri, 20 May 2022 12:02:04 -0700 (PDT)","by 2002:a7b:c5d1:0:b0:37f:a8a3:9e17 with SMTP id\n\tn17-20020a7bc5d1000000b0037fa8a39e17mr9661203wmk.109.1653073323713; \n\tFri, 20 May 2022 12:02:03 -0700 (PDT)"],"X-Google-Smtp-Source":"ABdhPJyx4BYjfmA59a5sCuLbdZhAq53dO3cWxGhNRrZDG7EoxLZ1ZUjUNf7+nrOrcH/gqqyE4XMOJQ==","To":"libcamera-devel@lists.libcamera.org, laurent.pinchart@ideasonboard.com, \n\tkieran.bingham@ideasonboard.com, jacopo@jmondi.org, javierm@redhat.com","Date":"Fri, 20 May 2022 20:01:04 +0100","Message-Id":"<20220520190106.425386-3-ecurtin@redhat.com>","X-Mailer":"git-send-email 2.35.3","In-Reply-To":"<20220520190106.425386-1-ecurtin@redhat.com>","References":"<20220520190106.425386-1-ecurtin@redhat.com>","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Transfer-Encoding":"8bit","Content-Type":"text/plain; charset=\"US-ASCII\"; x-default=true","Subject":"[libcamera-devel] [PATCH v9 2/4] cam: event_loop: Add timer events\n\tto event loop","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Eric Curtin via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Eric Curtin <ecurtin@redhat.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Extend the EventLoop class to support periodic timer events. This can be\nused to run tasks periodically, such as handling the event loop of SDL.\n\nAlso delete all events in the list, before we event_base_loopbreak, in\nan effort to avoid race conditions.\n\nSigned-off-by: Eric Curtin <ecurtin@redhat.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nTested-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/cam/event_loop.cpp | 27 +++++++++++++++++++++++++++\n src/cam/event_loop.h   |  7 ++++++-\n 2 files changed, 33 insertions(+), 1 deletion(-)","diff":"diff --git a/src/cam/event_loop.cpp b/src/cam/event_loop.cpp\nindex 2e3ce995..315da38a 100644\n--- a/src/cam/event_loop.cpp\n+++ b/src/cam/event_loop.cpp\n@@ -47,6 +47,8 @@ int EventLoop::exec()\n void EventLoop::exit(int code)\n {\n \texitCode_ = code;\n+\tevents_.clear();\n+\n \tevent_base_loopbreak(base_);\n }\n \n@@ -84,6 +86,31 @@ void EventLoop::addFdEvent(int fd, EventType type,\n \tevents_.push_back(std::move(event));\n }\n \n+void EventLoop::addTimerEvent(const duration period,\n+\t\t\t      const std::function<void()> &callback)\n+{\n+\tstd::unique_ptr<Event> event = std::make_unique<Event>(callback);\n+\tevent->event_ = event_new(base_, -1, EV_PERSIST, &EventLoop::Event::dispatch,\n+\t\t\t\t  event.get());\n+\tif (!event->event_) {\n+\t\tstd::cerr << \"Failed to create timer event\" << std::endl;\n+\t\treturn;\n+\t}\n+\n+\tstruct timeval tv;\n+\tconst uint64_t usecs = std::chrono::duration_cast<std::chrono::microseconds>(period).count();\n+\ttv.tv_sec = usecs / 1000000ULL;\n+\ttv.tv_usec = usecs % 1000000ULL;\n+\n+\tconst int ret = event_add(event->event_, &tv);\n+\tif (ret < 0) {\n+\t\tstd::cerr << \"Failed to add timer event\" << std::endl;\n+\t\treturn;\n+\t}\n+\n+\tevents_.push_back(std::move(event));\n+}\n+\n void EventLoop::dispatchCallback([[maybe_unused]] evutil_socket_t fd,\n \t\t\t\t [[maybe_unused]] short flags, void *param)\n {\ndiff --git a/src/cam/event_loop.h b/src/cam/event_loop.h\nindex 79902d87..22769ea5 100644\n--- a/src/cam/event_loop.h\n+++ b/src/cam/event_loop.h\n@@ -7,9 +7,10 @@\n \n #pragma once\n \n+#include <chrono>\n #include <functional>\n-#include <memory>\n #include <list>\n+#include <memory>\n #include <mutex>\n \n #include <event2/util.h>\n@@ -37,6 +38,10 @@ public:\n \tvoid addFdEvent(int fd, EventType type,\n \t\t\tconst std::function<void()> &handler);\n \n+\tusing duration = std::chrono::steady_clock::duration;\n+\tvoid addTimerEvent(const duration period,\n+\t\t\t   const std::function<void()> &handler);\n+\n private:\n \tstruct Event {\n \t\tEvent(const std::function<void()> &callback);\n","prefixes":["libcamera-devel","v9","2/4"]}