{"id":12374,"url":"https://patchwork.libcamera.org/api/1.1/patches/12374/?format=json","web_url":"https://patchwork.libcamera.org/patch/12374/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20210524084822.3690690-2-naush@raspberrypi.com>","date":"2021-05-24T08:48:19","name":"[libcamera-devel,v4,1/4] libcamera: utils: Add helper class for std::chrono::duration","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"5a10b3689f631f501f5a024c07f7bb7c20041733","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/12374/mbox/","series":[{"id":2052,"url":"https://patchwork.libcamera.org/api/1.1/series/2052/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2052","date":"2021-05-24T08:48:18","name":"Switch RaspberryPi IPA to use std::chrono::duration","version":4,"mbox":"https://patchwork.libcamera.org/series/2052/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12374/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12374/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 1CB55C3201\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 May 2021 08:48:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1EDD268923;\n\tMon, 24 May 2021 10:48:31 +0200 (CEST)","from mail-wr1-x436.google.com (mail-wr1-x436.google.com\n\t[IPv6:2a00:1450:4864:20::436])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AF5D46050E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 May 2021 10:48:29 +0200 (CEST)","by mail-wr1-x436.google.com with SMTP id d11so27637446wrw.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 May 2021 01:48:29 -0700 (PDT)","from naush-laptop.pitowers.org\n\t([2a00:1098:3142:14:4bf6:b415:2edf:916a])\n\tby smtp.gmail.com with ESMTPSA id\n\tx10sm11275767wrt.65.2021.05.24.01.48.28\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 24 May 2021 01:48:28 -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=\"s5YhR00A\"; 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=W+Swnp6RToqrqm1MpiH1WAAxqrpawJsMhjuvrg/Bpy8=;\n\tb=s5YhR00AAut7k7172eUJ0yNQbeL+R/YX4SD4qL1/rGp3nQRJ4OyNzi7FBYmuNODIml\n\tdrG0hfkQzzVfRIlR0vy91WVuNPiByGyLJc53oijMmcyvPK0szIuIxU3lGLsBtnw2b9Ys\n\t3UL8I8061QmN1yNuodE+G/zdgaW49CpoYnhS5woE+ep2J2UmLIZDhL2oi+woDMcU0Czk\n\tPwBDyNCU/hf1c0APeJphU+W2/jr0un5Z5omlv0S9G7kDjH7potnPnU9Zhgy/v+7KC0CP\n\tGw0Y09cIRMF44O7oOgRz9lahEFZTpkhlSY98BE1PxhyTuNJsHVvdoP3wn/jvImPb0a1u\n\tqnjQ==","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=W+Swnp6RToqrqm1MpiH1WAAxqrpawJsMhjuvrg/Bpy8=;\n\tb=ICtO6vkytBaTCMeH0y5IOdIButQwuFHMTYyMkKrBQIuIKcbXf7beDu9BDWTmPftjj7\n\to5QG9cIk0LhxPag+dro96a8yUMpnaOYY1rSwQ7XWh+tXKFb8iQTu4sEz5zkvviUisATa\n\tsO40EigRWZvIBKwwbt3oqUEnogPrLOsqS9LCnaITonKEMy4BVOdIpdXE8fP9GEVqpXS4\n\tGGfZs0mZosczQ+vkLEqUfSAfPMHDuicF+AR9akC7KGlSuDAj2qqXSko7c3qiPUe8tKDF\n\t4rNPd4T5hSB41BKrnfQz7AzrCnFSs0CsW/f2ov9X5DNvYpJZT0HrQXdiNxJx8J8P7jU5\n\tuExQ==","X-Gm-Message-State":"AOAM530RQQw8LXNvCqLxH3F77q+sMXo+qtYwp2JMYumNPAjZkopUIDNM\n\txVerQH7oEtkHcf5FiZKHCTuCEdhmKoO3Qg==","X-Google-Smtp-Source":"ABdhPJwSBR28nHMwJh23RfYa0lYF1wKwpBeVt7IMPfOl98rHfc01Zr2UUBYfDPLv/QGzFq7itYBPnw==","X-Received":"by 2002:a05:6000:24f:: with SMTP id\n\tm15mr21809869wrz.338.1621846109199; \n\tMon, 24 May 2021 01:48:29 -0700 (PDT)","From":"Naushir Patuck <naush@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 24 May 2021 09:48:19 +0100","Message-Id":"<20210524084822.3690690-2-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20210524084822.3690690-1-naush@raspberrypi.com>","References":"<20210524084822.3690690-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 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>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n---\n include/libcamera/internal/utils.h | 42 ++++++++++++++++++++++++++++++\n src/libcamera/utils.cpp            | 41 +++++++++++++++++++++++++++++\n 2 files changed, 83 insertions(+)","diff":"diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h\nindex 83dada7cc16c..f536f2267d70 100644\n--- a/include/libcamera/internal/utils.h\n+++ b/include/libcamera/internal/utils.h\n@@ -316,8 +316,50 @@ auto enumerate(T (&iterable)[N]) -> details::enumerate_adapter<T *>\n }\n #endif\n \n+class Duration : public std::chrono::duration<double, std::nano>\n+{\n+\tusing BaseDuration = std::chrono::duration<double, std::nano>;\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 } /* namespace utils */\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 utils::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 libcamera */\n \n #endif /* __LIBCAMERA_INTERNAL_UTILS_H__ */\ndiff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\nindex 826144d3c837..480284c6c2c9 100644\n--- a/src/libcamera/utils.cpp\n+++ b/src/libcamera/utils.cpp\n@@ -506,6 +506,47 @@ std::string libcameraSourcePath()\n  * loop, iterates over an indexed view of the \\a iterable\n  */\n \n+/**\n+ * \\class Duration\n+ * \\brief Helper class for std::chrono::duration types\n+ */\n+\n+/**\n+ * \\typedef Duration::BaseDuration\n+ * \\brief Base struct for the \\a Duration helper class\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+ * internally converting the representation to \\a Duration::BaseDuration type\n+ */\n+\n+/**\n+ * \\fn Duration::get<Period>()\n+ * \\brief Retrieve the tick count, converted 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 The tick count of the Duration expressed in \\a Period\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","v4","1/4"]}