From patchwork Sat Aug 22 13:35:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9358 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8A941BD87C for ; Sat, 22 Aug 2020 13:36:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0DEF461080; Sat, 22 Aug 2020 15:36:08 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="h4q3cf7d"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E02F261080 for ; Sat, 22 Aug 2020 15:36:06 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0D89D29E for ; Sat, 22 Aug 2020 15:36:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1598103363; bh=cro4Su5I33BT9oKeHYt2CSWe1Jy7CQMX+nRiI5JWHgg=; h=From:To:Subject:Date:From; b=h4q3cf7d5aZb18IGlTfBkebIQgTBcKSO73q+mlFq8yY7edAYxqAFgpiArr9DPE0ov 3yp3S6/9FJ0cV6xecIuTcxHnMVg1mISGISJA7CXF3VC1+ZHnaQ4dGSj/P5TtlWEMh7 ALhdN/F2Aj1v0br5M474Lgc0OmRZtMO4ec9qnAKs= From: Laurent Pinchart 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Print the timestamp of the captured buffer in addition to the frame rate, as this is more precise information that can help debugging issue. While at it, compute the frame rate on the buffer timestamps instead of sampling the clock in the request completion handler. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- src/cam/capture.cpp | 18 +++++++++++------- src/cam/capture.h | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp index af9029b743de..5510c009ca57 100644 --- a/src/cam/capture.cpp +++ b/src/cam/capture.cpp @@ -5,7 +5,6 @@ * capture.cpp - Cam capture */ -#include #include #include #include @@ -159,14 +158,19 @@ void Capture::requestComplete(Request *request) const Request::BufferMap &buffers = request->buffers(); - std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); - double fps = std::chrono::duration_cast(now - last_).count(); - fps = last_ != std::chrono::steady_clock::time_point() && fps - ? 1000.0 / fps : 0.0; - last_ = now; + /* + * Compute the frame rate. The timestamp is arbitrarily retrieved from + * the first buffer, as all buffers should have matching timestamps. + */ + uint64_t ts = buffers.begin()->second->metadata().timestamp; + double fps = ts - last_; + fps = last_ != 0 && fps ? 1000000000.0 / fps : 0.0; + last_ = ts; std::stringstream info; - info << "fps: " << std::fixed << std::setprecision(2) << fps; + info << ts / 1000000000 << "." + << std::setw(6) << std::setfill('0') << ts / 1000 % 1000000 + << " (" << std::fixed << std::setprecision(2) << fps << " fps)"; for (auto it = buffers.begin(); it != buffers.end(); ++it) { const Stream *stream = it->first; diff --git a/src/cam/capture.h b/src/cam/capture.h index b4e39d51fdfa..0aebdac944cf 100644 --- a/src/cam/capture.h +++ b/src/cam/capture.h @@ -7,8 +7,8 @@ #ifndef __CAM_CAPTURE_H__ #define __CAM_CAPTURE_H__ -#include #include +#include #include #include @@ -38,7 +38,7 @@ private: std::map streamName_; BufferWriter *writer_; - std::chrono::steady_clock::time_point last_; + uint64_t last_; EventLoop *loop_; unsigned int captureCount_;