{"id":9358,"url":"https://patchwork.libcamera.org/api/1.1/patches/9358/?format=json","web_url":"https://patchwork.libcamera.org/patch/9358/","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":"<20200822133542.15612-1-laurent.pinchart@ideasonboard.com>","date":"2020-08-22T13:35:42","name":"[libcamera-devel] cam: Print timestamp of captured buffers","commit_ref":"da3c15c3de74d7d8e6b26a9725729cc32c1625f6","pull_url":null,"state":"accepted","archived":false,"hash":"64462c5f04b14f874d9180535f56c8b9b0a8824d","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/9358/mbox/","series":[{"id":1230,"url":"https://patchwork.libcamera.org/api/1.1/series/1230/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1230","date":"2020-08-22T13:35:42","name":"[libcamera-devel] cam: Print timestamp of captured buffers","version":1,"mbox":"https://patchwork.libcamera.org/series/1230/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9358/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9358/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 8A941BD87C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 22 Aug 2020 13:36:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0DEF461080;\n\tSat, 22 Aug 2020 15:36:08 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E02F261080\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 22 Aug 2020 15:36:06 +0200 (CEST)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0D89D29E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 22 Aug 2020 15:36:02 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"h4q3cf7d\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1598103363;\n\tbh=cro4Su5I33BT9oKeHYt2CSWe1Jy7CQMX+nRiI5JWHgg=;\n\th=From:To:Subject:Date:From;\n\tb=h4q3cf7d5aZb18IGlTfBkebIQgTBcKSO73q+mlFq8yY7edAYxqAFgpiArr9DPE0ov\n\t3yp3S6/9FJ0cV6xecIuTcxHnMVg1mISGISJA7CXF3VC1+ZHnaQ4dGSj/P5TtlWEMh7\n\tALhdN/F2Aj1v0br5M474Lgc0OmRZtMO4ec9qnAKs=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 22 Aug 2020 16:35:42 +0300","Message-Id":"<20200822133542.15612-1-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH] cam: Print timestamp of captured buffers","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Print the timestamp of the captured buffer in addition to the frame\nrate, as this is more precise information that can help debugging issue.\nWhile at it, compute the frame rate on the buffer timestamps instead of\nsampling the clock in the request completion handler.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/cam/capture.cpp | 18 +++++++++++-------\n src/cam/capture.h   |  4 ++--\n 2 files changed, 13 insertions(+), 9 deletions(-)","diff":"diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp\nindex af9029b743de..5510c009ca57 100644\n--- a/src/cam/capture.cpp\n+++ b/src/cam/capture.cpp\n@@ -5,7 +5,6 @@\n  * capture.cpp - Cam capture\n  */\n \n-#include <chrono>\n #include <iomanip>\n #include <iostream>\n #include <limits.h>\n@@ -159,14 +158,19 @@ void Capture::requestComplete(Request *request)\n \n \tconst Request::BufferMap &buffers = request->buffers();\n \n-\tstd::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();\n-\tdouble fps = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_).count();\n-\tfps = last_ != std::chrono::steady_clock::time_point() && fps\n-\t    ? 1000.0 / fps : 0.0;\n-\tlast_ = now;\n+\t/*\n+\t * Compute the frame rate. The timestamp is arbitrarily retrieved from\n+\t * the first buffer, as all buffers should have matching timestamps.\n+\t */\n+\tuint64_t ts = buffers.begin()->second->metadata().timestamp;\n+\tdouble fps = ts - last_;\n+\tfps = last_ != 0 && fps ? 1000000000.0 / fps : 0.0;\n+\tlast_ = ts;\n \n \tstd::stringstream info;\n-\tinfo << \"fps: \" << std::fixed << std::setprecision(2) << fps;\n+\tinfo << ts / 1000000000 << \".\"\n+\t     << std::setw(6) << std::setfill('0') << ts / 1000 % 1000000\n+\t     << \" (\" << std::fixed << std::setprecision(2) << fps << \" fps)\";\n \n \tfor (auto it = buffers.begin(); it != buffers.end(); ++it) {\n \t\tconst Stream *stream = it->first;\ndiff --git a/src/cam/capture.h b/src/cam/capture.h\nindex b4e39d51fdfa..0aebdac944cf 100644\n--- a/src/cam/capture.h\n+++ b/src/cam/capture.h\n@@ -7,8 +7,8 @@\n #ifndef __CAM_CAPTURE_H__\n #define __CAM_CAPTURE_H__\n \n-#include <chrono>\n #include <memory>\n+#include <stdint.h>\n \n #include <libcamera/buffer.h>\n #include <libcamera/camera.h>\n@@ -38,7 +38,7 @@ private:\n \n \tstd::map<const libcamera::Stream *, std::string> streamName_;\n \tBufferWriter *writer_;\n-\tstd::chrono::steady_clock::time_point last_;\n+\tuint64_t last_;\n \n \tEventLoop *loop_;\n \tunsigned int captureCount_;\n","prefixes":["libcamera-devel"]}