From patchwork Fri Oct 16 05:51:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 10076 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 BB154BE905 for ; Fri, 16 Oct 2020 05:51:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 346DE60F61; Fri, 16 Oct 2020 07:51:42 +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="mvZyuZYX"; 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 2E27360354 for ; Fri, 16 Oct 2020 07:51:40 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A357F528; Fri, 16 Oct 2020 07:51:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1602827499; bh=45GwxK1nIMcjnmyr55/Jzr+4PBm4UZoVaxoSACi8aRE=; h=From:To:Cc:Subject:Date:From; b=mvZyuZYXoomQyfrmAFyOt2jRxKw+AJKQrBbsTqVeAFz444hlIhng7QEazQsHkLEst NmW/r3+13Qfahsa3MqadNZimnbWbkFUWUBfY1aWcKPcAVjJ2hHaN3DJKkgxE5eYE2e nf6mr0oVb2UHwapfTRRRfkjzjOrYcVSxIJ5IhxKA= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Fri, 16 Oct 2020 14:51:19 +0900 Message-Id: <20201016055119.682577-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] simple-cam: Reuse Requests 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" Update simple-cam to reuse Request objects, and use the new API with unique pointers. Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham --- simple-cam.cpp | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/simple-cam.cpp b/simple-cam.cpp index 3aa975e..727bb6d 100644 --- a/simple-cam.cpp +++ b/simple-cam.cpp @@ -55,27 +55,8 @@ static void requestComplete(Request *request) */ } - /* - * Re-queue a Request to the camera. - * - * Create a new request and populate it with one buffer for each - * stream. - */ - request = camera->createRequest(); - if (!request) - { - std::cerr << "Can't create request" << std::endl; - return; - } - - for (auto it = buffers.begin(); it != buffers.end(); ++it) - { - const Stream *stream = it->first; - FrameBuffer *buffer = it->second; - - request->addBuffer(stream, buffer); - } - + /* Re-queue the Request to the camera. */ + request->reuse(Request::ReuseBuffers); camera->queueRequest(request); } @@ -263,9 +244,9 @@ int main() */ Stream *stream = streamConfig.stream(); const std::vector> &buffers = allocator->buffers(stream); - std::vector requests; + std::vector> requests; for (unsigned int i = 0; i < buffers.size(); ++i) { - Request *request = camera->createRequest(); + std::unique_ptr request = camera->createRequest(); if (!request) { std::cerr << "Can't create request" << std::endl; @@ -281,13 +262,13 @@ int main() return ret; } - requests.push_back(request); - /* * Controls can be added to a request on a per frame basis. */ ControlList &controls = request->controls(); controls.set(controls::Brightness, 0.5); + + requests.push_back(std::move(request)); } /* @@ -323,8 +304,8 @@ int main() * Camera::requestCompleted Signal is called. */ camera->start(); - for (Request *request : requests) - camera->queueRequest(request); + for (std::unique_ptr &request : requests) + camera->queueRequest(request.get()); /* * --------------------------------------------------------------------