[{"id":22014,"web_url":"https://patchwork.libcamera.org/comment/22014/","msgid":"<CAO5uPHN1TFG=AUHHt-Ovd998uW8bdA3=qKKq2erS7s0vOwBUmA@mail.gmail.com>","date":"2022-01-12T07:31:42","subject":"Re: [libcamera-devel] [PATCH 3/5] android: camera_device: Post-pone\n\tmapped streams handling","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"content":"Hi Jacopo,\n\n\nOn Tue, Jan 11, 2022 at 1:54 AM Jacopo Mondi <jacopo@jmondi.org> wrote:\n>\n> Mapped streams are generated by post-processing and always require a\n> source buffer from where to process image data from.\n>\n> In case a Mapped stream is requested but its source stream is not, it\n> is required to allocate a buffer on the fly and add it to the\n> libcamera::Request.\n>\n> Make sure a source stream is available for all mapped streams, and if\n> that's not the case, add a dedicated buffer to the request for that\n> purpose.\n>\n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/android/camera_device.cpp | 81 +++++++++++++++++++++++++++++++----\n>  1 file changed, 73 insertions(+), 8 deletions(-)\n>\n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index 005d95b51a0c..a44f199d25d8 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> @@ -924,6 +925,32 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n>         LOG(HAL, Debug) << \"Queueing request \" << descriptor->request_->cookie()\n>                         << \" with \" << descriptor->buffers_.size() << \" streams\";\n>\n> +       /*\n> +        * Collect the CameraStream associated to each requested capture stream.\n> +        * Being requestedStreams an std::set<> no duplications can happen.\n> +        */\n> +       std::set<CameraStream *> requestedStreams;\n> +       for (const auto &[i, buffer] : utils::enumerate(descriptor->buffers_)) {\n> +               CameraStream *cameraStream = buffer.stream;\n> +\n> +               switch (cameraStream->type()) {\n> +               case CameraStream::Type::Mapped:\n> +                       requestedStreams.insert(cameraStream->sourceStream());\n> +                       break;\n> +\n> +               case CameraStream::Type::Direct:\n> +               case CameraStream::Type::Internal:\n> +                       requestedStreams.insert(cameraStream);\n> +                       break;\n> +               }\n> +       }\n> +\n> +       /*\n> +        * Process all the Direct and Internal streams, for which the CameraStream\n> +        * they refer to is the one that points to the right libcamera::Stream.\n> +        *\n> +        * Streams of type Mapped will be handled later.\n> +        */\n>         for (const auto &[i, buffer] : utils::enumerate(descriptor->buffers_)) {\n>                 CameraStream *cameraStream = buffer.stream;\n>                 camera3_stream_t *camera3Stream = cameraStream->camera3Stream();\n> @@ -946,14 +973,6 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n>\n>                 switch (cameraStream->type()) {\n>                 case CameraStream::Type::Mapped:\n> -                       /*\n> -                        * Mapped streams don't need buffers added to the\n> -                        * Request.\n> -                        */\n> -                       LOG(HAL, Debug) << ss.str() << \" (mapped)\";\n> -\n> -                       descriptor->pendingStreamsToProcess_.insert(\n> -                               { cameraStream, &buffer });\n>                         continue;\n>\n>                 case CameraStream::Type::Direct:\n> @@ -997,6 +1016,52 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n>                 auto fence = std::make_unique<Fence>(std::move(acquireFence));\n>                 descriptor->request_->addBuffer(cameraStream->stream(),\n>                                                 frameBuffer, std::move(fence));\n> +\n> +               requestedStreams.erase(cameraStream);\n> +       }\n> +\n> +       /*\n> +        * Now handle the mapped streams. If no buffer has been addded for them\n\nnit: the Mapped streams\ns/added/addded/\n\n> +        * as their corresponding direct source stream has not been requested,\n> +        * add it here.\n> +        */\n> +       for (const auto &[i, buffer] : utils::enumerate(descriptor->buffers_)) {\n> +               CameraStream *cameraStream = buffer.stream;\n> +               camera3_stream_t *camera3Stream = cameraStream->camera3Stream();\n> +               CameraStream *sourceStream = cameraStream->sourceStream();\n> +               FrameBuffer *frameBuffer = nullptr;\n> +\n> +               if (cameraStream->type() != CameraStream::Type::Mapped)\n> +                       continue;\n\nI would move camera3Stream here.\n\n> +\n> +               LOG(HAL, Debug) << i << \" - (\" << camera3Stream->width << \"x\"\n> +                               << camera3Stream->height << \")\"\n> +                               << \"[\" << utils::hex(camera3Stream->format) << \"] -> \"\n> +                               << \"(\" << cameraStream->configuration().size.toString() << \")[\"\n> +                               << cameraStream->configuration().pixelFormat.toString() << \"]\"\n> +                               << \" (mapped)\";\n> +\n> +               MutexLocker lock(descriptor->streamsProcessMutex_);\n> +               descriptor->pendingStreamsToProcess_.insert({ cameraStream, &buffer });\n> +\n\nI move sourceStrfeam here.\n\n> +               /*\n> +                * Make sure the CameraStream this stream is mapped on has been\n> +                * added to the request.\n> +                */\n> +               if (requestedStreams.find(sourceStream) == requestedStreams.end())\n> +                       continue;\n> +\n> +               /*\n> +                * If that's not the case, we need to add a buffer to the request\n> +                * for this stream.\n> +                */\n> +               frameBuffer = cameraStream->getBuffer();\nnit: FrameBuffer *frameBuffer =\n\n> +               buffer.internalBuffer = frameBuffer;\n> +\n> +               descriptor->request_->addBuffer(sourceStream->stream(),\n> +                                               frameBuffer, nullptr);\n> +\n> +               requestedStreams.erase(sourceStream);\n>         }\n\nShall we check requestedStreams is empty?\n\nBest Regards,\n-Hiro\n>\n>         /*\n> --\n> 2.34.1\n>","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 E0687BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 12 Jan 2022 07:31:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4491A60921;\n\tWed, 12 Jan 2022 08:31:55 +0100 (CET)","from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com\n\t[IPv6:2a00:1450:4864:20::52c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E832460217\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 12 Jan 2022 08:31:53 +0100 (CET)","by mail-ed1-x52c.google.com with SMTP id b13so6455559edn.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 11 Jan 2022 23:31:53 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"Mt5ddlVT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=ByjusCAYC6IQlZmb4/XZ0/b0ZTgw7+2C7jb4Pr/F0Cw=;\n\tb=Mt5ddlVTxatfWmPyH54F6rNmKqBjbX3ZPBPT0lCCxN24vsp6aImSpschmlBWjHNIut\n\t/ApAjC86fRPPMcXgfFQc7xrW+069ecK40sJuuWsc/bTrAp2PcydEPEH12O9VO8esMjdK\n\t3JuQbQjFgKg5xix/R96Q14ab/ekyVOnjWhQIc=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=ByjusCAYC6IQlZmb4/XZ0/b0ZTgw7+2C7jb4Pr/F0Cw=;\n\tb=KLcNqb0YhRgh92SL244SkKYbqTw3R6+wFVhSB6npHywNnsJxceyrl4tmDygyQ5J9Bj\n\twALtsfZ43u+k7UMPE/e+c1Ebow5SSfKSVvOg49fNP33UYEfiyy69l5fxBlXAsGdZ7BAC\n\tZO2JYX+mCsj90ohVr+kxji2GsbtX8z1eiv90HS6VoNUOi9myHR+E0ryZJjq+dCLKfvfm\n\tQvHLlL/qY435lqTnjicolfNH72CH3zH4ulLUfurVaho3KSszRCfop00fCwIg51KgdMfj\n\t13V4x4V6E6y+1zMmBv2j0GUi/bbInGBffEkS7tr2bfQrsYL1Fsbmh8sdQzCSyQplRCd5\n\tq+Ow==","X-Gm-Message-State":"AOAM532KRKhL9r1ZpC87i0nSuZbgvg8TdjI7huyAtesax94cap1qk7ng\n\t4Nm9WgoTVictPO97oUu5ajxvkAZwSpGdP8fqPd4pqQ==","X-Google-Smtp-Source":"ABdhPJwe5e6q6ZMHosm6PW0i+XxEA3mc52BwnCg1rW0CaXgUIPgEFUAc1NqQACWomrubJ6vwmV4X6myljjx5Ap1NTsg=","X-Received":"by 2002:aa7:dd56:: with SMTP id o22mr8031876edw.73.1641972713301;\n\tTue, 11 Jan 2022 23:31:53 -0800 (PST)","MIME-Version":"1.0","References":"<20220110165524.72978-1-jacopo@jmondi.org>\n\t<20220110165524.72978-4-jacopo@jmondi.org>","In-Reply-To":"<20220110165524.72978-4-jacopo@jmondi.org>","From":"Hirokazu Honda <hiroh@chromium.org>","Date":"Wed, 12 Jan 2022 16:31:42 +0900","Message-ID":"<CAO5uPHN1TFG=AUHHt-Ovd998uW8bdA3=qKKq2erS7s0vOwBUmA@mail.gmail.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH 3/5] android: camera_device: Post-pone\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>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]