Show a patch.

GET /api/patches/17730/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 17730,
    "url": "https://patchwork.libcamera.org/api/patches/17730/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17730/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20221030230500.74842-2-nicholas@rothemail.net>",
    "date": "2022-10-30T23:04:56",
    "name": "[libcamera-devel,v6,1/5] ipa: workaround libcxx duration limitation",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "ab7e2b59a6d5a2e3fd512d58c53fb228bbb2e4dd",
    "submitter": {
        "id": 137,
        "url": "https://patchwork.libcamera.org/api/people/137/?format=api",
        "name": "Nicholas Roth",
        "email": "nicholas@rothemail.net"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/17730/mbox/",
    "series": [
        {
            "id": 3589,
            "url": "https://patchwork.libcamera.org/api/series/3589/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3589",
            "date": "2022-10-30T23:04:56",
            "name": "[libcamera-devel,v6,1/5] ipa: workaround libcxx duration limitation",
            "version": 6,
            "mbox": "https://patchwork.libcamera.org/series/3589/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17730/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17730/checks/",
    "tags": {},
    "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 D293ABD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 30 Oct 2022 23:05:19 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 92DA463031;\n\tMon, 31 Oct 2022 00:05:19 +0100 (CET)",
            "from mail-oi1-x231.google.com (mail-oi1-x231.google.com\n\t[IPv6:2607:f8b0:4864:20::231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 812A462FFC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 31 Oct 2022 00:05:18 +0100 (CET)",
            "by mail-oi1-x231.google.com with SMTP id v81so2719568oie.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 30 Oct 2022 16:05:18 -0700 (PDT)",
            "from nroth-pc.attlocal.net\n\t(104-5-61-214.lightspeed.austtx.sbcglobal.net. [104.5.61.214])\n\tby smtp.gmail.com with ESMTPSA id\n\tu4-20020a056871008400b0013c8ae74a14sm2269403oaa.42.2022.10.30.16.05.16\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSun, 30 Oct 2022 16:05:16 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1667171119;\n\tbh=1hsrjbrde8bBvjHQnOynnU9Y5CWmkye0DmPEbQouXzI=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=MTJTszaQJxAr1A5fSvAtM6iAxCiqrsWE0OsjPQ6O6GiPcxAycA/K/aS8z9jUbUprF\n\ti7gmn26kjuhMQKddRsNvwQe3O638Wz/88PHTodQs477EpygesN54dqQFVq69fVC802\n\tXqEHNu1DrVzCJL225spih63D8ui9lyHx7nh6LPXvqJM+mQ/wgQ8tzBo73FDwxcnXG0\n\t/4ef6jbVy5ssNajeidvlZ3Fkns7EnNCXzy5Atll95EVedmZDqKoccky+ja5g5GP4mA\n\t/PsoAb5f/txtKegSPXUpkSIkycX0+hFo3kObExNZV10LlL7bbanvbvzUewH2gpytDs\n\toz3DAajzIfHXQ==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=rothemail-net.20210112.gappssmtp.com; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=T3FmDHIMAFBus0uMqBXIYh9g2aFEhrbzsIVmVSsen3U=;\n\tb=U1WyLQu5SJT9DZ6D98NiBDUCzSL0QAXaER9k9RuM/JY9IGYW4X5DHTMxyH3zs49U/P\n\tFCoH1yh/2q5qoHsmpBSQaJIkjaDrWmJNMnbKALLYixsTrrrTdKGcFTYdwzzQUxffnyv1\n\t4ObTDVzSWu4WXKL69YY0x0XfEH8QZKiziShUx3id+1m+M18ifnhJgwLpov2qx0KjTSxK\n\tWpY5pHwSUpT5q6XIvoAhbmFjG1kk7o2rJue2E1sVMN6jNk3Qgp1ZALHi6QExDqyt6khN\n\t9Fxc5pvwPtReMxorGlZ/mYT0puJEkt1Junjqks4egF+Qwy160FdIqoFHUou+NVZgfMnB\n\tJryA=="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=rothemail-net.20210112.gappssmtp.com\n\theader.i=@rothemail-net.20210112.gappssmtp.com header.b=\"U1WyLQu5\"; \n\tdkim-atps=neutral",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=T3FmDHIMAFBus0uMqBXIYh9g2aFEhrbzsIVmVSsen3U=;\n\tb=YmWLJNkTwWF7gxbCW/LWmlZyy9q5W7LksTHyEkX0JcVOJDvzwK2h4vhJk9Pu2RJJ+f\n\tf3CqmYSoDCArRI8jEsqbNj3zCWdCtFEL37iJwTSzRZUrQLKYqEuFU1cy+8t7j3qGO2wE\n\tdAdOae6Pb7YY1SxbqDf+VzpnJN2sAvtsp7Hz+dulJVWblVcy0gZQHmK9nWmzjH1A/nU4\n\tWWBFkLHtEkTRq0YjkwWX6OgfxXu3XY3LPG2lPua1eWUR/kg738HZHuHNGuWsOj1XFn4X\n\tNptt7dab7RNfA55aTrwAaxyZNUpbT1+tvmlTcH3p0Gr/+qG8XYLXLCgT4nMV7Wdnvog4\n\trHgw==",
        "X-Gm-Message-State": "ACrzQf1pNbRS47cOX7QKzUV3TcLYyNAwBqL8AgxZPMm8w4ZUJL639LkP\n\tf9THmu3mrZspq8Y9JMlqNf0IaDqz5o4dCA==",
        "X-Google-Smtp-Source": "AMsMyM7m/UKBKAovTEBysw3jYM6bdmWH6zAFRJt8H5ctPfn0pr68N2Y1mCpg181fNvaJt5xpTUpkEQ==",
        "X-Received": "by 2002:a05:6808:1304:b0:354:b62f:a027 with SMTP id\n\ty4-20020a056808130400b00354b62fa027mr5161730oiv.144.1667171116958; \n\tSun, 30 Oct 2022 16:05:16 -0700 (PDT)",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Sun, 30 Oct 2022 18:04:56 -0500",
        "Message-Id": "<20221030230500.74842-2-nicholas@rothemail.net>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20221030230500.74842-1-nicholas@rothemail.net>",
        "References": "<20221030230500.74842-1-nicholas@rothemail.net>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v6 1/5] ipa: workaround libcxx duration\n\tlimitation",
        "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": "Nicholas Roth via libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Nicholas Roth <nicholas@rothemail.net>",
        "Cc": "Nicholas Roth <nicholas@rothemail.net>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "A bug in libcxx [0] used by clang version 11.0.2 is prevalent when\nbuilding libcamera for Android SDK30. This has been fixed and\nintegrated upstream with [1].\n\nAs a workaround, directly cast libcamera::utils::Duration objects to\nstd::chrono::duration when dividing.\n\nAlternatives evaluated:\nConsidered: Enable public inheritance of std::chrono::duration and\noverride operator/ in the class.\nOutcome: Does not fix the original compiler error.\n\nConsidered: Enable public inheritance of std::chrono::duration and\noverride operator/ in the libcamera namespace.\nOutcome: new compiler error:\nld.lld: error: duplicate symbol: libcamera::operator/\n(libcamera::utils::Duration const&, libcamera::utils::Duration const&)\n\nConsidered: Use private inheritance of std::chrono::duration and\nre-implement a pass-through version of each std::chrono::duration\noperator within libcamera::utils::Duration and use template\nmetaprogramming to fix the division operator.\nOutcome: Testing shows that this would introduce substantial\nlimitations, i.e. requring the Duration object to be on the LHS of any\narithmetic operation with other numeric types. This also substantially\nincreases implementation complexity.\n\nConsidered: Extract double values from libcamera::utils::Duration\nobjects and use those to divide.\nOutcome: This creates substantial readability and unit-safety issues.\n\n[0] https://github.com/llvm/llvm-project/issues/40475\n[1] https://github.com/llvm/llvm-project/commit/efa6d803c624f9251d0ab7881122501bb9d27368\nBug: https://bugs.libcamera.org/show_bug.cgi?id=156\n\nSigned-off-by: Nicholas Roth <nicholas@rothemail.net>\n---\n src/ipa/ipu3/algorithms/agc.cpp            | 16 ++++++++++------\n src/ipa/raspberrypi/cam_helper.cpp         |  6 +++---\n src/ipa/raspberrypi/cam_helper_imx296.cpp  |  3 ++-\n src/ipa/raspberrypi/controller/rpi/agc.cpp | 12 ++++++++----\n src/ipa/raspberrypi/controller/rpi/lux.cpp |  3 ++-\n src/ipa/rkisp1/algorithms/agc.cpp          | 12 ++++++++----\n 6 files changed, 33 insertions(+), 19 deletions(-)",
    "diff": "diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nindex b5309bdb..0f85a32e 100644\n--- a/src/ipa/ipu3/algorithms/agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -101,7 +101,8 @@ int Agc::configure(IPAContext &context,\n \n \t/* Configure the default exposure and gain. */\n \tactiveState.agc.gain = std::max(minAnalogueGain_, kMinAnalogueGain);\n-\tactiveState.agc.exposure = 10ms / configuration.sensor.lineDuration;\n+\tactiveState.agc.exposure = 10ms /\n+\t\t\t\tstd::chrono::duration(configuration.sensor.lineDuration);\n \n \tframeCount_ = 0;\n \treturn 0;\n@@ -241,17 +242,20 @@ void Agc::computeExposure(IPAContext &context, IPAFrameContext &frameContext,\n \t * increase the gain.\n \t */\n \tutils::Duration shutterTime =\n-\t\tstd::clamp<utils::Duration>(exposureValue / minAnalogueGain_,\n-\t\t\t\t\t    minShutterSpeed_, maxShutterSpeed_);\n-\tdouble stepGain = std::clamp(exposureValue / shutterTime,\n-\t\t\t\t     minAnalogueGain_, maxAnalogueGain_);\n+\t\tstd::clamp<utils::Duration>(std::chrono::duration(exposureValue) /\n+\t\t\t\t\t\tminAnalogueGain_,\n+\t\t\t\t\tminShutterSpeed_, maxShutterSpeed_);\n+\tdouble stepGain = std::clamp(std::chrono::duration(exposureValue) /\n+\t\t\t\t\tstd::chrono::duration(shutterTime),\n+\t\t\t\tminAnalogueGain_, maxAnalogueGain_);\n \tLOG(IPU3Agc, Debug) << \"Divided up shutter and gain are \"\n \t\t\t    << shutterTime << \" and \"\n \t\t\t    << stepGain;\n \n \tIPAActiveState &activeState = context.activeState;\n \t/* Update the estimated exposure and gain. */\n-\tactiveState.agc.exposure = shutterTime / configuration.sensor.lineDuration;\n+\tactiveState.agc.exposure = std::chrono::duration(shutterTime) /\n+\t\t\t\tstd::chrono::duration(configuration.sensor.lineDuration);\n \tactiveState.agc.gain = stepGain;\n }\n \ndiff --git a/src/ipa/raspberrypi/cam_helper.cpp b/src/ipa/raspberrypi/cam_helper.cpp\nindex d90ac1de..48a8a068 100644\n--- a/src/ipa/raspberrypi/cam_helper.cpp\n+++ b/src/ipa/raspberrypi/cam_helper.cpp\n@@ -63,7 +63,7 @@ void CamHelper::process([[maybe_unused]] StatisticsPtr &stats,\n \n uint32_t CamHelper::exposureLines(const Duration exposure, const Duration lineLength) const\n {\n-\treturn exposure / lineLength;\n+\treturn std::chrono::duration(exposure) / std::chrono::duration(lineLength);\n }\n \n Duration CamHelper::exposure(uint32_t exposureLines, const Duration lineLength) const\n@@ -85,8 +85,8 @@ std::pair<uint32_t, uint32_t> CamHelper::getBlanking(Duration &exposure,\n \t * frameLengthMax gets calculated on the smallest line length as we do\n \t * not want to extend that unless absolutely necessary.\n \t */\n-\tframeLengthMin = minFrameDuration / mode_.minLineLength;\n-\tframeLengthMax = maxFrameDuration / mode_.minLineLength;\n+\tframeLengthMin = std::chrono::duration(minFrameDuration) / std::chrono::duration(mode_.minLineLength);\n+\tframeLengthMax = std::chrono::duration(maxFrameDuration) / std::chrono::duration(mode_.minLineLength);\n \n \t/*\n \t * Watch out for (exposureLines + frameIntegrationDiff_) overflowing a\ndiff --git a/src/ipa/raspberrypi/cam_helper_imx296.cpp b/src/ipa/raspberrypi/cam_helper_imx296.cpp\nindex ecb845e7..c5180de5 100644\n--- a/src/ipa/raspberrypi/cam_helper_imx296.cpp\n+++ b/src/ipa/raspberrypi/cam_helper_imx296.cpp\n@@ -57,7 +57,8 @@ double CamHelperImx296::gain(uint32_t gainCode) const\n uint32_t CamHelperImx296::exposureLines(const Duration exposure,\n \t\t\t\t\t[[maybe_unused]] const Duration lineLength) const\n {\n-\treturn std::max<uint32_t>(minExposureLines, (exposure - 14.26us) / timePerLine);\n+\treturn std::max<uint32_t>(minExposureLines, std::chrono::duration(exposure - 14.26us) /\n+\t\t\t\t\t\t\tstd::chrono::duration(timePerLine));\n }\n \n Duration CamHelperImx296::exposure(uint32_t exposureLines,\ndiff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp\nindex bd54a639..65baab99 100644\n--- a/src/ipa/raspberrypi/controller/rpi/agc.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp\n@@ -418,7 +418,8 @@ void Agc::prepare(Metadata *imageMetadata)\n \t\t\tDuration actualExposure = deviceStatus.shutterSpeed *\n \t\t\t\t\t\t  deviceStatus.analogueGain;\n \t\t\tif (actualExposure) {\n-\t\t\t\tstatus_.digitalGain = status_.totalExposureValue / actualExposure;\n+\t\t\t\tstatus_.digitalGain = std::chrono::duration(status_.totalExposureValue) /\n+\t\t\t\t\t\t\tstd::chrono::duration(actualExposure);\n \t\t\t\tLOG(RPiAgc, Debug) << \"Want total exposure \" << status_.totalExposureValue;\n \t\t\t\t/*\n \t\t\t\t * Never ask for a gain < 1.0, and also impose\n@@ -823,7 +824,8 @@ void Agc::divideUpExposure()\n \t\t\t}\n \t\t\tif (status_.fixedAnalogueGain == 0.0) {\n \t\t\t\tif (exposureMode_->gain[stage] * shutterTime >= exposureValue) {\n-\t\t\t\t\tanalogueGain = exposureValue / shutterTime;\n+\t\t\t\t\tanalogueGain = std::chrono::duration(exposureValue) /\n+\t\t\t\t\t\t\tstd::chrono::duration(shutterTime);\n \t\t\t\t\tbreak;\n \t\t\t\t}\n \t\t\t\tanalogueGain = exposureMode_->gain[stage];\n@@ -838,10 +840,12 @@ void Agc::divideUpExposure()\n \t */\n \tif (!status_.fixedShutter && !status_.fixedAnalogueGain &&\n \t    status_.flickerPeriod) {\n-\t\tint flickerPeriods = shutterTime / status_.flickerPeriod;\n+\t\tint flickerPeriods = std::chrono::duration(shutterTime) /\n+\t\t\t\tstd::chrono::duration(status_.flickerPeriod);\n \t\tif (flickerPeriods) {\n \t\t\tDuration newShutterTime = flickerPeriods * status_.flickerPeriod;\n-\t\t\tanalogueGain *= shutterTime / newShutterTime;\n+\t\t\tanalogueGain *= std::chrono::duration(shutterTime) /\n+\t\t\t\t\tstd::chrono::duration(newShutterTime);\n \t\t\t/*\n \t\t\t * We should still not allow the ag to go over the\n \t\t\t * largest value in the exposure mode. Note that this\ndiff --git a/src/ipa/raspberrypi/controller/rpi/lux.cpp b/src/ipa/raspberrypi/controller/rpi/lux.cpp\nindex 9759186a..410f6f44 100644\n--- a/src/ipa/raspberrypi/controller/rpi/lux.cpp\n+++ b/src/ipa/raspberrypi/controller/rpi/lux.cpp\n@@ -94,7 +94,8 @@ void Lux::process(StatisticsPtr &stats, Metadata *imageMetadata)\n \t\tdouble currentY = sum / (double)num + .5;\n \t\tdouble gainRatio = referenceGain_ / currentGain;\n \t\tdouble shutterSpeedRatio =\n-\t\t\treferenceShutterSpeed_ / deviceStatus.shutterSpeed;\n+\t\t\tstd::chrono::duration(referenceShutterSpeed_) /\n+\t\t\tstd::chrono::duration(deviceStatus.shutterSpeed);\n \t\tdouble apertureRatio = referenceAperture_ / currentAperture;\n \t\tdouble yRatio = currentY * (65536 / numBins) / referenceY_;\n \t\tdouble estimatedLux = shutterSpeedRatio * gainRatio *\ndiff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\nindex b4fc7aed..e0192729 100644\n--- a/src/ipa/rkisp1/algorithms/agc.cpp\n+++ b/src/ipa/rkisp1/algorithms/agc.cpp\n@@ -75,7 +75,8 @@ int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)\n {\n \t/* Configure the default exposure and gain. */\n \tcontext.activeState.agc.gain = std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain);\n-\tcontext.activeState.agc.exposure = 10ms / context.configuration.sensor.lineDuration;\n+\tcontext.activeState.agc.exposure = 10ms /\n+\t\t\t\t\tstd::chrono::duration(context.configuration.sensor.lineDuration);\n \n \t/*\n \t * According to the RkISP1 documentation:\n@@ -213,16 +214,19 @@ void Agc::computeExposure(IPAContext &context, IPAFrameContext &frameContext,\n \t * Push the shutter time up to the maximum first, and only then\n \t * increase the gain.\n \t */\n-\tutils::Duration shutterTime = std::clamp<utils::Duration>(exposureValue / minAnalogueGain,\n+\tutils::Duration shutterTime = std::clamp<utils::Duration>(std::chrono::duration(exposureValue) /\n+\t\t\t\t\t\t\t\t\tminAnalogueGain,\n \t\t\t\t\t\t\t\t  minShutterSpeed, maxShutterSpeed);\n-\tdouble stepGain = std::clamp(exposureValue / shutterTime,\n+\tdouble stepGain = std::clamp(std::chrono::duration(exposureValue) /\n+\t\t\t\t\t\tstd::chrono::duration(shutterTime),\n \t\t\t\t     minAnalogueGain, maxAnalogueGain);\n \tLOG(RkISP1Agc, Debug) << \"Divided up shutter and gain are \"\n \t\t\t      << shutterTime << \" and \"\n \t\t\t      << stepGain;\n \n \t/* Update the estimated exposure and gain. */\n-\tactiveState.agc.exposure = shutterTime / configuration.sensor.lineDuration;\n+\tactiveState.agc.exposure = std::chrono::duration(shutterTime) /\n+\t\t\t\tstd::chrono::duration(configuration.sensor.lineDuration);\n \tactiveState.agc.gain = stepGain;\n }\n \n",
    "prefixes": [
        "libcamera-devel",
        "v6",
        "1/5"
    ]
}