From patchwork Tue Jul 21 22:01:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 8915 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 1CC23C2E68 for ; Tue, 21 Jul 2020 22:01:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E20D160998; Wed, 22 Jul 2020 00:01:38 +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="nzOYwopN"; 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 61D7760987 for ; Wed, 22 Jul 2020 00:01:33 +0200 (CEST) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E4D521414; Wed, 22 Jul 2020 00:01:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1595368893; bh=eW+PNbRr/LnRbFeT+LVAIiVoD7/UNRFIwYJMGKGYfKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nzOYwopN2QoeKr64kP1TE/94KLP+NRxscTBKY75s/Axqvf59m6ntKwEVr0iuzHlly E1u+s1zYrMMlpL2lEFPF2650SKzQ5TuUyvshxTOJEZ8tBT+8JlXEGVohVegGfH9RD7 /sw6TNueF/so/pF9t+RYTMjzi7dtsp6DUTY/M9O8= From: Kieran Bingham To: libcamera devel Date: Tue, 21 Jul 2020 23:01:26 +0100 Message-Id: <20200721220126.202065-7-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200721220126.202065-1-kieran.bingham@ideasonboard.com> References: <20200721220126.202065-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 6/6] android: camera_device: Provide a MappedCamera3Buffer 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" Utilise the MappedBuffer interface to map each of the planes provided in the Camera3 buffer to facilitate use in software streams. The buffers will be automatically unmapped when the object goes out of scope or is deleted. Signed-off-by: Kieran Bingham --- This shows how the MappedCamera3Buffer which was posted as part of the MappedBuffer series can get used. Originally my aim was to pass a MappedBuffer in place of creating a CompressedImage object, but passing in a MappedBuffer alone restricts passing back how many bytes were consumed, and I expect other meta-data might be needed, so I anticipate needing more than just a function return value soon. (i.e. so I don't yet think I can just return the compressed image size in the return value, but maybe it might end up being possible/cleaner to do that...) src/android/camera_device.cpp | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 23dde1cfaf98..34c60556e5fa 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1281,30 +1281,6 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques return 0; } -static CompressedImage mapAndroidBlobBuffer(const buffer_handle_t camera3buffer) -{ - CompressedImage img; - - /* ANDROID_JPEG_MAX_SIZE */ - unsigned int length = int32_t{13 << 20}; - - /* Take only the first plane */ - void *memory = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, - camera3buffer->data[0], 0); - - img.length = length; - img.data = static_cast(memory); - - return img; -} - -static void unmapAndroidBlobBuffer(CompressedImage *img) -{ - munmap(img->data, img->length); - img->data = nullptr; - img->length = 0; -} - void CameraDevice::requestComplete(Request *request) { const std::map &buffers = request->buffers(); @@ -1341,19 +1317,22 @@ void CameraDevice::requestComplete(Request *request) continue; } - CompressedImage output = mapAndroidBlobBuffer(*descriptor->buffers[i].buffer); - if (output.data == MAP_FAILED) { - LOG(HAL, Error) << "Failed to mmap android blob buffer of length " << output.length; + MappedCamera3Buffer mapped(*descriptor->buffers[i].buffer, PROT_READ|PROT_WRITE); + if (!mapped.isValid()) { + LOG(HAL, Error) << "Failed to mmap android blob buffer"; continue; } + CompressedImage output; + output.data = static_cast(mapped.maps()[0].address); + output.length = mapped.maps()[0].length; + int ret = compressor->compress(buffer, &output); if (ret) { LOG(HAL, Error) << "Failed to compress stream image"; status = CAMERA3_BUFFER_STATUS_ERROR; } - unmapAndroidBlobBuffer(&output); } /* Prepare to call back the Android camera stack. */