[{"id":19872,"web_url":"https://patchwork.libcamera.org/comment/19872/","msgid":"<CAO5uPHNC8w1b3aC0WdJytBbcGiZHtW+hWxmgh+uVvz2Awj43RQ@mail.gmail.com>","date":"2021-09-27T11:09:24","subject":"Re: [libcamera-devel] [PATCH 2/2] android: Post-pone fences reset\n\tin result","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"content":"Hi Jacopo,\n\nOn Sat, Sep 25, 2021 at 2:01 AM Jacopo Mondi <jacopo@jmondi.org> wrote:\n>\n> When a request has been completed and a new capture_result is created\n> to be sent to the framework through the process_capture_result()\n> callback we assumed all fences had been waited on, hence we set both\n> the release and acquisition fences to -1.\n>\n> Now that the acquisition fence of streams generated through\n> post-processing are handled by CameraStream::process(), resetting fences\n> too early would invalidate them before they get handled.\n>\n> Post-pone setting fences to -1 for successful capture results, and\n> correct the release_fence handling for failed captures, as the framework\n> requires the release fences to be set to the acquire fence value if the\n> acquire fence has not been waited on.\n>\n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThe change looks good.\nReviewed-by: Hirokazu Honda <hiroh@chromium.org>\n\nBut I think the patch order should be reversed. Otherwise, a passed\nacquire_fence in CameraStream::process() is always -1.\n\n-Hiro\n> ---\n>  src/android/camera_device.cpp | 44 ++++++++++++++++++++++++-----------\n>  1 file changed, 31 insertions(+), 13 deletions(-)\n>\n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index db35947afc2f..8ca2353e5f33 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -1098,22 +1098,10 @@ void CameraDevice::requestComplete(Request *request)\n>         }\n>         Camera3RequestDescriptor &descriptor = node.mapped();\n>\n> -       /*\n> -        * Prepare the capture result for the Android camera stack.\n> -        *\n> -        * The buffer status is set to OK and later changed to ERROR if\n> -        * post-processing/compression fails.\n> -        */\n>         camera3_capture_result_t captureResult = {};\n>         captureResult.frame_number = descriptor.frameNumber_;\n>         captureResult.num_output_buffers = descriptor.buffers_.size();\n> -       for (camera3_stream_buffer_t &buffer : descriptor.buffers_) {\n> -               buffer.acquire_fence = -1;\n> -               buffer.release_fence = -1;\n> -               buffer.status = CAMERA3_BUFFER_STATUS_OK;\n> -       }\n>         captureResult.output_buffers = descriptor.buffers_.data();\n> -       captureResult.partial_result = 1;\n>\n>         /*\n>          * If the Request has failed, abort the request by notifying the error\n> @@ -1128,8 +1116,27 @@ void CameraDevice::requestComplete(Request *request)\n>                             CAMERA3_MSG_ERROR_REQUEST);\n>\n>                 captureResult.partial_result = 0;\n> -               for (camera3_stream_buffer_t &buffer : descriptor.buffers_)\n> +               for (camera3_stream_buffer_t &buffer : descriptor.buffers_) {\n> +                       CameraStream *cameraStream =\n> +                               static_cast<CameraStream *>(buffer.stream->priv);\n> +\n> +                       /*\n> +                        * Streams of type Direct have been queued to the\n> +                        * libcamera::Camera and their acquisition fences has\n> +                        * already been waited on by the CameraWorker.\n> +                        *\n> +                        * For other stream types signal to the framework the\n> +                        * acquisition fence has not been waited on, by setting\n> +                        * the release fence to its value.\n> +                        */\n> +                       if (cameraStream->type() == CameraStream::Type::Direct)\n> +                               buffer.release_fence = -1;\n> +                       else\n> +                               buffer.release_fence = buffer.acquire_fence;\n> +\n> +                       buffer.acquire_fence = -1;\n>                         buffer.status = CAMERA3_BUFFER_STATUS_ERROR;\n> +               }\n>                 callbacks_->process_capture_result(callbacks_, &captureResult);\n>\n>                 return;\n> @@ -1196,6 +1203,17 @@ void CameraDevice::requestComplete(Request *request)\n>                 }\n>         }\n>\n> +       /*\n> +        * Finalize the capture result by setting fences and buffer status\n> +        * before executing the callback.\n> +        */\n> +       for (camera3_stream_buffer_t &buffer : descriptor.buffers_) {\n> +               buffer.acquire_fence = -1;\n> +               buffer.release_fence = -1;\n> +               buffer.status = CAMERA3_BUFFER_STATUS_OK;\n> +       }\n> +       captureResult.partial_result = 1;\n> +\n>         captureResult.result = resultMetadata->get();\n>         callbacks_->process_capture_result(callbacks_, &captureResult);\n>  }\n> --\n> 2.32.0\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 592F5C3243\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Sep 2021 11:09:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A5C896918D;\n\tMon, 27 Sep 2021 13:09:36 +0200 (CEST)","from mail-ed1-x534.google.com (mail-ed1-x534.google.com\n\t[IPv6:2a00:1450:4864:20::534])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EBC5C69189\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Sep 2021 13:09:34 +0200 (CEST)","by mail-ed1-x534.google.com with SMTP id x7so53005037edd.6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Sep 2021 04:09:34 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"SThdlvQZ\"; 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=wCfsDPxBFpn2bgNXADrOLBPwMJUHC3i5ALOEZM7pmpY=;\n\tb=SThdlvQZ3ebW2h8BJl3lW8Qsj5Hj75gYQmxkgcXVb0JFCc07Jba1TpY37HnygxpG0W\n\tzof+cy2dI6ZzbtLnYOkSHHQuZPQubM5Ca1oK3/vRoMy38zqHaPn7p9EbvE1OOcbXW111\n\tJBTbPCTn2C99k+8LTPbe2AnzFcQBXvzWe/Q2k=","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=wCfsDPxBFpn2bgNXADrOLBPwMJUHC3i5ALOEZM7pmpY=;\n\tb=VlSycLB6T2fp6hbpO8CsRtAgrWv1cgJ13gJwPSiKU6WYYCLXw4R6ONffp6RpJKVp7w\n\taMZ78hwMvt0aMXhcMAJwdv8OHK3Qid+AtMMmGxVv8hGkwKstbVH2ZONuiDwgkD9klI1m\n\tZrhWRFJiqiMVQ3C9zZgDr19agvpD//5+TVEql1JzmQ/8tSCFd8KDko3sEJtTaFrKMMXM\n\tEXzfnns8ZTSxxu/SFc2pUlMhJS7k3/ou15XZLo0AKA+djZVJ2mwBljyEDch0bqiRuKrT\n\t9oeE3WDh41QltqdVuVVt2FmfFrgVFRwMNfrS6mztTZ1YJJPEKrWro1VZTM7SC4QizEmr\n\te9XQ==","X-Gm-Message-State":"AOAM532O4N8GHnartcUu9DzzaWQZnFCmd0moBtebxFKCckuNetbRrZi4\n\tVtDf8E4kZo3lRrvfXQOGLoTT2TR+7xBGl7mQv5h8yA==","X-Google-Smtp-Source":"ABdhPJyrfMWyLj9lfdOeomVl5ISWLW6247Zu2FwwdLW6l4bTFPY2nd82ijsZzmNtponDfzkr+ZVfl9AlSk4BgHLrPkM=","X-Received":"by 2002:a50:d80d:: with SMTP id\n\to13mr22676035edj.204.1632740974541; \n\tMon, 27 Sep 2021 04:09:34 -0700 (PDT)","MIME-Version":"1.0","References":"<20210924170234.152783-1-jacopo@jmondi.org>\n\t<20210924170234.152783-3-jacopo@jmondi.org>","In-Reply-To":"<20210924170234.152783-3-jacopo@jmondi.org>","From":"Hirokazu Honda <hiroh@chromium.org>","Date":"Mon, 27 Sep 2021 20:09:24 +0900","Message-ID":"<CAO5uPHNC8w1b3aC0WdJytBbcGiZHtW+hWxmgh+uVvz2Awj43RQ@mail.gmail.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH 2/2] android: Post-pone fences reset\n\tin result","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 <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]