From patchwork Fri Jun 17 14:35:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Semkowicz X-Patchwork-Id: 16268 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 EAB26C3275 for ; Fri, 17 Jun 2022 14:36:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5660B65632; Fri, 17 Jun 2022 16:36:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655476565; bh=hhnoCMzCfRivBh9MgDRXZ3EySgVnoGHUFnZUEy9Y1V8=; 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=Z0OFWPcfgRynrxTaXrruv4RE/wYav66+HAdPDb05/kGWSRVEYVYfgcBVYvIGLs1db sMS8c+VfOi/QvY/JmJuftgtkRNIrrgSdkrAHrHlUUCKk2rrjLZNis2LP1fpGj2S29t EfGoYSnYnO52klFH+gzttP/2yX6Q9N1JriE2Jx8e7wsdDKllbnJrvG/7WF1XrwObOv XPqhfJNbj0lypROx+aXUX0TJoJg5d1XhUyyr88FtYsYtLn/SZs9ldTSeIBJzT0f8Yk jO3hbg3SQB2Tv0nMp/CYtWyN9y7qLI2huI+q+uqLhEz0chFBjB7BE7VCzmQ2Vty2Kl YoVjaM0BjuM2g== Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B97D65634 for ; Fri, 17 Jun 2022 16:36:04 +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="iDQg2qMY"; dkim-atps=neutral Received: by mail-ej1-x62e.google.com with SMTP id hj18so8551716ejb.0 for ; Fri, 17 Jun 2022 07:36:04 -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=ES6xm68K6Natf3Fld5kgrC9puFGuwBiA/I1sDxCCj00=; b=iDQg2qMYN5cjkqQZp1jJBDuUY7cc144998os75uMoaJ3S1+fwHErUYN8aJ+vCkoK7r Sr3qIfLBZYUhr19eewMwp4EZ/uNvbby1A4vrYrGm32v2YB5AuetZdU+zrHtvJQRWNMLE B9063sjyPDRTnooTvCWeFvKDgxIOCO/F4zSF+MD72mXSftt8zu5mlS6BUpF9PYVJ/V8+ EL0jwWkLvfSdiSAqbtMGGjqIKqwnChWh4AwNx06Mskq8v8jN+SBN56J1NTwX0RjlHAfc WlXdCcusNuJDsUYP3QOCdJ8hURMT2aClfg26eAj5uedbwv1z54yE3JAA3jIbulJA08PM pDFw== 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=ES6xm68K6Natf3Fld5kgrC9puFGuwBiA/I1sDxCCj00=; b=UVsj2d0lwiLw87kaapuzS2sx8pbV9GW3zfMCTs9AxH3HEaurYMSNyKem+HszDZjv5Y zabof/bxIeb9xPrcJXamPxRUJsPOrbNTRYMXDbrZCkALfgCL3vnfX74olnc/Br4Zc4Vy Vrdvi79Bc1Ct+LBnR9HgMnZcKVqAEkRcWJ+fE//M0Zs7ahMu2wXSrXG/1llkHTlKkHId kP0ujVcXIwnvGtqSx0gKLfTmm9HyyEF1Rkz1asHz5mlBQKygz/xE3MV2un6Ca1paos/+ iwxYkjigr7UMZ+2mZUeJw+DuviM0r3CZzO2Dy7soi2chTFvl1zXvm46dY/KB1zH2o9Nw Ix9g== X-Gm-Message-State: AJIora//LQefYx3ZjkQG/ujgQ9DXwP0Q5IJDchyvFfP9qr0dd8iiAvC4 faMNxTw1Nfi79Qqi73G8V1iK4bd5HvSbIg== X-Google-Smtp-Source: AGRyM1slK5lxJd4t+gZSLGP5/CCKoxWxDu5XKoQsmtdn16a4VLAH7uVyVtEjhn5LS41209UlwBR8uw== X-Received: by 2002:a17:906:4f:b0:712:af2:29d9 with SMTP id 15-20020a170906004f00b007120af229d9mr9676537ejg.751.1655476563865; Fri, 17 Jun 2022 07:36:03 -0700 (PDT) Received: from localhost.localdomain (ip092042140082.rev.nessus.at. [92.42.140.82]) by smtp.gmail.com with ESMTPSA id u20-20020aa7d554000000b0042a2d9af0f8sm3746189edr.79.2022.06.17.07.36.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 07:36:03 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 17 Jun 2022 16:35:49 +0200 Message-Id: <20220617143549.35442-4-dse@thaumatec.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220617143549.35442-1-dse@thaumatec.com> References: <20220617143549.35442-1-dse@thaumatec.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/3] Documentation: Update the "Start an event loop" section 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" Event loop was moved to be a part of CameraManager, so it is no longer a user responsibility to control the event dispatching. Signed-off-by: Daniel Semkowicz Reviewed-by: Laurent Pinchart --- .../guides/application-developer.rst | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/Documentation/guides/application-developer.rst b/Documentation/guides/application-developer.rst index a5f363cf..f4551f58 100644 --- a/Documentation/guides/application-developer.rst +++ b/Documentation/guides/application-developer.rst @@ -27,10 +27,12 @@ defined names and types without the need of prefixing them. #include #include #include + #include #include using namespace libcamera; + using namespace std::chrono_literals; int main() { @@ -506,35 +508,27 @@ and queue all the previously created requests. for (std::unique_ptr &request : requests) camera->queueRequest(request.get()); -Start an event loop +Event processing ~~~~~~~~~~~~~~~~~~~ -The libcamera library needs an event loop to monitor and dispatch events -generated by the video devices part of the capture pipeline. libcamera provides -its own ``EventDispatcher`` class (inspired by the `Qt event system`_) to -process and deliver events generated by ``EventNotifiers``. +libcamera creates an internal execution thread at `CameraManager::start()`_ +time to decouple its own event processing from the application's main thread. +Applications are thus free to manage their own execution opportunely, and only +need to respond to events generated by libcamera emitted through signals. -.. _Qt event system: https://doc.qt.io/qt-5/eventsandfilters.html +.. _CameraManager::start(): https://libcamera.org/api-html/classlibcamera_1_1CameraManager.html#a49e322880a2a26013bb0076788b298c5 -The libcamera library implements this by creating instances of the -``EventNotifier`` class, which models a file descriptor event source registered -to an ``EventDispatcher``. Whenever the ``EventDispatcher`` detects an event on -a notifier it is monitoring, it emits the notifier's -``EventNotifier::activated`` signal. The libcamera components connect to the -notifiers' signals and emit application visible events, such as the -``Camera::bufferReady`` and ``Camera::requestCompleted`` signals. - -The code below retrieves a reference to the system-wide event dispatcher and for -the a fixed duration of 3 seconds, processes all the events detected in the -system. +Real-world applications will likely either integrate with the event loop of the +framework they use, or create their own event loop to respond to user events. +For the simple application presented in this example, it is enough to prevent +immediate termination by pausing for 3 seconds. During that time, the libcamera +thread will generate request completion events that the application will handle +in the ``requestComplete()`` slot connected to the ``Camera::requestCompleted`` +signal. .. code:: cpp - EventDispatcher *dispatcher = cm->eventDispatcher(); - Timer timer; - timer.start(3000); - while (timer.isRunning()) - dispatcher->processEvents(); + std::this_thread::sleep_for(3000ms); Clean up and stop the application ---------------------------------