[{"id":27882,"web_url":"https://patchwork.libcamera.org/comment/27882/","msgid":"<169565353019.3049594.7031362347558201747@ping.linuxembedded.co.uk>","date":"2023-09-25T14:52:10","subject":"Re: [libcamera-devel] [PATCH v2] ipa: rpi: imx296: Enable embedded\n\tdata","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck via libcamera-devel (2023-06-26 15:39:32)\n> Enable embedded data parsing for the imx296 sensor.\n> \n> However, the imx296 has a quirk where the embedded data is ahead by a\n> single frame, i.e. embedded data in frame N corresponds to the image\n> data in frame N+1. So make a copy of the embedded data buffer stored in\n> the camera helper state, and use that copy in the next frame.\n> \n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n\nAnything blocking this patch?\n\nIt looks like there was small discussion on v1 and that was handled with\nan update noted below. This seems reasonable to me here... so\n\n\n> ---\n> Changes since v1:\n> - Replace the use of std::unique_ptr with std::vector<uint8_t>\n> ---\n>  src/ipa/rpi/cam_helper/cam_helper_imx296.cpp | 60 +++++++++++++++++++-\n>  1 file changed, 59 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp\n> index ecb845e76e12..e84243704e5a 100644\n> --- a/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp\n> +++ b/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp\n> @@ -7,7 +7,9 @@\n>  \n>  #include <algorithm>\n>  #include <cmath>\n> +#include <string.h>\n>  #include <stddef.h>\n> +#include <vector>\n>  \n>  #include \"cam_helper.h\"\n>  \n> @@ -15,6 +17,17 @@ using namespace RPiController;\n>  using libcamera::utils::Duration;\n>  using namespace std::literals::chrono_literals;\n>  \n> +constexpr uint32_t gainReg = 0x41ba;\n> +constexpr uint32_t shsLoReg = 0x41b4;\n> +constexpr uint32_t shsMidReg = 0x41b5;\n> +constexpr uint32_t shsHiReg = 0x41b6;\n> +constexpr uint32_t vmaxLoReg = 0x41cc;\n> +constexpr uint32_t vmaxMidReg = 0x41cd;\n> +constexpr uint32_t vmaxHiReg = 0x41ce;\n> +constexpr uint32_t tempReg = 0x41da;\n> +constexpr std::initializer_list<uint32_t> registerList =\n> +       { gainReg, shsLoReg, shsMidReg, shsHiReg, vmaxLoReg, vmaxMidReg, vmaxHiReg, tempReg };\n> +\n>  class CamHelperImx296 : public CamHelper\n>  {\n>  public:\n> @@ -23,8 +36,12 @@ public:\n>         double gain(uint32_t gainCode) const override;\n>         uint32_t exposureLines(const Duration exposure, const Duration lineLength) const override;\n>         Duration exposure(uint32_t exposureLines, const Duration lineLength) const override;\n> +       void prepare(libcamera::Span<const uint8_t> buffer, Metadata &metadata) override;\n>         void getDelays(int &exposureDelay, int &gainDelay,\n>                        int &vblankDelay, int &hblankDelay) const override;\n> +       bool sensorEmbeddedDataPresent() const override;\n> +       void populateMetadata(const MdParser::RegisterMap &registers,\n> +                             Metadata &metadata) const override;\n>  \n>  private:\n>         static constexpr uint32_t minExposureLines = 1;\n> @@ -36,10 +53,12 @@ private:\n>          * in units of lines.\n>          */\n>         static constexpr int frameIntegrationDiff = 4;\n> +\n> +       std::vector<uint8_t> lastEmbeddedBuffer_;\n>  };\n>  \n>  CamHelperImx296::CamHelperImx296()\n> -       : CamHelper(nullptr, frameIntegrationDiff)\n> +       : CamHelper(std::make_unique<MdParserSmia>(registerList), frameIntegrationDiff)\n>  {\n>  }\n>  \n> @@ -66,6 +85,23 @@ Duration CamHelperImx296::exposure(uint32_t exposureLines,\n>         return std::max<uint32_t>(minExposureLines, exposureLines) * timePerLine + 14.26us;\n>  }\n>  \n> +void CamHelperImx296::prepare(libcamera::Span<const uint8_t> buffer, Metadata &metadata)\n> +{\n> +       /*\n> +        * The imx296 embedded data is ahead by a single frame, i.e. embedded\n> +        * data in frame N corresponds to the image data in frame N+1. So make\n> +        * a copy of the embedded data buffer and use it as normal for the next\n> +        * frame.\n> +        */\n> +       CamHelper::prepare({ lastEmbeddedBuffer_.data(), lastEmbeddedBuffer_.size() },\n> +                          metadata);\n> +\n> +       if (lastEmbeddedBuffer_.size() != buffer.size())\n> +               lastEmbeddedBuffer_.resize(buffer.size());\n> +\n> +       memcpy(lastEmbeddedBuffer_.data(), buffer.data(), buffer.size());\n> +}\n> +\n>  void CamHelperImx296::getDelays(int &exposureDelay, int &gainDelay,\n>                                 int &vblankDelay, int &hblankDelay) const\n>  {\n> @@ -75,6 +111,28 @@ void CamHelperImx296::getDelays(int &exposureDelay, int &gainDelay,\n>         hblankDelay = 2;\n>  }\n>  \n> +bool CamHelperImx296::sensorEmbeddedDataPresent() const\n> +{\n> +       return true;\n> +}\n> +\n> +void CamHelperImx296::populateMetadata(const MdParser::RegisterMap &registers,\n> +                                      Metadata &metadata) const\n> +{\n> +       uint32_t shs = registers.at(shsLoReg) + (registers.at(shsMidReg) << 8) +\n> +                      (registers.at(shsHiReg) << 16);\n> +       uint32_t vmax = registers.at(vmaxLoReg) + (registers.at(vmaxMidReg) << 8) +\n> +                       (registers.at(vmaxHiReg) << 16);\n\nMaybe in the future we could add some register access helpers to make\nthis easier? But I don't see that blocking here.\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> +\n> +       DeviceStatus deviceStatus;\n> +       deviceStatus.lineLength = timePerLine;\n> +       deviceStatus.frameLength = vmax;\n> +       deviceStatus.shutterSpeed = exposure(vmax - shs, timePerLine);\n> +       deviceStatus.analogueGain = gain(registers.at(gainReg));\n> +\n> +       metadata.set(\"device.status\", deviceStatus);\n> +}\n> +\n>  static CamHelper *create()\n>  {\n>         return new CamHelperImx296();\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 4FE9EBD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 25 Sep 2023 14:52:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A5CC162931;\n\tMon, 25 Sep 2023 16:52:14 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0C873628FA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 25 Sep 2023 16:52:13 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net\n\t[82.37.23.78])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D30C518BF;\n\tMon, 25 Sep 2023 16:50:32 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1695653534;\n\tbh=H31oGsaG304bvDrB9hjAm3Pp7pEp0vGQSUSRoZxzd9k=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=3fvES7fHXfdpK+bnV/HIOBLthMU+1OdGM1um8yDukZ5yH+V5kFhC+1zH19RypeMZ0\n\tWdeDsqBZcDWO8wcP4rYcNmURIMO3tzBwCF9GnhcSk8c4epEurBcWlqq3xcktppyYMg\n\t7PZRpL3AmhNZwvdkLOWr3QD9HukbOejJQM4q0kD36U2i98b3owYf4rvZpCU7QnmwXy\n\tGxrH3nM085v5P1Q0rJAhjWSt748L01ngdWxFyoyESeecMfloKPlIggHVSdeOnKLHw+\n\tIQHKPR14dhf4G5uxzWKOaC9heWak2nR5+sXBrMT4/FM4rHxt3gFbopUe5OHc2DF/j9\n\tAfHGQ5PZr3LZA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1695653432;\n\tbh=H31oGsaG304bvDrB9hjAm3Pp7pEp0vGQSUSRoZxzd9k=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=vAd6XNqqYe63sCr6Jhv/v9wwG+5e0vrQzo1PB90sh87QlsnhPI/qR5hWxcxbmpIeA\n\t3zRjn5+6V1cmhRqZtr4VUuSdVZ/4AcBxf2lsxS61YyoAO8AIWyr9mwPUzNBjI5UedP\n\tVWSpw5Z/oddOZpNgdJlFZGtgmUuk4tIrLnz19ZOM="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"vAd6XNqq\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20230626143932.18888-1-naush@raspberrypi.com>","References":"<20230626143932.18888-1-naush@raspberrypi.com>","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 25 Sep 2023 15:52:10 +0100","Message-ID":"<169565353019.3049594.7031362347558201747@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v2] ipa: rpi: imx296: Enable embedded\n\tdata","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":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27885,"web_url":"https://patchwork.libcamera.org/comment/27885/","msgid":"<CAEmqJPpMYEV04edpCfcNE4QqMaKgV3EpXXqHf5k-YVQGWGuXLg@mail.gmail.com>","date":"2023-09-25T15:06:07","subject":"Re: [libcamera-devel] [PATCH v2] ipa: rpi: imx296: Enable embedded\n\tdata","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Kieran,\n\nOn Mon, 25 Sept 2023 at 15:52, Kieran Bingham\n<kieran.bingham@ideasonboard.com> wrote:\n>\n> Quoting Naushir Patuck via libcamera-devel (2023-06-26 15:39:32)\n> > Enable embedded data parsing for the imx296 sensor.\n> >\n> > However, the imx296 has a quirk where the embedded data is ahead by a\n> > single frame, i.e. embedded data in frame N corresponds to the image\n> > data in frame N+1. So make a copy of the embedded data buffer stored in\n> > the camera helper state, and use that copy in the next frame.\n> >\n> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n>\n> Anything blocking this patch?\n>\n> It looks like there was small discussion on v1 and that was handled with\n> an update noted below. This seems reasonable to me here... so\n\nThe only reason to hold back is that the imx296 kernel driver does not\ncurrently enable/advertise embedded data.  But the pipeline handler\ncode should handle this so.... I am ok to merge this now.\n\n>\n>\n> > ---\n> > Changes since v1:\n> > - Replace the use of std::unique_ptr with std::vector<uint8_t>\n> > ---\n> >  src/ipa/rpi/cam_helper/cam_helper_imx296.cpp | 60 +++++++++++++++++++-\n> >  1 file changed, 59 insertions(+), 1 deletion(-)\n> >\n> > diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp\n> > index ecb845e76e12..e84243704e5a 100644\n> > --- a/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp\n> > +++ b/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp\n> > @@ -7,7 +7,9 @@\n> >\n> >  #include <algorithm>\n> >  #include <cmath>\n> > +#include <string.h>\n> >  #include <stddef.h>\n> > +#include <vector>\n> >\n> >  #include \"cam_helper.h\"\n> >\n> > @@ -15,6 +17,17 @@ using namespace RPiController;\n> >  using libcamera::utils::Duration;\n> >  using namespace std::literals::chrono_literals;\n> >\n> > +constexpr uint32_t gainReg = 0x41ba;\n> > +constexpr uint32_t shsLoReg = 0x41b4;\n> > +constexpr uint32_t shsMidReg = 0x41b5;\n> > +constexpr uint32_t shsHiReg = 0x41b6;\n> > +constexpr uint32_t vmaxLoReg = 0x41cc;\n> > +constexpr uint32_t vmaxMidReg = 0x41cd;\n> > +constexpr uint32_t vmaxHiReg = 0x41ce;\n> > +constexpr uint32_t tempReg = 0x41da;\n> > +constexpr std::initializer_list<uint32_t> registerList =\n> > +       { gainReg, shsLoReg, shsMidReg, shsHiReg, vmaxLoReg, vmaxMidReg, vmaxHiReg, tempReg };\n> > +\n> >  class CamHelperImx296 : public CamHelper\n> >  {\n> >  public:\n> > @@ -23,8 +36,12 @@ public:\n> >         double gain(uint32_t gainCode) const override;\n> >         uint32_t exposureLines(const Duration exposure, const Duration lineLength) const override;\n> >         Duration exposure(uint32_t exposureLines, const Duration lineLength) const override;\n> > +       void prepare(libcamera::Span<const uint8_t> buffer, Metadata &metadata) override;\n> >         void getDelays(int &exposureDelay, int &gainDelay,\n> >                        int &vblankDelay, int &hblankDelay) const override;\n> > +       bool sensorEmbeddedDataPresent() const override;\n> > +       void populateMetadata(const MdParser::RegisterMap &registers,\n> > +                             Metadata &metadata) const override;\n> >\n> >  private:\n> >         static constexpr uint32_t minExposureLines = 1;\n> > @@ -36,10 +53,12 @@ private:\n> >          * in units of lines.\n> >          */\n> >         static constexpr int frameIntegrationDiff = 4;\n> > +\n> > +       std::vector<uint8_t> lastEmbeddedBuffer_;\n> >  };\n> >\n> >  CamHelperImx296::CamHelperImx296()\n> > -       : CamHelper(nullptr, frameIntegrationDiff)\n> > +       : CamHelper(std::make_unique<MdParserSmia>(registerList), frameIntegrationDiff)\n> >  {\n> >  }\n> >\n> > @@ -66,6 +85,23 @@ Duration CamHelperImx296::exposure(uint32_t exposureLines,\n> >         return std::max<uint32_t>(minExposureLines, exposureLines) * timePerLine + 14.26us;\n> >  }\n> >\n> > +void CamHelperImx296::prepare(libcamera::Span<const uint8_t> buffer, Metadata &metadata)\n> > +{\n> > +       /*\n> > +        * The imx296 embedded data is ahead by a single frame, i.e. embedded\n> > +        * data in frame N corresponds to the image data in frame N+1. So make\n> > +        * a copy of the embedded data buffer and use it as normal for the next\n> > +        * frame.\n> > +        */\n> > +       CamHelper::prepare({ lastEmbeddedBuffer_.data(), lastEmbeddedBuffer_.size() },\n> > +                          metadata);\n> > +\n> > +       if (lastEmbeddedBuffer_.size() != buffer.size())\n> > +               lastEmbeddedBuffer_.resize(buffer.size());\n> > +\n> > +       memcpy(lastEmbeddedBuffer_.data(), buffer.data(), buffer.size());\n> > +}\n> > +\n> >  void CamHelperImx296::getDelays(int &exposureDelay, int &gainDelay,\n> >                                 int &vblankDelay, int &hblankDelay) const\n> >  {\n> > @@ -75,6 +111,28 @@ void CamHelperImx296::getDelays(int &exposureDelay, int &gainDelay,\n> >         hblankDelay = 2;\n> >  }\n> >\n> > +bool CamHelperImx296::sensorEmbeddedDataPresent() const\n> > +{\n> > +       return true;\n> > +}\n> > +\n> > +void CamHelperImx296::populateMetadata(const MdParser::RegisterMap &registers,\n> > +                                      Metadata &metadata) const\n> > +{\n> > +       uint32_t shs = registers.at(shsLoReg) + (registers.at(shsMidReg) << 8) +\n> > +                      (registers.at(shsHiReg) << 16);\n> > +       uint32_t vmax = registers.at(vmaxLoReg) + (registers.at(vmaxMidReg) << 8) +\n> > +                       (registers.at(vmaxHiReg) << 16);\n>\n> Maybe in the future we could add some register access helpers to make\n> this easier? But I don't see that blocking here.\n>\n>\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n>\n> > +\n> > +       DeviceStatus deviceStatus;\n> > +       deviceStatus.lineLength = timePerLine;\n> > +       deviceStatus.frameLength = vmax;\n> > +       deviceStatus.shutterSpeed = exposure(vmax - shs, timePerLine);\n> > +       deviceStatus.analogueGain = gain(registers.at(gainReg));\n> > +\n> > +       metadata.set(\"device.status\", deviceStatus);\n> > +}\n> > +\n> >  static CamHelper *create()\n> >  {\n> >         return new CamHelperImx296();\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 17FF3C326B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 25 Sep 2023 15:06:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 651F562944;\n\tMon, 25 Sep 2023 17:06:46 +0200 (CEST)","from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com\n\t[IPv6:2607:f8b0:4864:20::112d])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A85D6293E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 25 Sep 2023 17:06:45 +0200 (CEST)","by mail-yw1-x112d.google.com with SMTP id\n\t00721157ae682-59f57ad6126so41244787b3.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 25 Sep 2023 08:06:44 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1695654406;\n\tbh=IN/kY59Ue9Y5tf1ZjtvOucQFNGYPau418hjP91L4l98=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=E4MURgMXurXc1uunwQVJTMvd22DuxdV7hAphhtsaZr7rywAuTjq3Xh9ABo1eKJHT9\n\tZwBQMyFFq4Nib8gOTUV32tsuYbIv3GOjHaufWsgeY/QGIX3Y6pgQOifq/sQnI+qsa3\n\txlk2hGo5oeiM6gjiGxzWW9wtH64oHHeBIw0e8TVxNJN10c6vLzmxDw+QfwrnXZiPQP\n\tqwjPF+UQlEceoVmmqaR/ap3IGpZnhxuADvEFuzIFmeeSn/svG4hosxgUxXvFCg6GSW\n\tS/HL8sZuzYbIWw9lFYkhD2+AKQDht2ZyI/A+8XdmuJjaabOn4dUUJmk2royqLiaX1P\n\tuEzbONM/XuKTA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1695654403; x=1696259203;\n\tdarn=lists.libcamera.org; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=hgRuy7XZW4hlMNh6gfZKT0U5xvtxNr9P64wSdT2RXfU=;\n\tb=Sv87yv2MDBIJGxQOyXUJsk1vBYikUEm6nS996JKimLztKYxL4Jn8oLCeQPwBGxCL9O\n\tCE06qppJTa5xtRE6NTDcVASr3VvjoBcXDiWHAjuZAtpnSQi92oJbnFUHeXp2IiijB4H/\n\tfyl0wbTF8KuwCJ7zNfPPdFu6Cc2V5QGsgi97mbWJZdfBZ3+CP12V08yAKZuaa2nuruCB\n\twaKjgv8Qnz5p+sh3Obht+4nThdHoE0QhUh0MhzJLQnykbIsTILGoGNAZMvZRZmDpdNhj\n\t/NVMfQbIRUUT7S0xDOUz1/0XBeIK6pV9ZudnNGN3jKl2M87Zqm/YfdCN4pPtSURxZH3x\n\tDn3Q=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"Sv87yv2M\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1695654403; x=1696259203;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=hgRuy7XZW4hlMNh6gfZKT0U5xvtxNr9P64wSdT2RXfU=;\n\tb=He74izbxQwDcZeMF8/EumKHf6+aBHNWM5Xv+jio9jiaAjmoXrmf3kbk2adA6vFBgfF\n\t9Y8iHQiLH4xDtIM7oBVyJunTHgqTOOqEct5oro05VhVoiiOQaGW5Ib+F+OcXQy6W6Rys\n\tQ4fjaqaCiHKODPUKaSkK7NIHG0pqEehM8UxgMEUM/mFpvhiT31nhkUOfwPoiJyj9pZct\n\tSXBcikpd+t6msAufTrz7S9MDq2XsmLtPLE7GCX6GxJ3J6nasC4P5KWbes88kR0vEI4vE\n\tgjG+b0NNtIX1QHcn/fGF3pB+Z7A88DDwNx2sj1TKGjOaNlVhuMEdzCXDTUmIy5pWjguh\n\tZRSw==","X-Gm-Message-State":"AOJu0YyZOgvMCdXZ4AwaKnh+4zq8sPs5sgq6Ti2HrP6PGNY9oGVNJZNo\n\trZZHNGbUiSbkHLLrNQfC2H2/ie4wu+TYJ7Y8jGqw9A==","X-Google-Smtp-Source":"AGHT+IG/kiLSatars+YI/NCz6I3nnZpP3yXN4euRwFDtfMyW37ZzvPYyt52coFAWTBWeo3BiKdOsYSxKsM4FD4itOmU=","X-Received":"by 2002:a0d:ce85:0:b0:589:e4aa:7b67 with SMTP id\n\tq127-20020a0dce85000000b00589e4aa7b67mr6615899ywd.41.1695654403523;\n\tMon, 25 Sep 2023 08:06:43 -0700 (PDT)","MIME-Version":"1.0","References":"<20230626143932.18888-1-naush@raspberrypi.com>\n\t<169565353019.3049594.7031362347558201747@ping.linuxembedded.co.uk>","In-Reply-To":"<169565353019.3049594.7031362347558201747@ping.linuxembedded.co.uk>","Date":"Mon, 25 Sep 2023 16:06:07 +0100","Message-ID":"<CAEmqJPpMYEV04edpCfcNE4QqMaKgV3EpXXqHf5k-YVQGWGuXLg@mail.gmail.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH v2] ipa: rpi: imx296: Enable embedded\n\tdata","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":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27886,"web_url":"https://patchwork.libcamera.org/comment/27886/","msgid":"<169565519874.2427060.6402917833810187049@ping.linuxembedded.co.uk>","date":"2023-09-25T15:19:58","subject":"Re: [libcamera-devel] [PATCH v2] ipa: rpi: imx296: Enable embedded\n\tdata","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Naushir Patuck (2023-09-25 16:06:07)\n> Hi Kieran,\n> \n> On Mon, 25 Sept 2023 at 15:52, Kieran Bingham\n> <kieran.bingham@ideasonboard.com> wrote:\n> >\n> > Quoting Naushir Patuck via libcamera-devel (2023-06-26 15:39:32)\n> > > Enable embedded data parsing for the imx296 sensor.\n> > >\n> > > However, the imx296 has a quirk where the embedded data is ahead by a\n> > > single frame, i.e. embedded data in frame N corresponds to the image\n> > > data in frame N+1. So make a copy of the embedded data buffer stored in\n> > > the camera helper state, and use that copy in the next frame.\n> > >\n> > > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> >\n> > Anything blocking this patch?\n> >\n> > It looks like there was small discussion on v1 and that was handled with\n> > an update noted below. This seems reasonable to me here... so\n> \n> The only reason to hold back is that the imx296 kernel driver does not\n> currently enable/advertise embedded data.  But the pipeline handler\n> code should handle this so.... I am ok to merge this now.\n\nWell I'll leave that to an additional tag appearing!\n\n--\nKieran\n\n\n> \n> >\n> >\n> > > ---\n> > > Changes since v1:\n> > > - Replace the use of std::unique_ptr with std::vector<uint8_t>\n> > > ---\n> > >  src/ipa/rpi/cam_helper/cam_helper_imx296.cpp | 60 +++++++++++++++++++-\n> > >  1 file changed, 59 insertions(+), 1 deletion(-)\n> > >\n> > > diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp\n> > > index ecb845e76e12..e84243704e5a 100644\n> > > --- a/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp\n> > > +++ b/src/ipa/rpi/cam_helper/cam_helper_imx296.cpp\n> > > @@ -7,7 +7,9 @@\n> > >\n> > >  #include <algorithm>\n> > >  #include <cmath>\n> > > +#include <string.h>\n> > >  #include <stddef.h>\n> > > +#include <vector>\n> > >\n> > >  #include \"cam_helper.h\"\n> > >\n> > > @@ -15,6 +17,17 @@ using namespace RPiController;\n> > >  using libcamera::utils::Duration;\n> > >  using namespace std::literals::chrono_literals;\n> > >\n> > > +constexpr uint32_t gainReg = 0x41ba;\n> > > +constexpr uint32_t shsLoReg = 0x41b4;\n> > > +constexpr uint32_t shsMidReg = 0x41b5;\n> > > +constexpr uint32_t shsHiReg = 0x41b6;\n> > > +constexpr uint32_t vmaxLoReg = 0x41cc;\n> > > +constexpr uint32_t vmaxMidReg = 0x41cd;\n> > > +constexpr uint32_t vmaxHiReg = 0x41ce;\n> > > +constexpr uint32_t tempReg = 0x41da;\n> > > +constexpr std::initializer_list<uint32_t> registerList =\n> > > +       { gainReg, shsLoReg, shsMidReg, shsHiReg, vmaxLoReg, vmaxMidReg, vmaxHiReg, tempReg };\n> > > +\n> > >  class CamHelperImx296 : public CamHelper\n> > >  {\n> > >  public:\n> > > @@ -23,8 +36,12 @@ public:\n> > >         double gain(uint32_t gainCode) const override;\n> > >         uint32_t exposureLines(const Duration exposure, const Duration lineLength) const override;\n> > >         Duration exposure(uint32_t exposureLines, const Duration lineLength) const override;\n> > > +       void prepare(libcamera::Span<const uint8_t> buffer, Metadata &metadata) override;\n> > >         void getDelays(int &exposureDelay, int &gainDelay,\n> > >                        int &vblankDelay, int &hblankDelay) const override;\n> > > +       bool sensorEmbeddedDataPresent() const override;\n> > > +       void populateMetadata(const MdParser::RegisterMap &registers,\n> > > +                             Metadata &metadata) const override;\n> > >\n> > >  private:\n> > >         static constexpr uint32_t minExposureLines = 1;\n> > > @@ -36,10 +53,12 @@ private:\n> > >          * in units of lines.\n> > >          */\n> > >         static constexpr int frameIntegrationDiff = 4;\n> > > +\n> > > +       std::vector<uint8_t> lastEmbeddedBuffer_;\n> > >  };\n> > >\n> > >  CamHelperImx296::CamHelperImx296()\n> > > -       : CamHelper(nullptr, frameIntegrationDiff)\n> > > +       : CamHelper(std::make_unique<MdParserSmia>(registerList), frameIntegrationDiff)\n> > >  {\n> > >  }\n> > >\n> > > @@ -66,6 +85,23 @@ Duration CamHelperImx296::exposure(uint32_t exposureLines,\n> > >         return std::max<uint32_t>(minExposureLines, exposureLines) * timePerLine + 14.26us;\n> > >  }\n> > >\n> > > +void CamHelperImx296::prepare(libcamera::Span<const uint8_t> buffer, Metadata &metadata)\n> > > +{\n> > > +       /*\n> > > +        * The imx296 embedded data is ahead by a single frame, i.e. embedded\n> > > +        * data in frame N corresponds to the image data in frame N+1. So make\n> > > +        * a copy of the embedded data buffer and use it as normal for the next\n> > > +        * frame.\n> > > +        */\n> > > +       CamHelper::prepare({ lastEmbeddedBuffer_.data(), lastEmbeddedBuffer_.size() },\n> > > +                          metadata);\n> > > +\n> > > +       if (lastEmbeddedBuffer_.size() != buffer.size())\n> > > +               lastEmbeddedBuffer_.resize(buffer.size());\n> > > +\n> > > +       memcpy(lastEmbeddedBuffer_.data(), buffer.data(), buffer.size());\n> > > +}\n> > > +\n> > >  void CamHelperImx296::getDelays(int &exposureDelay, int &gainDelay,\n> > >                                 int &vblankDelay, int &hblankDelay) const\n> > >  {\n> > > @@ -75,6 +111,28 @@ void CamHelperImx296::getDelays(int &exposureDelay, int &gainDelay,\n> > >         hblankDelay = 2;\n> > >  }\n> > >\n> > > +bool CamHelperImx296::sensorEmbeddedDataPresent() const\n> > > +{\n> > > +       return true;\n> > > +}\n> > > +\n> > > +void CamHelperImx296::populateMetadata(const MdParser::RegisterMap &registers,\n> > > +                                      Metadata &metadata) const\n> > > +{\n> > > +       uint32_t shs = registers.at(shsLoReg) + (registers.at(shsMidReg) << 8) +\n> > > +                      (registers.at(shsHiReg) << 16);\n> > > +       uint32_t vmax = registers.at(vmaxLoReg) + (registers.at(vmaxMidReg) << 8) +\n> > > +                       (registers.at(vmaxHiReg) << 16);\n> >\n> > Maybe in the future we could add some register access helpers to make\n> > this easier? But I don't see that blocking here.\n> >\n> >\n> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> >\n> > > +\n> > > +       DeviceStatus deviceStatus;\n> > > +       deviceStatus.lineLength = timePerLine;\n> > > +       deviceStatus.frameLength = vmax;\n> > > +       deviceStatus.shutterSpeed = exposure(vmax - shs, timePerLine);\n> > > +       deviceStatus.analogueGain = gain(registers.at(gainReg));\n> > > +\n> > > +       metadata.set(\"device.status\", deviceStatus);\n> > > +}\n> > > +\n> > >  static CamHelper *create()\n> > >  {\n> > >         return new CamHelperImx296();\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 6CD05BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 25 Sep 2023 15:20:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DA9F362944;\n\tMon, 25 Sep 2023 17:20:02 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 64796628FA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 25 Sep 2023 17:20:01 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net\n\t[82.37.23.78])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3064913C5;\n\tMon, 25 Sep 2023 17:18:21 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1695655202;\n\tbh=FoXSRjzTLGMrES1HPmOY/zMdHKIvIyCJTfEgGBVm7Uc=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=rYFhjsyJRLvnvmnRWaePV/Lf83B/PhtpcMbAWubqOPa6GPu3sdzGiyjQwNnGYXipT\n\t02hDoNyxsex/8AaSMdcOoJlnDJTCucIbED27oSURdWPGRemBw47AkAnDsNjSiaa+Fs\n\tRwXaC8BFvvfEn7HtCKz7kdnlm2Qw+C/Zc8Yshe7vrYMuvYqs4p49Q9vj0vr2OLdkzW\n\tsILLk0ylB2u/58gKCJdcugr7CxDt6nOX/1XZY+8hON++b0Q8Mov+T7n7cAhiEN8onI\n\t8hqTQKJI13nFlyfRMRQkz7jwrvyRAOWhPgaaLeCP7vrD5+bROckOBnR0ReJ0PIZsUw\n\tW6oTpbP9+55OQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1695655101;\n\tbh=FoXSRjzTLGMrES1HPmOY/zMdHKIvIyCJTfEgGBVm7Uc=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=D0e6CigTMsSZvHdtr4x1p+tfqt9p/7UVvoe3dHAqma05n2272K8b1caoewqHSdafH\n\t7vxhgaP2kNcbhs1sUwEokj/vnpyIyp4N6B4AL6LrobuHRpF8BKTAX1BYft8uNwHrsH\n\tQqPa0VWQE9e8O17b8W36l+8+REzuSlhH7LD1AAII="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"D0e6CigT\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<CAEmqJPpMYEV04edpCfcNE4QqMaKgV3EpXXqHf5k-YVQGWGuXLg@mail.gmail.com>","References":"<20230626143932.18888-1-naush@raspberrypi.com>\n\t<169565353019.3049594.7031362347558201747@ping.linuxembedded.co.uk>\n\t<CAEmqJPpMYEV04edpCfcNE4QqMaKgV3EpXXqHf5k-YVQGWGuXLg@mail.gmail.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Date":"Mon, 25 Sep 2023 16:19:58 +0100","Message-ID":"<169565519874.2427060.6402917833810187049@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v2] ipa: rpi: imx296: Enable embedded\n\tdata","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":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]