From patchwork Fri Jul 3 12:39:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8584 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 C828AC2E69 for ; Fri, 3 Jul 2020 12:39:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8879D60CE4; Fri, 3 Jul 2020 14:39:29 +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="glHynd/+"; 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 ACF9060C63 for ; Fri, 3 Jul 2020 14:39:25 +0200 (CEST) Received: from Q.local (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2D7CF9C6; Fri, 3 Jul 2020 14:39:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1593779965; bh=FIgZ7tdHmAgZPdqa+5fkin4TBMksUd11jEpciokXp24=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=glHynd/+uedE+ZX7ajHmWDOSSPugD0ImQ42InyIcIjnyXu2XY6sd9QJkGeVrXlFZA xOk9kYPSJva2P0bzh9S8Wf5Ct57d/2xbyeATJQEETKMSEhoi76T2f3GJIG/hpsrbbn 1MJFBBnftb4iCBhrO12gqV7PHaWSuPR1x03dhmvc= From: Kieran Bingham To: libcamera devel Date: Fri, 3 Jul 2020 13:39:15 +0100 Message-Id: <20200703123919.2223048-5-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200703123919.2223048-1-kieran.bingham@ideasonboard.com> References: <20200703123919.2223048-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/8] android: camera_device: Simplify FrameBuffer construction from a buffer_handle_t 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" Move the code which constructs a FrameBuffer from the Android buffer handle to it's own function to simplify the code flow and readability. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Jacopo Mondi --- src/android/camera_device.cpp | 35 +++++++++++++++++++---------------- src/android/camera_device.h | 1 + 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 03dcdd520794..73cfab532cf5 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1011,6 +1011,24 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return 0; } +FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer) +{ + std::vector planes; + for (unsigned int i = 0; i < 3; i++) { + FrameBuffer::Plane plane; + plane.fd = FileDescriptor(camera3buffer->data[i]); + /* + * Setting length to zero here is OK as the length is only used + * to map the memory of the plane. Libcamera do not need to poke + * at the memory content queued by the HAL. + */ + plane.length = 0; + planes.push_back(std::move(plane)); + } + + return new FrameBuffer(std::move(planes)); +} + int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) { StreamConfiguration *streamConfiguration = &config_->at(0); @@ -1064,22 +1082,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * Create a libcamera buffer using the dmabuf descriptors of the first * and (currently) only supported request buffer. */ - const buffer_handle_t camera3Handle = *camera3Buffers[0].buffer; - - std::vector planes; - for (int i = 0; i < 3; i++) { - FrameBuffer::Plane plane; - plane.fd = FileDescriptor(camera3Handle->data[i]); - /* - * Setting length to zero here is OK as the length is only used - * to map the memory of the plane. Libcamera do not need to poke - * at the memory content queued by the HAL. - */ - plane.length = 0; - planes.push_back(std::move(plane)); - } - - FrameBuffer *buffer = new FrameBuffer(std::move(planes)); + FrameBuffer *buffer = createFrameBuffer(*camera3Buffers[0].buffer); if (!buffer) { LOG(HAL, Error) << "Failed to create buffer"; delete descriptor; diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 5bd6cf416156..d7834d94f439 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -70,6 +70,7 @@ private: int initializeStreamConfigurations(); std::tuple calculateStaticMetadataSize(); + libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer); void notifyShutter(uint32_t frameNumber, uint64_t timestamp); void notifyError(uint32_t frameNumber, camera3_stream_t *stream); libcamera::PixelFormat toPixelFormat(int format);