{"id":1965,"url":"https://patchwork.libcamera.org/api/1.1/patches/1965/?format=json","web_url":"https://patchwork.libcamera.org/patch/1965/","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":"<20190914005457.16926-1-laurent.pinchart@ideasonboard.com>","date":"2019-09-14T00:54:56","name":"[libcamera-devel,1/2] libcamera: utils: Add clock helpers","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"e1ba812553fac617b691ca3d6596b834d42af336","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1965/mbox/","series":[{"id":489,"url":"https://patchwork.libcamera.org/api/1.1/series/489/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=489","date":"2019-09-14T00:54:56","name":"[libcamera-devel,1/2] libcamera: utils: Add clock helpers","version":1,"mbox":"https://patchwork.libcamera.org/series/489/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1965/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1965/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F43C600E9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 14 Sep 2019 02:55:13 +0200 (CEST)","from pendragon.lan (bl10-204-24.dsl.telepac.pt [85.243.204.24])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4A8C12DB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 14 Sep 2019 02:55:12 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1568422513;\n\tbh=ld3KQjRs/cuBqAj1qCZazqmBMF8jmGfvEidrHcu8Uwk=;\n\th=From:To:Subject:Date:From;\n\tb=FJisVzShhFIY51Pa1lY3NdZPOyQgnG3SkoCm+bFuMGyeNaCJGUe4Ns+yibzJ8ulKW\n\tAkd11kg5qNJtMWjS40PsMn6crHwEo+pE4mTekoveSzoMYwlC7HJK8YoxamcR/bx4ML\n\twyR8f2oupW0v0BStjuICmQS1SFh/aJMg4y8VHC+E=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 14 Sep 2019 03:54:56 +0300","Message-Id":"<20190914005457.16926-1-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.21.0","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 1/2] libcamera: utils: Add clock helpers","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Sat, 14 Sep 2019 00:55:13 -0000"},"content":"In preparation for standardisation of the std::chrono::steady_clock as\nthe libcamera default clock, define aliases for the clock, duration and\ntime point, and add helper functions to convert a duration to a timespec\nand a time point to a string. More helpers will be added later as\nneeded.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/utils.h | 10 +++++++\n src/libcamera/utils.cpp       | 50 +++++++++++++++++++++++++++++++++++\n 2 files changed, 60 insertions(+)","diff":"diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h\nindex 47a422587338..52eee8ac2804 100644\n--- a/src/libcamera/include/utils.h\n+++ b/src/libcamera/include/utils.h\n@@ -8,7 +8,10 @@\n #define __LIBCAMERA_UTILS_H__\n \n #include <algorithm>\n+#include <chrono>\n #include <memory>\n+#include <string>\n+#include <sys/time.h>\n \n #define ARRAY_SIZE(a)\t(sizeof(a) / sizeof(a[0]))\n \n@@ -53,6 +56,13 @@ const T& clamp(const T& v, const T& lo, const T& hi)\n \treturn std::max(lo, std::min(v, hi));\n }\n \n+using clock = std::chrono::steady_clock;\n+using duration = std::chrono::steady_clock::duration;\n+using time_point = std::chrono::steady_clock::time_point;\n+\n+struct timespec duration_to_timespec(const duration &value);\n+std::string time_point_to_string(const time_point &time);\n+\n } /* namespace utils */\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\nindex afbdd8349790..fe7ec53302a3 100644\n--- a/src/libcamera/utils.cpp\n+++ b/src/libcamera/utils.cpp\n@@ -7,6 +7,8 @@\n \n #include \"utils.h\"\n \n+#include <iomanip>\n+#include <sstream>\n #include <stdlib.h>\n #include <string.h>\n #include <unistd.h>\n@@ -93,6 +95,54 @@ char *secure_getenv(const char *name)\n  * \\return lo if v is less than lo, hi if v is greater than hi, otherwise v\n  */\n \n+/**\n+ * \\typedef clock\n+ * \\brief The libcamera clock (monotonous)\n+ */\n+\n+/**\n+ * \\typedef duration\n+ * \\brief The libcamera duration related to libcamera::utils::clock\n+ */\n+\n+/**\n+ * \\typedef time_point\n+ * \\brief The libcamera time point related to libcamera::utils::clock\n+ */\n+\n+/**\n+ * \\brief Convert a duration to a timespec\n+ * \\param[in] value The duration\n+ * \\return A timespec expressing the duration\n+ */\n+struct timespec duration_to_timespec(const duration &value)\n+{\n+\tuint64_t nsecs = std::chrono::duration_cast<std::chrono::nanoseconds>(value).count();\n+\tstruct timespec ts;\n+\tts.tv_sec = nsecs / 1000000000ULL;\n+\tts.tv_nsec = nsecs % 1000000000ULL;\n+\treturn ts;\n+}\n+\n+/**\n+ * \\brief Convert a time point to a string representation\n+ * \\param[in] time The time point\n+ * \\return A string representing the time point in hh:mm:ss.nanoseconds format\n+ */\n+std::string time_point_to_string(const time_point &time)\n+{\n+\tuint64_t nsecs = std::chrono::duration_cast<std::chrono::nanoseconds>(time.time_since_epoch()).count();\n+\tunsigned int secs = nsecs / 1000000000ULL;\n+\n+\tstd::ostringstream ossTimestamp;\n+\tossTimestamp.fill('0');\n+\tossTimestamp << secs / (60 * 60) << \":\"\n+\t\t     << std::setw(2) << (secs / 60) % 60 << \":\"\n+\t\t     << std::setw(2) << secs % 60 << \".\"\n+\t\t     << std::setw(9) << nsecs % 1000000000ULL;\n+\treturn ossTimestamp.str();\n+}\n+\n } /* namespace utils */\n \n } /* namespace libcamera */\n","prefixes":["libcamera-devel","1/2"]}