From patchwork Wed Jul 7 02:19:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12828 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 8EDF3C3229 for ; Wed, 7 Jul 2021 02:20:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4E6BC68547; Wed, 7 Jul 2021 04:20:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="H6Q5Z2oz"; dkim-atps=neutral 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 D46B168520 for ; Wed, 7 Jul 2021 04:20:36 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6E991DEE for ; Wed, 7 Jul 2021 04:20:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1625624436; bh=WQZDznOdlF0nRjRUwVUswkU1h4pQuFCdYq1zEA5OSz4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=H6Q5Z2ozeQuBz8qNJIexGUVITXkgvwQTZZAZaWWaPzbZFjkw8mHby/vy0hPAaWjha ACKS7mPZcR3VsaDFtZkShAWWNKYH2VDatrS89olePCmy4Z32OAv/dF+TU7n5LIOVmN eDZ7TQ0QqELLzLarflJm+En7cSY0H6lchlomCt24= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Jul 2021 05:19:26 +0300 Message-Id: <20210707021941.20804-16-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210707021941.20804-1-laurent.pinchart@ideasonboard.com> References: <20210707021941.20804-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 15/30] cam: Move event loop execution from CameraSession to CamApp 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To prepare for multiple concurrent camera sessions, move the event loop exec() call from the CameraSession class to the CamApp class. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/cam/camera_session.cpp | 43 +++++++++++++++++--------------------- src/cam/camera_session.h | 6 ++++-- src/cam/main.cpp | 12 ++++++++++- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp index 16c1c66a285a..b1200e60329c 100644 --- a/src/cam/camera_session.cpp +++ b/src/cam/camera_session.cpp @@ -22,11 +22,11 @@ CameraSession::CameraSession(std::shared_ptr camera, CameraConfiguration *config) : camera_(camera), config_(config), writer_(nullptr), last_(0), queueCount_(0), captureCount_(0), captureLimit_(0), - printMetadata_(false) + printMetadata_(false), allocator_(nullptr) { } -int CameraSession::run(const OptionsParser::Options &options) +int CameraSession::start(const OptionsParser::Options &options) { int ret; @@ -61,36 +61,39 @@ int CameraSession::run(const OptionsParser::Options &options) writer_ = new BufferWriter(); } - FrameBufferAllocator *allocator = new FrameBufferAllocator(camera_); + allocator_ = new FrameBufferAllocator(camera_); - ret = capture(allocator); + return startCapture(); +} - if (options.isSet(OptFile)) { - delete writer_; - writer_ = nullptr; - } +void CameraSession::stop() +{ + int ret = camera_->stop(); + if (ret) + std::cout << "Failed to stop capture" << std::endl; + + delete writer_; + writer_ = nullptr; requests_.clear(); - delete allocator; - - return ret; + delete allocator_; } -int CameraSession::capture(FrameBufferAllocator *allocator) +int CameraSession::startCapture() { int ret; /* Identify the stream with the least number of buffers. */ unsigned int nbuffers = UINT_MAX; for (StreamConfiguration &cfg : *config_) { - ret = allocator->allocate(cfg.stream()); + ret = allocator_->allocate(cfg.stream()); if (ret < 0) { std::cerr << "Can't allocate buffers" << std::endl; return -ENOMEM; } - unsigned int allocated = allocator->buffers(cfg.stream()).size(); + unsigned int allocated = allocator_->buffers(cfg.stream()).size(); nbuffers = std::min(nbuffers, allocated); } @@ -109,7 +112,7 @@ int CameraSession::capture(FrameBufferAllocator *allocator) for (StreamConfiguration &cfg : *config_) { Stream *stream = cfg.stream(); const std::vector> &buffers = - allocator->buffers(stream); + allocator_->buffers(stream); const std::unique_ptr &buffer = buffers[i]; ret = request->addBuffer(stream, buffer.get()); @@ -146,15 +149,7 @@ int CameraSession::capture(FrameBufferAllocator *allocator) else std::cout << "Capture until user interrupts by SIGINT" << std::endl; - ret = EventLoop::instance()->exec(); - if (ret) - std::cout << "Failed to run capture loop" << std::endl; - - ret = camera_->stop(); - if (ret) - std::cout << "Failed to stop capture" << std::endl; - - return ret; + return 0; } int CameraSession::queueRequest(Request *request) diff --git a/src/cam/camera_session.h b/src/cam/camera_session.h index 2728d7607db2..5131cfd48b4e 100644 --- a/src/cam/camera_session.h +++ b/src/cam/camera_session.h @@ -28,12 +28,13 @@ public: CameraSession(std::shared_ptr camera, libcamera::CameraConfiguration *config); - int run(const OptionsParser::Options &options); + int start(const OptionsParser::Options &options); + void stop(); libcamera::Signal<> captureDone; private: - int capture(libcamera::FrameBufferAllocator *allocator); + int startCapture(); int queueRequest(libcamera::Request *request); void requestComplete(libcamera::Request *request); @@ -51,6 +52,7 @@ private: unsigned int captureLimit_; bool printMetadata_; + libcamera::FrameBufferAllocator *allocator_; std::vector> requests_; }; diff --git a/src/cam/main.cpp b/src/cam/main.cpp index a567a7cc7653..b13230c374ad 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -371,7 +371,17 @@ int CamApp::run() if (options_.isSet(OptCapture)) { CameraSession session(camera_, config_.get()); session.captureDone.connect(this, &CamApp::captureDone); - return session.run(options_); + + ret = session.start(options_); + if (ret) { + std::cout << "Failed to start camera session" << std::endl; + return ret; + } + + loop_.exec(); + + session.stop(); + return 0; } if (options_.isSet(OptMonitor)) {