{"id":16152,"url":"https://patchwork.libcamera.org/api/patches/16152/?format=json","web_url":"https://patchwork.libcamera.org/patch/16152/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20220604093025.77737-4-jacopo@jmondi.org>","date":"2022-06-04T09:30:23","name":"[libcamera-devel,v3,3/5] android: camera_device: Postpone mapped streams handling","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"2aa279237eff66bc8c31b02bb17a2f89ae166fac","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16152/mbox/","series":[{"id":3160,"url":"https://patchwork.libcamera.org/api/series/3160/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3160","date":"2022-06-04T09:30:20","name":"Plumb the YUV processor in","version":3,"mbox":"https://patchwork.libcamera.org/series/3160/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16152/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16152/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 86618C3274\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat,  4 Jun 2022 09:30:38 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0468565638;\n\tSat,  4 Jun 2022 11:30:38 +0200 (CEST)","from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[IPv6:2001:4b98:dc4:8::224])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DDBBD65631\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  4 Jun 2022 11:30:35 +0200 (CEST)","(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id 03822E0007;\n\tSat,  4 Jun 2022 09:30:34 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1654335038;\n\tbh=irjNUSvMTEto48WgeaZp6ZxqddgLlY+v/FXisawyOjU=;\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=XAdA3mm1i+HdBifaFdPG36YZKYGa+II6rgFOzGxekgcxZnDkdhju3NCmwOVhi6j2r\n\tEs+WqDOd3ZAHfcCyH3l3B48WbSk9DdEKK50xHiZ+BnZ6RuKgfWukhdth7kd31xREC1\n\t/K/MMK8zmXEFDUgkTUNzcwdyVCR6i6ss5S6nc5MCBRBdrwfqqj3JDW6IHWIHiEMCYz\n\tnJ1fVeBe6pXKTy1cntyXORUEUtBwmu/GLs3EVNWn+vWL6UDkMwF+ZfnuopdmzXU7MX\n\tHR2vi1VUjP4VKIHn5a1VXLAMPmzJbKKy9XrvIvmQVaTvqdgLC09HJUOemnLWzSX1LC\n\tgAAmqWf4vpDog==","To":"libcamera-devel@lists.libcamera.org","Date":"Sat,  4 Jun 2022 11:30:23 +0200","Message-Id":"<20220604093025.77737-4-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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 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":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo@jmondi.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Mapped streams are generated by post-processing and always require a\nsource buffer 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>\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/android/camera_device.cpp | 63 ++++++++++++++++++++++++++++++-----\n 1 file changed, 55 insertions(+), 8 deletions(-)\n\n--\n2.35.1","diff":"diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 773cb3b66d48..bfe61cf715c8 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@@ -930,6 +931,14 @@ 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 * Process all the Direct and Internal streams first, they map directly\n+\t * to a libcamera stream. Streams of type Mapped will be handled later.\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 \t\tcamera3_stream_t *camera3Stream = cameraStream->camera3Stream();\n@@ -952,14 +961,7 @@ 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\t/* Mapped streams will be handled in the next loop. */\n \t\t\tcontinue;\n\n \t\tcase CameraStream::Type::Direct:\n@@ -1003,6 +1005,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.insert(cameraStream);\n+\t}\n+\n+\t/*\n+\t * Now handle the Mapped streams. If no buffer has been added for them\n+\t * because their corresponding direct source stream is not part of this\n+\t * particular request, add one 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 << \")[\"\n+\t\t\t\t<< cameraStream->configuration().pixelFormat << \"]\"\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","v3","3/5"]}