{"id":16068,"url":"https://patchwork.libcamera.org/api/1.1/patches/16068/?format=json","web_url":"https://patchwork.libcamera.org/patch/16068/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220527093440.953377-4-paul.elder@ideasonboard.com>","date":"2022-05-27T09:34:38","name":"[libcamera-devel,v2,3/5] android: camera_device: Postpone mapped streams handling","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"96e64d6641127617c01f1fac0f5e6487b21b7f89","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/1.1/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16068/mbox/","series":[{"id":3145,"url":"https://patchwork.libcamera.org/api/1.1/series/3145/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3145","date":"2022-05-27T09:34:35","name":"Plumb the YUV processor in","version":2,"mbox":"https://patchwork.libcamera.org/series/3145/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16068/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16068/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id BA5A9BD161\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 May 2022 09:35:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6D5DA65634;\n\tFri, 27 May 2022 11:35:00 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0119F65631\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 May 2022 11:34:56 +0200 (CEST)","from pyrite.rasen.tech (softbank036240126034.bbtec.net\n\t[36.240.126.34])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 664CB32A;\n\tFri, 27 May 2022 11:34:55 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1653644100;\n\tbh=ZeOGn5mw6G0hlgpBAD5YHgN1dG0X6mM4ZNfUvj8r45Q=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=WrVCVp0Tu3jkoZ+M/VCd/1y3JHGiEQhAFIOYdhijJ9w/7wE9geqttxZsyUss9jGNa\n\tQNQbjdhkTrI4PPzQnxSVvQggZPtVm7xOHwbG1YUyahQUQH4UVZofgS3E8BoWfbyzAX\n\th75jz40niOIiDtW71LEQ0fHFmsONtaQMLXs+WvTmDjpgZKQMaSeZMIiTLbD7jbqtUi\n\tA6JSeGyZJbqO7vHOfzXmA6MlN0kdos7Xow8ZUi9qHy5p3I7+0Fdc2+W38iL/Xx0j8A\n\tGWp276wL5jMtnUjxjx7U4UcN6ub/Y4jviSxFNLBqbBg6PipnQDgbMyRukTcG0H0LrS\n\tS6ecR6BZi5gPw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1653644096;\n\tbh=ZeOGn5mw6G0hlgpBAD5YHgN1dG0X6mM4ZNfUvj8r45Q=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=IrMBW7KcejgDTWp4WO5cyBF+w6NKKcW1hjRGIvEl9ewry8nA/TOZR8/NR6Kugde3U\n\t9FOrdsBRR9H/bw1AsBSLM91HWmt6q0kup1A4rGFWFhzfiZ0fA9jB4zsv2czBHH87eT\n\tOm/4qFIopM3WxspYKLxG0iyawPwo41Xrd6KMHRhY="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"IrMBW7Kc\"; dkim-atps=neutral","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 3/5] android: camera_device: Postpone\n\tmapped streams handling","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Paul Elder via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Paul Elder <paul.elder@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Jacopo Mondi <jacopo@jmondi.org>\n\nMapped streams are generated by post-processing and always require a\nsource buffer from where to process image data from.\n\nIn case a Mapped stream is requested but its source stream is not, it\nis required to allocate a buffer on the fly and add it to the\nlibcamera::Request.\n\nMake sure a source stream is available for all mapped streams, and if\nthat's not the case, add a dedicated buffer to the request for that\npurpose.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\n---\nChanges in v2:\n- cosmetic changes in code\n- fix typo in the commit message\n---\n src/android/camera_device.cpp | 80 +++++++++++++++++++++++++++++++----\n 1 file changed, 72 insertions(+), 8 deletions(-)","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 20599665..95c14f60 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -9,6 +9,7 @@\n \n #include <algorithm>\n #include <fstream>\n+#include <set>\n #include <sys/mman.h>\n #include <unistd.h>\n #include <vector>\n@@ -923,6 +924,32 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \tLOG(HAL, Debug) << \"Queueing request \" << descriptor->request_->cookie()\n \t\t\t<< \" with \" << descriptor->buffers_.size() << \" streams\";\n \n+\t/*\n+\t * Collect the CameraStream associated to each requested capture stream.\n+\t * Since requestedStreams is an std:set<>, no duplications can happen.\n+\t */\n+\tstd::set<CameraStream *> requestedStreams;\n+\tfor (const auto &[i, buffer] : utils::enumerate(descriptor->buffers_)) {\n+\t\tCameraStream *cameraStream = buffer.stream;\n+\n+\t\tswitch (cameraStream->type()) {\n+\t\tcase CameraStream::Type::Mapped:\n+\t\t\trequestedStreams.insert(cameraStream->sourceStream());\n+\t\t\tbreak;\n+\n+\t\tcase CameraStream::Type::Direct:\n+\t\tcase CameraStream::Type::Internal:\n+\t\t\trequestedStreams.insert(cameraStream);\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\t/*\n+\t * Process all the Direct and Internal streams, for which the CameraStream\n+\t * they refer to is the one that points to the right libcamera::Stream.\n+\t *\n+\t * Streams of type Mapped will be handled later.\n+\t */\n \tfor (const auto &[i, buffer] : utils::enumerate(descriptor->buffers_)) {\n \t\tCameraStream *cameraStream = buffer.stream;\n \t\tcamera3_stream_t *camera3Stream = cameraStream->camera3Stream();\n@@ -945,14 +972,6 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \n \t\tswitch (cameraStream->type()) {\n \t\tcase CameraStream::Type::Mapped:\n-\t\t\t/*\n-\t\t\t * Mapped streams don't need buffers added to the\n-\t\t\t * Request.\n-\t\t\t */\n-\t\t\tLOG(HAL, Debug) << ss.str() << \" (mapped)\";\n-\n-\t\t\tdescriptor->pendingStreamsToProcess_.insert(\n-\t\t\t\t{ cameraStream, &buffer });\n \t\t\tcontinue;\n \n \t\tcase CameraStream::Type::Direct:\n@@ -996,6 +1015,51 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \t\tauto fence = std::make_unique<Fence>(std::move(acquireFence));\n \t\tdescriptor->request_->addBuffer(cameraStream->stream(),\n \t\t\t\t\t\tframeBuffer, std::move(fence));\n+\n+\t\trequestedStreams.erase(cameraStream);\n+\t}\n+\n+\t/*\n+\t * Now handle the Mapped streams. If no buffer has been added for them\n+\t * as their corresponding direct source stream has not been requested,\n+\t * add it here.\n+\t */\n+\tfor (const auto &[i, buffer] : utils::enumerate(descriptor->buffers_)) {\n+\t\tCameraStream *cameraStream = buffer.stream;\n+\t\tcamera3_stream_t *camera3Stream = cameraStream->camera3Stream();\n+\n+\t\tif (cameraStream->type() != CameraStream::Type::Mapped)\n+\t\t\tcontinue;\n+\n+\t\tLOG(HAL, Debug) << i << \" - (\" << camera3Stream->width << \"x\"\n+\t\t\t\t<< camera3Stream->height << \")\"\n+\t\t\t\t<< \"[\" << utils::hex(camera3Stream->format) << \"] -> \"\n+\t\t\t\t<< \"(\" << cameraStream->configuration().size.toString() << \")[\"\n+\t\t\t\t<< cameraStream->configuration().pixelFormat.toString() << \"]\"\n+\t\t\t\t<< \" (mapped)\";\n+\n+\t\tMutexLocker lock(descriptor->streamsProcessMutex_);\n+\t\tdescriptor->pendingStreamsToProcess_.insert({ cameraStream, &buffer });\n+\n+\t\t/*\n+\t\t * Make sure the CameraStream this stream is mapped on has been\n+\t\t * added to the request.\n+\t\t */\n+\t\tCameraStream *sourceStream = cameraStream->sourceStream();\n+\t\tif (requestedStreams.find(sourceStream) == requestedStreams.end())\n+\t\t\tcontinue;\n+\n+\t\t/*\n+\t\t * If that's not the case, we need to add a buffer to the request\n+\t\t * for this stream.\n+\t\t */\n+\t\tFrameBuffer *frameBuffer = cameraStream->getBuffer();\n+\t\tbuffer.internalBuffer = frameBuffer;\n+\n+\t\tdescriptor->request_->addBuffer(sourceStream->stream(),\n+\t\t\t\t\t\tframeBuffer, nullptr);\n+\n+\t\trequestedStreams.erase(sourceStream);\n \t}\n \n \t/*\n","prefixes":["libcamera-devel","v2","3/5"]}