[{"id":19625,"web_url":"https://patchwork.libcamera.org/comment/19625/","msgid":"<YT6WiNqED9XJepCc@pendragon.ideasonboard.com>","date":"2021-09-13T00:08:40","subject":"Re: [libcamera-devel] [PATCH v2 4/9] android: post_processor:\n\tNotify post processing completion status","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Umang,\n\nThank you for the patch.\n\nOn Fri, Sep 10, 2021 at 12:36:33PM +0530, Umang Jain wrote:\n> We should be able to know if post-processing has been completed\n> successfully or encountered some errors. This commit introduces a\n> Signal<> which when connected, will notify that the post-processing\n\nThe signal notifies completion regardless of whether it's connected or\nnot, the same way that a tree falling in an empty forest still makes\nsound :-)\n\n> has been completed. The status of PostProcessor::process() will be\n> passed as a PostProcessor::Status argument. The signal will be required\n> when the post-processor is meant to run asynchronously (in subsequent\n> commits).\n> \n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> ---\n>  src/android/jpeg/post_processor_jpeg.cpp | 7 ++++++-\n>  src/android/post_processor.h             | 8 ++++++++\n>  src/android/yuv/post_processor_yuv.cpp   | 4 ++++\n>  3 files changed, 18 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp\n> index 741eeb21..1df3dfb1 100644\n> --- a/src/android/jpeg/post_processor_jpeg.cpp\n> +++ b/src/android/jpeg/post_processor_jpeg.cpp\n> @@ -103,8 +103,10 @@ int PostProcessorJpeg::process(const FrameBuffer *source,\n>  \t\t\t       CameraMetadata *resultMetadata,\n>  \t\t\t       const Camera3RequestDescriptor *context)\n>  {\n> -\tif (!encoder_)\n> +\tif (!encoder_) {\n> +\t\tprocessComplete.emit(PostProcessor::Status::Failed, context);\n\nAs PostProcessorJpeg inherits from PostProcessor, I think you can write\n\n\t\tprocessComplete.emit(Status::Failed, context);\n\nhere. Same below.\n\n>  \t\treturn 0;\n> +\t}\n>  \n>  \tASSERT(destination->numPlanes() == 1);\n>  \n> @@ -197,6 +199,7 @@ int PostProcessorJpeg::process(const FrameBuffer *source,\n>  \t\t\t\t\t exif.data(), quality);\n>  \tif (jpeg_size < 0) {\n>  \t\tLOG(JPEG, Error) << \"Failed to encode stream image\";\n> +\t\tprocessComplete.emit(PostProcessor::Status::Failed, context);\n>  \t\treturn jpeg_size;\n>  \t}\n>  \n> @@ -211,5 +214,7 @@ int PostProcessorJpeg::process(const FrameBuffer *source,\n>  \t/* Update the JPEG result Metadata. */\n>  \tresultMetadata->addEntry(ANDROID_JPEG_SIZE, jpeg_size);\n>  \n> +\tprocessComplete.emit(PostProcessor::Status::Succeeded, context);\n> +\n>  \treturn 0;\n>  }\n> diff --git a/src/android/post_processor.h b/src/android/post_processor.h\n> index 1213e7e6..25c9411f 100644\n> --- a/src/android/post_processor.h\n> +++ b/src/android/post_processor.h\n> @@ -7,6 +7,8 @@\n>  #ifndef __ANDROID_POST_PROCESSOR_H__\n>  #define __ANDROID_POST_PROCESSOR_H__\n>  \n> +#include <libcamera/base/signal.h>\n> +\n>  #include <libcamera/framebuffer.h>\n>  #include <libcamera/stream.h>\n>  \n> @@ -28,6 +30,12 @@ public:\n>  \t\t\t    const CameraMetadata &requestMetadata,\n>  \t\t\t    CameraMetadata *resultMetadata,\n>  \t\t\t    const Camera3RequestDescriptor *context) = 0;\n> +\n> +\tenum Status {\n> +\t\tSucceeded,\n> +\t\tFailed,\n> +\t};\n\nThis should move right after \"public\", we define types before fucntions.\n\nWe have\n\n\tenum Status {\n\t\tFrameSuccess,\n\t\tFrameError,\n\t\tFrameCancelled,\n\t};\n\nin FrameMetadata, I'd thus name the enumerators Success and Error.\n\nI'd also make this an enum class to make usage of the Status:: prefix\nmandatory, given that you already use it everywhere.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\tlibcamera::Signal<Status, const Camera3RequestDescriptor *> processComplete;\n>  };\n>  \n>  #endif /* __ANDROID_POST_PROCESSOR_H__ */\n> diff --git a/src/android/yuv/post_processor_yuv.cpp b/src/android/yuv/post_processor_yuv.cpp\n> index 13a78abe..d2df110a 100644\n> --- a/src/android/yuv/post_processor_yuv.cpp\n> +++ b/src/android/yuv/post_processor_yuv.cpp\n> @@ -61,6 +61,7 @@ int PostProcessorYuv::process(const FrameBuffer *source,\n>  \tconst MappedFrameBuffer sourceMapped(source, MappedFrameBuffer::MapFlag::Read);\n>  \tif (!sourceMapped.isValid()) {\n>  \t\tLOG(YUV, Error) << \"Failed to mmap camera frame buffer\";\n> +\t\tprocessComplete.emit(PostProcessor::Status::Failed, context);\n>  \t\treturn -EINVAL;\n>  \t}\n>  \n> @@ -78,9 +79,12 @@ int PostProcessorYuv::process(const FrameBuffer *source,\n>  \t\t\t\t    libyuv::FilterMode::kFilterBilinear);\n>  \tif (ret) {\n>  \t\tLOG(YUV, Error) << \"Failed NV12 scaling: \" << ret;\n> +\t\tprocessComplete.emit(PostProcessor::Status::Failed, context);\n>  \t\treturn -EINVAL;\n>  \t}\n>  \n> +\tprocessComplete.emit(PostProcessor::Status::Succeeded, context);\n> +\n>  \treturn 0;\n>  }\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 84E9FBDB1D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 13 Sep 2021 00:09:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F3EB569185;\n\tMon, 13 Sep 2021 02:09:05 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2120769182\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Sep 2021 02:09:05 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 94A7D9E;\n\tMon, 13 Sep 2021 02:09:04 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"NEuVR1kg\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1631491744;\n\tbh=i4YCppcl710b6TFE3tKxVtqF91y5OFM4Dkc7tTuHpcM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=NEuVR1kg2iE8gFonxabqSrahDb/lUqHjorMYQ8xJ2LXSqUx8sJtVUzf1z4Eby5YqT\n\t3LYV4JX1Qis25ImlBRBCXYelaIg4O5yavMW1vaQCgg/UlOq2ocULOn59wmgNnaj2pt\n\tQQM5MXGCrHnbLlJx3jmxMhcxJQCDui8Hbua9zr6w=","Date":"Mon, 13 Sep 2021 03:08:40 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<YT6WiNqED9XJepCc@pendragon.ideasonboard.com>","References":"<20210910070638.467294-1-umang.jain@ideasonboard.com>\n\t<20210910070638.467294-5-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210910070638.467294-5-umang.jain@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 4/9] android: post_processor:\n\tNotify post processing completion status","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>"}}]