[{"id":18982,"web_url":"https://patchwork.libcamera.org/comment/18982/","msgid":"<20210820135632.af6euixdxweabsys@uno.localdomain>","date":"2021-08-20T13:56:32","subject":"Re: [libcamera-devel] [PATCH v2 1/3] android: camera_stream: Create\n\tpost porcessor in configure()","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Hiro,\n\nOn Fri, Aug 20, 2021 at 05:12:12AM +0900, Hirokazu Honda wrote:\n> CameraStream creates PostProcessor and FrameBufferAllocator in\n> the constructor. CameraStream assumes that a used post processor\n> is JPEG post processor. Since we need to support various post\n> processors, we would rather move the creation to configure() so\n> as to return an error code if no proper post processor is found.\n> This also moves FrameBufferAllocator and Mutex creation for\n> consistency.\n>\n> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> ---\n>  src/android/camera_device.h   |  1 +\n>  src/android/camera_stream.cpp | 36 ++++++++++++++++++-----------------\n>  2 files changed, 20 insertions(+), 17 deletions(-)\n>\n> diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n> index dd9aebba..abe8ca44 100644\n> --- a/src/android/camera_device.h\n> +++ b/src/android/camera_device.h\n> @@ -46,6 +46,7 @@ public:\n>\n>  \tunsigned int id() const { return id_; }\n>  \tcamera3_device_t *camera3Device() { return &camera3Device_; }\n> +\tconst CameraCapabilities *capabilities() const { return &capabilities_; }\n>  \tconst std::shared_ptr<libcamera::Camera> &camera() const { return camera_; }\n>\n>  \tconst std::string &maker() const { return maker_; }\n> diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp\n> index 61b44183..c205cd7a 100644\n> --- a/src/android/camera_stream.cpp\n> +++ b/src/android/camera_stream.cpp\n> @@ -10,6 +10,7 @@\n>  #include <sys/mman.h>\n>\n>  #include \"camera_buffer.h\"\n> +#include \"camera_capabilities.h\"\n>  #include \"camera_device.h\"\n>  #include \"camera_metadata.h\"\n>  #include \"jpeg/post_processor_jpeg.h\"\n> @@ -47,20 +48,6 @@ CameraStream::CameraStream(CameraDevice *const cameraDevice,\n>  \t: cameraDevice_(cameraDevice), config_(config), type_(type),\n>  \t  camera3Stream_(camera3Stream), index_(index)\n>  {\n> -\tif (type_ == Type::Internal || type_ == Type::Mapped) {\n> -\t\t/*\n> -\t\t * \\todo There might be multiple post-processors. The logic\n> -\t\t * which should be instantiated here, is deferred for the\n> -\t\t * future. For now, we only have PostProcessorJpeg and that\n> -\t\t * is what we instantiate here.\n> -\t\t */\n> -\t\tpostProcessor_ = std::make_unique<PostProcessorJpeg>(cameraDevice_);\n> -\t}\n> -\n> -\tif (type == Type::Internal) {\n> -\t\tallocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());\n> -\t\tmutex_ = std::make_unique<std::mutex>();\n> -\t}\n>  }\n>\n>  const StreamConfiguration &CameraStream::configuration() const\n> @@ -75,15 +62,30 @@ Stream *CameraStream::stream() const\n>\n>  int CameraStream::configure()\n>  {\n> -\tif (postProcessor_) {\n> +\tif (type_ == Type::Internal || type_ == Type::Mapped) {\n> +\t\tconst PixelFormat outFormat =\n> +\t\t\tcameraDevice_->capabilities()->toPixelFormat(camera3Stream_->format);\n>  \t\tStreamConfiguration output = configuration();\n> -\t\toutput.pixelFormat = formats::MJPEG;\n> +\t\toutput.pixelFormat = outFormat;\n> +\t\tswitch (outFormat) {\n> +\t\tcase formats::MJPEG:\n> +\t\t\tpostProcessor_ = std::make_unique<PostProcessorJpeg>(cameraDevice_);\n\nI might have missed why for JPEG we don't set the output's size and\nfor YUV we do. But I might have missed some pieces...\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\n> +\t\t\tbreak;\n> +\n> +\t\tdefault:\n> +\t\t\tLOG(HAL, Error) << \"Unsupported format: \" << outFormat;\n> +\t\t\treturn -EINVAL;\n> +\t\t}\n> +\n>  \t\tint ret = postProcessor_->configure(configuration(), output);\n>  \t\tif (ret)\n>  \t\t\treturn ret;\n>  \t}\n>\n> -\tif (allocator_) {\n> +\tif (type_ == Type::Internal) {\n> +\t\tallocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());\n> +\t\tmutex_ = std::make_unique<std::mutex>();\n> +\n>  \t\tint ret = allocator_->allocate(stream());\n>  \t\tif (ret < 0)\n>  \t\t\treturn ret;\n> --\n> 2.33.0.rc2.250.ged5fa647cd-goog\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 4FA3DBD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 20 Aug 2021 13:55:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BC146688A2;\n\tFri, 20 Aug 2021 15:55:47 +0200 (CEST)","from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 458616888E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 Aug 2021 15:55:46 +0200 (CEST)","(Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id 4E98110000F;\n\tFri, 20 Aug 2021 13:55:44 +0000 (UTC)"],"Date":"Fri, 20 Aug 2021 15:56:32 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Hirokazu Honda <hiroh@chromium.org>","Message-ID":"<20210820135632.af6euixdxweabsys@uno.localdomain>","References":"<20210819201214.1554322-1-hiroh@chromium.org>\n\t<20210819201214.1554322-2-hiroh@chromium.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20210819201214.1554322-2-hiroh@chromium.org>","Subject":"Re: [libcamera-devel] [PATCH v2 1/3] android: camera_stream: Create\n\tpost porcessor in configure()","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>"}},{"id":18997,"web_url":"https://patchwork.libcamera.org/comment/18997/","msgid":"<CAO5uPHMJhmDb1X5LwUkR1oKUihzqrkqVaDgLE9iPWvNHzShkVA@mail.gmail.com>","date":"2021-08-23T08:11:47","subject":"Re: [libcamera-devel] [PATCH v2 1/3] android: camera_stream: Create\n\tpost porcessor in configure()","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"content":"Hi Jacopo, thank you for reviewing.\n\nOn Fri, Aug 20, 2021 at 10:55 PM Jacopo Mondi <jacopo@jmondi.org> wrote:\n>\n> Hi Hiro,\n>\n> On Fri, Aug 20, 2021 at 05:12:12AM +0900, Hirokazu Honda wrote:\n> > CameraStream creates PostProcessor and FrameBufferAllocator in\n> > the constructor. CameraStream assumes that a used post processor\n> > is JPEG post processor. Since we need to support various post\n> > processors, we would rather move the creation to configure() so\n> > as to return an error code if no proper post processor is found.\n> > This also moves FrameBufferAllocator and Mutex creation for\n> > consistency.\n> >\n> > Signed-off-by: Hirokazu Honda <hiroh@chromium.org>\n> > ---\n> >  src/android/camera_device.h   |  1 +\n> >  src/android/camera_stream.cpp | 36 ++++++++++++++++++-----------------\n> >  2 files changed, 20 insertions(+), 17 deletions(-)\n> >\n> > diff --git a/src/android/camera_device.h b/src/android/camera_device.h\n> > index dd9aebba..abe8ca44 100644\n> > --- a/src/android/camera_device.h\n> > +++ b/src/android/camera_device.h\n> > @@ -46,6 +46,7 @@ public:\n> >\n> >       unsigned int id() const { return id_; }\n> >       camera3_device_t *camera3Device() { return &camera3Device_; }\n> > +     const CameraCapabilities *capabilities() const { return &capabilities_; }\n> >       const std::shared_ptr<libcamera::Camera> &camera() const { return camera_; }\n> >\n> >       const std::string &maker() const { return maker_; }\n> > diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp\n> > index 61b44183..c205cd7a 100644\n> > --- a/src/android/camera_stream.cpp\n> > +++ b/src/android/camera_stream.cpp\n> > @@ -10,6 +10,7 @@\n> >  #include <sys/mman.h>\n> >\n> >  #include \"camera_buffer.h\"\n> > +#include \"camera_capabilities.h\"\n> >  #include \"camera_device.h\"\n> >  #include \"camera_metadata.h\"\n> >  #include \"jpeg/post_processor_jpeg.h\"\n> > @@ -47,20 +48,6 @@ CameraStream::CameraStream(CameraDevice *const cameraDevice,\n> >       : cameraDevice_(cameraDevice), config_(config), type_(type),\n> >         camera3Stream_(camera3Stream), index_(index)\n> >  {\n> > -     if (type_ == Type::Internal || type_ == Type::Mapped) {\n> > -             /*\n> > -              * \\todo There might be multiple post-processors. The logic\n> > -              * which should be instantiated here, is deferred for the\n> > -              * future. For now, we only have PostProcessorJpeg and that\n> > -              * is what we instantiate here.\n> > -              */\n> > -             postProcessor_ = std::make_unique<PostProcessorJpeg>(cameraDevice_);\n> > -     }\n> > -\n> > -     if (type == Type::Internal) {\n> > -             allocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());\n> > -             mutex_ = std::make_unique<std::mutex>();\n> > -     }\n> >  }\n> >\n> >  const StreamConfiguration &CameraStream::configuration() const\n> > @@ -75,15 +62,30 @@ Stream *CameraStream::stream() const\n> >\n> >  int CameraStream::configure()\n> >  {\n> > -     if (postProcessor_) {\n> > +     if (type_ == Type::Internal || type_ == Type::Mapped) {\n> > +             const PixelFormat outFormat =\n> > +                     cameraDevice_->capabilities()->toPixelFormat(camera3Stream_->format);\n> >               StreamConfiguration output = configuration();\n> > -             output.pixelFormat = formats::MJPEG;\n> > +             output.pixelFormat = outFormat;\n> > +             switch (outFormat) {\n> > +             case formats::MJPEG:\n> > +                     postProcessor_ = std::make_unique<PostProcessorJpeg>(cameraDevice_);\n>\n> I might have missed why for JPEG we don't set the output's size and\n> for YUV we do. But I might have missed some pieces...\n>\n\nIt is because we specify the same output resolution for JPEG as input\nresolution.\n\nRegards,\n-Hiro\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n>\n> Thanks\n>   j\n>\n> > +                     break;\n> > +\n> > +             default:\n> > +                     LOG(HAL, Error) << \"Unsupported format: \" << outFormat;\n> > +                     return -EINVAL;\n> > +             }\n> > +\n> >               int ret = postProcessor_->configure(configuration(), output);\n> >               if (ret)\n> >                       return ret;\n> >       }\n> >\n> > -     if (allocator_) {\n> > +     if (type_ == Type::Internal) {\n> > +             allocator_ = std::make_unique<FrameBufferAllocator>(cameraDevice_->camera());\n> > +             mutex_ = std::make_unique<std::mutex>();\n> > +\n> >               int ret = allocator_->allocate(stream());\n> >               if (ret < 0)\n> >                       return ret;\n> > --\n> > 2.33.0.rc2.250.ged5fa647cd-goog\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 1A8FBBD87D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Aug 2021 08:12:02 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 85A6968892;\n\tMon, 23 Aug 2021 10:12:01 +0200 (CEST)","from mail-ed1-x535.google.com (mail-ed1-x535.google.com\n\t[IPv6:2a00:1450:4864:20::535])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A466368891\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Aug 2021 10:11:59 +0200 (CEST)","by mail-ed1-x535.google.com with SMTP id cn28so24913196edb.6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Aug 2021 01:11:59 -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=\"SUmrCFSg\"; 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=55GbY439NvtHZV16xDQHV8GsnQ8JIdQr6vaBFK3yzWI=;\n\tb=SUmrCFSgxo4fG1VZRZvcF/VgVXLCPyD96SSNaVjcuihGfeV3wWZQv0JBOLmjBVY13E\n\tZOhfBj2PIddRkFH2UCkbwB9uoDAZdZoycHBYfVkPpBaOgiJygzvzDFZug9jpZHZ5uedH\n\tkMMUAGhdxfCCQfYE0fdZj4Hdvxe5VYFG9p4jg=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=55GbY439NvtHZV16xDQHV8GsnQ8JIdQr6vaBFK3yzWI=;\n\tb=Z0F8N0ZV3AHwq1EoRTr2GUXXhTEnmJNHRjWyK4OaTBCuFA03DT+AazTl/F7QOKkagN\n\tkaldAdQ5g1pxQPfSvPRwOpCXJdhZT3uNHRSFrHLusCLDnAGbLhFEeAULjDriazk1Wj6p\n\t7rVhC/sjDIIbTSnc/zdtiak2qCVSkqHgSQUuZ7WPnm85Z3kDqsePZHx56mFvjn7frUZ3\n\tSOufFoSLbUHuUuq3SHvKMA3yTTfQNC2rDh9lbbM50cRJjlkobwlaiXZU92bl4wsqtZvc\n\t+w6z2cyqI6f3M7YEgLWl5fA/s6Zxc9PV5KyU7Sj4a1WDZ4imJUIiuNYb8O7IDICuQvoN\n\tiAjw==","X-Gm-Message-State":"AOAM531E6pt0KuGwhFXksbYiD8JbUwg+lfU7cwNTjKbcLwlckmHFdTzX\n\t6jKX1ijCGhbEE2qx/W3uY9R5uc6f2SAy6Ozynbu3DQ==","X-Google-Smtp-Source":"ABdhPJx/mNJ0ybzA5HKApqNtiQuOBHRK8/CF39eESKcyahEvn1ioHpA5L/sgT1G0nJUE3qs5D4idliPHYYFIcbX4XEA=","X-Received":"by 2002:a05:6402:34d6:: with SMTP id\n\tw22mr36255310edc.244.1629706319307; \n\tMon, 23 Aug 2021 01:11:59 -0700 (PDT)","MIME-Version":"1.0","References":"<20210819201214.1554322-1-hiroh@chromium.org>\n\t<20210819201214.1554322-2-hiroh@chromium.org>\n\t<20210820135632.af6euixdxweabsys@uno.localdomain>","In-Reply-To":"<20210820135632.af6euixdxweabsys@uno.localdomain>","From":"Hirokazu Honda <hiroh@chromium.org>","Date":"Mon, 23 Aug 2021 17:11:47 +0900","Message-ID":"<CAO5uPHMJhmDb1X5LwUkR1oKUihzqrkqVaDgLE9iPWvNHzShkVA@mail.gmail.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH v2 1/3] android: camera_stream: Create\n\tpost porcessor in configure()","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>"}}]