From patchwork Sat Jun 4 09:30:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 16153 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 2DFFCC3275 for ; Sat, 4 Jun 2022 09:30:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7DACF65641; Sat, 4 Jun 2022 11:30:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1654335038; bh=5IqrAb2t3Vlkmylr4NzqDn4geSsuBec+eiAZ/HiObao=; 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=xeaAUck4f+n+ubPHPyXmuzQO3qvgLlkyMrQEVYuVjudPTGWDugnGc6diBdiSfS8me ou2N4zq1V2vknjzvzT9wykMhuP2G0FOefOX35agtOeB+A39tTmNl4TDAyuE1q/wlFC IgAY998IutEUYuyfp7t2OWgVZYQib1WsdGlxzlpyQ1mUzMXv1mjXEliNdgCtDLekAO IausBXsbX1/jOSOW1oJYhzkpjiudxx346x9JqdabRAVRSQyDj8wOJuEYTwL6mmjNYQ l5q5bNfW1OvpJe0kBzqrW/OlUM+qB1EnUav7YO40ztFTsFCQ9HMrBJ/Yz1vehzNf+v l0ab6YkB591ZQ== Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 27F7465634 for ; Sat, 4 Jun 2022 11:30:37 +0200 (CEST) Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id 1C177E0007; Sat, 4 Jun 2022 09:30:35 +0000 (UTC) To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Jun 2022 11:30:24 +0200 Message-Id: <20220604093025.77737-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220604093025.77737-1-jacopo@jmondi.org> References: <20220604093025.77737-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/5] android: camera_device: Use YUV post-processor 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: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Hirokazu Honda When creating the list of StreamConfiguration to be requested to the camera, map NV12 streams of equal size and format together, so that they will be generated by using the YUV post-processor. Signed-off-by: Hirokazu Honda Signed-off-by: Jacopo Mondi Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index bfe61cf715c8..0be6114e3c2c 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -605,14 +605,40 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) continue; } + /* + * While gralloc usage flags are supposed to report usage + * patterns to select a suitable buffer allocation strategy, in + * practice they're also used to make other decisions, such as + * selecting the actual format for the IMPLEMENTATION_DEFINED + * HAL pixel format. To avoid issues, we thus have to set the + * GRALLOC_USAGE_HW_CAMERA_WRITE flag unconditionally, even for + * streams that will be produced in software. + */ + stream->usage |= GRALLOC_USAGE_HW_CAMERA_WRITE; + + /* + * If a CameraStream with the same size and format as the + * current stream has already been requested, associate the two. + */ + auto iter = std::find_if( + streamConfigs.begin(), streamConfigs.end(), + [&size, &format](const Camera3StreamConfig &streamConfig) { + return streamConfig.config.size == size && + streamConfig.config.pixelFormat == format; + }); + if (iter != streamConfigs.end()) { + /* Add usage to copy the buffer in streams[0] to stream. */ + iter->streams[0].stream->usage |= GRALLOC_USAGE_SW_READ_OFTEN; + stream->usage |= GRALLOC_USAGE_SW_WRITE_OFTEN; + iter->streams.push_back({ stream, CameraStream::Type::Mapped }); + continue; + } + Camera3StreamConfig streamConfig; streamConfig.streams = { { stream, CameraStream::Type::Direct } }; streamConfig.config.size = size; streamConfig.config.pixelFormat = format; streamConfigs.push_back(std::move(streamConfig)); - - /* This stream will be produced by hardware. */ - stream->usage |= GRALLOC_USAGE_HW_CAMERA_WRITE; } /* Now handle the MJPEG streams, adding a new stream if required. */