{"id":12328,"url":"https://patchwork.libcamera.org/api/patches/12328/?format=json","web_url":"https://patchwork.libcamera.org/patch/12328/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210520151714.3366445-2-naush@raspberrypi.com>","date":"2021-05-20T15:17:11","name":"[libcamera-devel,v2,1/4] libcamera: utils: Add helper class for std::chrono::duration","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"e6a3c24c63a4f36fbb983293b580df1a417447d0","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/12328/mbox/","series":[{"id":2039,"url":"https://patchwork.libcamera.org/api/series/2039/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2039","date":"2021-05-20T15:17:10","name":"Switch RaspberryPi IPA to use std::chrono::duration","version":2,"mbox":"https://patchwork.libcamera.org/series/2039/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12328/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12328/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 92BACC31FF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 20 May 2021 15:17:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 53C2F68921;\n\tThu, 20 May 2021 17:17:24 +0200 (CEST)","from mail-wr1-x434.google.com (mail-wr1-x434.google.com\n\t[IPv6:2a00:1450:4864:20::434])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5250668918\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 20 May 2021 17:17:21 +0200 (CEST)","by mail-wr1-x434.google.com with SMTP id c14so16284196wrx.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 20 May 2021 08:17:21 -0700 (PDT)","from naush-laptop.pitowers.org\n\t([2a00:1098:3142:14:de31:dc1f:6be5:f58e])\n\tby smtp.gmail.com with ESMTPSA id\n\ta11sm3583885wrr.48.2021.05.20.08.17.19\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 20 May 2021 08:17:20 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"DjiZ2j8w\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=yRQJD3FtFPwqzHyk8t5WbR7NjNmKo1823QiCzgBqqEg=;\n\tb=DjiZ2j8w32MslxYdfKXyiX1smrL4gVcYnAVXVjSPvCBHqwCr+Kg/N15ELtZ6E+ndqh\n\tq4VaK/5Y3mzvHr7lCTf8Jun4M33k6bSWD1wlygUVuPaz9SktfSP50kvOWwL42So/vyHU\n\tmyxGTJIYxDJ+cV+qZ7PDr5AZf0idsQV1+TDgWa4czSvqPuonP1Eaptzgaw1MV19T/F8E\n\tBuW+nHEnOl3FuK+uxtBtqKElgOVnuFIy6uRTbcDDuX3kfJTvFEdMeO+GX3Pjzzhi1sGI\n\tta45JSQkDkRMnyNaEL6MtBCia5Ie2QSOXR5pbaQaW7AVIy7tK3gsYM6YPWn3JK/DdZbh\n\tCzZA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=yRQJD3FtFPwqzHyk8t5WbR7NjNmKo1823QiCzgBqqEg=;\n\tb=gSe/tNo9YGIrY6EQ/foosSLQKu4spHSx11FNzLBaqxG1QkFSFzev0X8z+O1xj3ZhLz\n\t41nq4qIPNmojhgcNtlkm71kc14gtMkaFXGLlfdSOg+3yrgtSukeNl0W2c3OZ21uv2bQ/\n\tU0XlzU24hUZ5QD4LTgerlqxfi7CqCpqSezz6V5ClPscvdwBx0T0BsW9A37WDVYE7/7Q7\n\tRO3BFmk36jMrqWFIDY0JNrzuAVhKIPIjq04wl76JuosTN2H97NjxlHC89SnBZHjVZQ2c\n\t29RrivT3mEPm6pvUDffJw13MdX7/rXyf7ggM9KTKTdqKAUmnH09cia6EjZxrmeZRDAVB\n\tu9Qg==","X-Gm-Message-State":"AOAM5310kJAV/+Oe9VHmsGhJSCMn6XFM6PVFaDHp1DacWDj02JPpTnPm\n\tmy+TMORSYX7p6frGAPwZxVIydmBOze8j4g==","X-Google-Smtp-Source":"ABdhPJyNAwJGtJiG4m1W95EOsi6KXPfmTWZKOt5OtZlnE+aIEU9/iyIlt5L3KRm6m8+o96WICmDGoQ==","X-Received":"by 2002:a5d:568c:: with SMTP id\n\tf12mr5089525wrv.382.1621523840627; \n\tThu, 20 May 2021 08:17:20 -0700 (PDT)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 20 May 2021 16:17:11 +0100","Message-Id":"<20210520151714.3366445-2-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20210520151714.3366445-1-naush@raspberrypi.com>","References":"<20210520151714.3366445-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 1/4] libcamera: utils: Add helper class\n\tfor std::chrono::duration","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"A new utils::Duration class is defined to represent a\nstd::chrono::duration type with double precision nanosecond timebase.\nUsing a double minimises the loss of precision when converting timebases.\nThis helper class may be used by IPAs to represent variables such as frame\ndurations and exposure times.\n\nAn operator << overload is define to help with displaying\nutils::Duration value in stream objects. Currently, this will display\nthe duration value in microseconds.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n include/libcamera/internal/utils.h | 42 ++++++++++++++++++++++++++++++\n src/libcamera/utils.cpp            | 36 +++++++++++++++++++++++++\n 2 files changed, 78 insertions(+)","diff":"diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h\nindex 83dada7cc16c..a377d4ea07ab 100644\n--- a/include/libcamera/internal/utils.h\n+++ b/include/libcamera/internal/utils.h\n@@ -316,6 +316,48 @@ auto enumerate(T (&iterable)[N]) -> details::enumerate_adapter<T *>\n }\n #endif\n \n+using BaseDuration = std::chrono::duration<double, std::nano>;\n+\n+class Duration : public BaseDuration\n+{\n+public:\n+\tDuration() = default;\n+\n+\ttemplate<typename Rep, typename Period>\n+\tconstexpr Duration(const std::chrono::duration<Rep, Period> &d)\n+\t\t: BaseDuration(d)\n+\t{\n+\t}\n+\n+\ttemplate<typename Period>\n+\tdouble get() const\n+\t{\n+\t\tauto const c = std::chrono::duration_cast<std::chrono::duration<double, Period>>(*this);\n+\t\treturn c.count();\n+\t}\n+\n+\texplicit constexpr operator bool() const\n+\t{\n+\t\treturn *this != BaseDuration::zero();\n+\t}\n+};\n+\n+#ifndef __DOXYGEN__\n+template<class CharT, class Traits>\n+static inline std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits> &os,\n+\t\t\t\t\t\t\t    const Duration &d)\n+{\n+\tstd::basic_ostringstream<CharT, Traits> s;\n+\n+\ts.flags(os.flags());\n+\ts.imbue(os.getloc());\n+\ts.setf(std::ios_base::fixed, std::ios_base::floatfield);\n+\ts.precision(2);\n+\ts << d.get<std::micro>() << \"us\";\n+\treturn os << s.str();\n+}\n+#endif\n+\n } /* namespace utils */\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\nindex 826144d3c837..3131aa2d6666 100644\n--- a/src/libcamera/utils.cpp\n+++ b/src/libcamera/utils.cpp\n@@ -506,6 +506,42 @@ std::string libcameraSourcePath()\n  * loop, iterates over an indexed view of the \\a iterable\n  */\n \n+/**\n+ * \\class Duration\n+ * \\brief Helper for std::chrono::duration types. Derived from \\a BaseDuration\n+ */\n+\n+/**\n+ * \\fn Duration::Duration(const std::chrono::duration<Rep, Period> &d)\n+ * \\brief Copy constructor from a \\a std::chrono::duration type.\n+ * \\param[in] d The std::chrono::duration object to convert from.\n+ *\n+ * Constructs a \\a Duration object from a \\a std::chrono::duration object,\n+ * converting the representation to \\a BaseDuration type.\n+ */\n+\n+/**\n+ * \\fn Duration::get<Period>()\n+ * \\brief Retrieve the tick count, coverted to the timebase provided by the\n+ * template argument Period of type \\a std::ratio.\n+ *\n+ * A typical usage example is given below:\n+ *\n+ * \\code{.cpp}\n+ * utils::Duration d = 5s;\n+ * double d_in_ms = d.get<std::milli>();\n+ * \\endcode\n+ *\n+ * \\return Tick count\n+ */\n+\n+/**\n+ * \\fn Duration::operator bool()\n+ * \\brief Boolean operator to test if a \\a Duration holds a non-zero time value.\n+ *\n+ * \\return True if \\a Duration is a non-zero time value, False otherwise.\n+ */\n+\n } /* namespace utils */\n \n } /* namespace libcamera */\n","prefixes":["libcamera-devel","v2","1/4"]}