From patchwork Fri May 27 09:34:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 16068 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 BA5A9BD161 for ; Fri, 27 May 2022 09:35:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6D5DA65634; Fri, 27 May 2022 11:35:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653644100; bh=ZeOGn5mw6G0hlgpBAD5YHgN1dG0X6mM4ZNfUvj8r45Q=; 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=WrVCVp0Tu3jkoZ+M/VCd/1y3JHGiEQhAFIOYdhijJ9w/7wE9geqttxZsyUss9jGNa QNQbjdhkTrI4PPzQnxSVvQggZPtVm7xOHwbG1YUyahQUQH4UVZofgS3E8BoWfbyzAX h75jz40niOIiDtW71LEQ0fHFmsONtaQMLXs+WvTmDjpgZKQMaSeZMIiTLbD7jbqtUi A6JSeGyZJbqO7vHOfzXmA6MlN0kdos7Xow8ZUi9qHy5p3I7+0Fdc2+W38iL/Xx0j8A GWp276wL5jMtnUjxjx7U4UcN6ub/Y4jviSxFNLBqbBg6PipnQDgbMyRukTcG0H0LrS S6ecR6BZi5gPw== 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 0119F65631 for ; Fri, 27 May 2022 11:34:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="IrMBW7Kc"; dkim-atps=neutral Received: from pyrite.rasen.tech (softbank036240126034.bbtec.net [36.240.126.34]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 664CB32A; Fri, 27 May 2022 11:34:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653644096; bh=ZeOGn5mw6G0hlgpBAD5YHgN1dG0X6mM4ZNfUvj8r45Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IrMBW7KcejgDTWp4WO5cyBF+w6NKKcW1hjRGIvEl9ewry8nA/TOZR8/NR6Kugde3U 9FOrdsBRR9H/bw1AsBSLM91HWmt6q0kup1A4rGFWFhzfiZ0fA9jB4zsv2czBHH87eT Om/4qFIopM3WxspYKLxG0iyawPwo41Xrd6KMHRhY= To: libcamera-devel@lists.libcamera.org Date: Fri, 27 May 2022 18:34:38 +0900 Message-Id: <20220527093440.953377-4-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220527093440.953377-1-paul.elder@ideasonboard.com> References: <20220527093440.953377-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/5] android: camera_device: Postpone mapped streams handling 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: Paul Elder via libcamera-devel From: Paul Elder Reply-To: Paul Elder Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Jacopo Mondi Mapped streams are generated by post-processing and always require a source buffer from where to process image data from. In case a Mapped stream is requested but its source stream is not, it is required to allocate a buffer on the fly and add it to the libcamera::Request. Make sure a source stream is available for all mapped streams, and if that's not the case, add a dedicated buffer to the request for that purpose. Signed-off-by: Jacopo Mondi Signed-off-by: Paul Elder Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- Changes in v2: - cosmetic changes in code - fix typo in the commit message --- src/android/camera_device.cpp | 80 +++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 20599665..95c14f60 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -923,6 +924,32 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques LOG(HAL, Debug) << "Queueing request " << descriptor->request_->cookie() << " with " << descriptor->buffers_.size() << " streams"; + /* + * Collect the CameraStream associated to each requested capture stream. + * Since requestedStreams is an std:set<>, no duplications can happen. + */ + std::set requestedStreams; + for (const auto &[i, buffer] : utils::enumerate(descriptor->buffers_)) { + CameraStream *cameraStream = buffer.stream; + + switch (cameraStream->type()) { + case CameraStream::Type::Mapped: + requestedStreams.insert(cameraStream->sourceStream()); + break; + + case CameraStream::Type::Direct: + case CameraStream::Type::Internal: + requestedStreams.insert(cameraStream); + break; + } + } + + /* + * Process all the Direct and Internal streams, for which the CameraStream + * they refer to is the one that points to the right libcamera::Stream. + * + * Streams of type Mapped will be handled later. + */ for (const auto &[i, buffer] : utils::enumerate(descriptor->buffers_)) { CameraStream *cameraStream = buffer.stream; camera3_stream_t *camera3Stream = cameraStream->camera3Stream(); @@ -945,14 +972,6 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques switch (cameraStream->type()) { case CameraStream::Type::Mapped: - /* - * Mapped streams don't need buffers added to the - * Request. - */ - LOG(HAL, Debug) << ss.str() << " (mapped)"; - - descriptor->pendingStreamsToProcess_.insert( - { cameraStream, &buffer }); continue; case CameraStream::Type::Direct: @@ -996,6 +1015,51 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques auto fence = std::make_unique(std::move(acquireFence)); descriptor->request_->addBuffer(cameraStream->stream(), frameBuffer, std::move(fence)); + + requestedStreams.erase(cameraStream); + } + + /* + * Now handle the Mapped streams. If no buffer has been added for them + * as their corresponding direct source stream has not been requested, + * add it here. + */ + for (const auto &[i, buffer] : utils::enumerate(descriptor->buffers_)) { + CameraStream *cameraStream = buffer.stream; + camera3_stream_t *camera3Stream = cameraStream->camera3Stream(); + + if (cameraStream->type() != CameraStream::Type::Mapped) + continue; + + LOG(HAL, Debug) << i << " - (" << camera3Stream->width << "x" + << camera3Stream->height << ")" + << "[" << utils::hex(camera3Stream->format) << "] -> " + << "(" << cameraStream->configuration().size.toString() << ")[" + << cameraStream->configuration().pixelFormat.toString() << "]" + << " (mapped)"; + + MutexLocker lock(descriptor->streamsProcessMutex_); + descriptor->pendingStreamsToProcess_.insert({ cameraStream, &buffer }); + + /* + * Make sure the CameraStream this stream is mapped on has been + * added to the request. + */ + CameraStream *sourceStream = cameraStream->sourceStream(); + if (requestedStreams.find(sourceStream) == requestedStreams.end()) + continue; + + /* + * If that's not the case, we need to add a buffer to the request + * for this stream. + */ + FrameBuffer *frameBuffer = cameraStream->getBuffer(); + buffer.internalBuffer = frameBuffer; + + descriptor->request_->addBuffer(sourceStream->stream(), + frameBuffer, nullptr); + + requestedStreams.erase(sourceStream); } /*