From patchwork Thu Mar 31 13:06:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Curtin X-Patchwork-Id: 15589 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 EF220C3256 for ; Thu, 31 Mar 2022 13:06:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9F4F065638; Thu, 31 Mar 2022 15:06:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648731983; bh=zMLvytW4CG/cfsO6Ief/dhTrEb4NA6qGozArrJJWFbM=; 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=yGFg4MI/xabfROBUFI8xxf8DW4jRfxVQYJCQoEGsId7HYvpeJ9PRK3kMcSzQpbtWu h+ymTakKmxcdYfqGYIWQWxR3YgZ/M9nT6mmoynU2jHJRnbNE7oFl4Zy7U5tKHcDAhs eHXFseM4S0M6y9d5bOSTczupFCE3ZDAO4hoOXU7V93Uz4P/3jW5ZL1SVshUj2Y3+aU A3ahg9dd8HkYA3c2SjWnrXUcJlEjFB3eTT9t+dhsoTbmMQ1tbbQ2/A5k7bCqo9mtsj HiU6oKsuL06r35tVysNiCxC0uhaIa22tByc0pLLiSIV66Lihtad7fn43V7+j/6tBs6 xW4Ro8xzkknCw== Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3999A6559A for ; Thu, 31 Mar 2022 15:06:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="Vq3JAZOa"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648731980; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=95sP7rPZv50sCVWcj2ajITKn/riJ4Z8qvWBgJqLAoBY=; b=Vq3JAZOaKmMvQfB3fjZ2e0CWyfbdqFZ6xeoUP/YbJxhcA6/yIomyCowhIT0M/pHqGHcw54 +DWGdpKoeCyKgRyK5rSx0/J4Gq2R0+9wfknyef790XEKEKKzA2UTvEAslS85LzfFW9jSwu UHKsudUDaFmMM27xJFpm6CUJdHnmYP8= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-107-7GxvI2_GONS6_U4b9IS73Q-1; Thu, 31 Mar 2022 09:06:19 -0400 X-MC-Unique: 7GxvI2_GONS6_U4b9IS73Q-1 Received: by mail-wm1-f71.google.com with SMTP id 2-20020a1c0202000000b0038c71e8c49cso1395830wmc.1 for ; Thu, 31 Mar 2022 06:06:18 -0700 (PDT) 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=95sP7rPZv50sCVWcj2ajITKn/riJ4Z8qvWBgJqLAoBY=; b=MqbW9mNlq8ciPkJ5S52Wp9rbkVQKPmhhSp3YFx89JxhYArTzWvonMLT6yWm68yYk2W rnj2q6AnddxnRvy1Gvv03l4rS0362GK49eJQBsGFYMOcxRuMph+Slpp7VZIqr9eMqojG xkrS5YA+2b5PUcYUWh/rze643veAVXGPIMnEHSQhPbnUk25xwTYTTQ5YBQxHVgmUdqCu z4W5lKR1saL46RDtlF1HHZbR828a2WtwCXK7ZbngjzKxm1jITPui7RoIXzEKmyG5rvby WwfljC6/YbFdS/JY7wSSrXH1Z6ZMVmcpVYm8xegT1P8DOl7prSRm9fMNGQY25NiH+XVX DFpw== X-Gm-Message-State: AOAM530vYtVV4ViKzShal2jWsVuXwBtaDAroMZDCdxyVEXXWnwNwflxc lDY/39qEEXGs2gIXqSCowBHU/1XQSDKzogqc3FbAuPaM+L3npbiKqP2cRhTXpH7PQKxRaabZGbX 9gMCYsnK5ok9WNvdKUuWjMGcjwrAQPBZdb6siAiV3i3geV9mERNFjvVfI88pFOwdR0y5VNWKZhi EHg5rcDu7L X-Received: by 2002:adf:ee87:0:b0:203:de0b:b236 with SMTP id b7-20020adfee87000000b00203de0bb236mr4003112wro.337.1648731977269; Thu, 31 Mar 2022 06:06:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnl6RQhKRhp2JWzdcdglIhwERUO8vK3XCOyBXvx+uznWBGrNftvKMPbnlyrrV4wAIsPfoSdA== X-Received: by 2002:adf:ee87:0:b0:203:de0b:b236 with SMTP id b7-20020adfee87000000b00203de0bb236mr4003090wro.337.1648731976969; Thu, 31 Mar 2022 06:06:16 -0700 (PDT) Received: from p1.Home ([2001:8a0:6724:4500:a69c:e66f:828e:b340]) by smtp.gmail.com with ESMTPSA id 7-20020a05600c028700b0038cc9bfe6a4sm6883538wmk.37.2022.03.31.06.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 06:06:16 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 31 Mar 2022 14:06:10 +0100 Message-Id: <20220331130610.31806-2-ecurtin@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220331130610.31806-1-ecurtin@redhat.com> References: <20220331130610.31806-1-ecurtin@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [libcamera-devel] [PATCH v5 2/2] cam: event_loop: Add timed events to event loop 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: Eric Curtin via libcamera-devel From: Eric Curtin Reply-To: Eric Curtin Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" If you add an event with EventLoop::Default, that event will be executed every 10ms or at a rate of 100fps. Used to handle resize of windows and quit events in SDL. Signed-off-by: Eric Curtin --- src/cam/event_loop.cpp | 10 +++++++++- src/cam/event_loop.h | 1 + src/cam/sdl_sink.cpp | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/cam/event_loop.cpp b/src/cam/event_loop.cpp index e25784c0..7a5ed4da 100644 --- a/src/cam/event_loop.cpp +++ b/src/cam/event_loop.cpp @@ -75,7 +75,15 @@ void EventLoop::addEvent(int fd, EventType type, return; } - int ret = event_add(event->event_, nullptr); + struct timeval *tp = nullptr; + struct timeval tv; + if (events == EV_PERSIST) { /* EventType = Default */ + tp = &tv; + tv.tv_sec = 0; + tv.tv_usec = 10000; /* every 10 ms */ + } + + int ret = event_add(event->event_, tp); if (ret < 0) { std::cerr << "Failed to add event for fd " << fd << std::endl; return; diff --git a/src/cam/event_loop.h b/src/cam/event_loop.h index a4613eb2..8fd9bd20 100644 --- a/src/cam/event_loop.h +++ b/src/cam/event_loop.h @@ -20,6 +20,7 @@ class EventLoop { public: enum EventType { + Default = 0, /* the event can be triggered only by a timeout or by manual activation */ Read = 1, Write = 2, }; diff --git a/src/cam/sdl_sink.cpp b/src/cam/sdl_sink.cpp index 28e59cbb..97a550b5 100644 --- a/src/cam/sdl_sink.cpp +++ b/src/cam/sdl_sink.cpp @@ -117,7 +117,7 @@ int SDLSink::start() return -EINVAL; } - EventLoop::instance()->addEvent(-1, EventLoop::Read, std::bind(&SDLSink::processSDLEvents, this)); + EventLoop::instance()->addEvent(-1, EventLoop::Default, std::bind(&SDLSink::processSDLEvents, this)); return 0; }