From patchwork Thu Jun 30 00:02:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16441 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 AD4CFBD808 for ; Thu, 30 Jun 2022 00:03:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2D9716564D; Thu, 30 Jun 2022 02:03:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656547406; bh=QuupnKHlYQE/5OxuJDMjEmlGrudsBuJBHh3NT/jjrOM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=BZlD44eRDOsslesKRGJpceMrsuy3O4//Z/eaqh2zqhNTa28SLCkX0NswTV2+ETDjs Mq3z7OLJoA59acv2t+9zQtjtsVIdjkRNArxhjQE//Gzf+dgBZSxL+L/krCE8+etBfA QNp4Xwskjf8O/dk/rk+fEsqnZL5ji7kgdb6Z6WtxxMSlNaEmcgCt9mVarFoueoUGfU enKay1OSgbQEjw97ozW1XVUCm2M//2/blSYDjokWevvzzNpcLoMRRDGsRWK7pBQxoT J+rdPngPbQtz2aRwSjgY0B7c/+2NP5s00Uai/NfC1+IR+cxrLpVLNktSoA8m6MmakV vQP6aqI0oX0rA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C3E5D6563E for ; Thu, 30 Jun 2022 02:03:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="I7B36/r8"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5D67059D; Thu, 30 Jun 2022 02:03:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1656547396; bh=QuupnKHlYQE/5OxuJDMjEmlGrudsBuJBHh3NT/jjrOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I7B36/r8xycPeCxeOrhADTG4WrI0BnkKDiJzOR3BrUxXfeVyjLw8feiOINqOhzwPX PDiNaOar6kVlPDcse7kh4L1WUwjnUszmsXrkUqZLImNU/BldsH4HASHaDHOaSWI+As 3Fe69mXqSdLTgd0JJE/rC/Mke/YrD25ZZ9ztW+3Q= To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Jun 2022 03:02:43 +0300 Message-Id: <20220630000251.31295-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220630000251.31295-1-laurent.pinchart@ideasonboard.com> References: <20220630000251.31295-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/12] gstreamer: Move timestamp calculation out of pad loop 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Nicolas Dufresne Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The buffer pts and the pad latency are computed from the framebuffer timestamp, separately for each pad. Use the sensor timestamp provided through the request metadata instead, to compute the values once outside of the pads loop. Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain --- Changes since v1: - Use GST_CLOCK_TIME_NONE and GST_CLOCK_TIME_IS_VALID() --- src/gstreamer/gstlibcamerasrc.cpp | 34 ++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 700bee2bf877..37f201e89828 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -34,6 +34,7 @@ #include #include +#include #include @@ -164,22 +165,35 @@ GstLibcameraSrcState::requestCompleted(Request *request) return; } + GstClockTime latency; + GstClockTime pts; + + if (GST_ELEMENT_CLOCK(src_)) { + int64_t timestamp = request->metadata().get(controls::SensorTimestamp); + + GstClockTime gst_base_time = GST_ELEMENT(src_)->base_time; + GstClockTime gst_now = gst_clock_get_time(GST_ELEMENT_CLOCK(src_)); + /* \todo Need to expose which reference clock the timestamp relates to. */ + GstClockTime sys_now = g_get_monotonic_time() * 1000; + + /* Deduced from: sys_now - sys_base_time == gst_now - gst_base_time */ + GstClockTime sys_base_time = sys_now - (gst_now - gst_base_time); + pts = timestamp - sys_base_time; + latency = sys_now - timestamp; + } else { + latency = 0; + pts = GST_CLOCK_TIME_NONE; + } + for (GstPad *srcpad : srcpads_) { Stream *stream = gst_libcamera_pad_get_stream(srcpad); GstBuffer *buffer = wrap->detachBuffer(stream); FrameBuffer *fb = gst_libcamera_buffer_get_frame_buffer(buffer); - if (GST_ELEMENT_CLOCK(src_)) { - GstClockTime gst_base_time = GST_ELEMENT(src_)->base_time; - GstClockTime gst_now = gst_clock_get_time(GST_ELEMENT_CLOCK(src_)); - /* \todo Need to expose which reference clock the timestamp relates to. */ - GstClockTime sys_now = g_get_monotonic_time() * 1000; - - /* Deduced from: sys_now - sys_base_time == gst_now - gst_base_time */ - GstClockTime sys_base_time = sys_now - (gst_now - gst_base_time); - GST_BUFFER_PTS(buffer) = fb->metadata().timestamp - sys_base_time; - gst_libcamera_pad_set_latency(srcpad, sys_now - fb->metadata().timestamp); + if (GST_CLOCK_TIME_IS_VALID(pts)) { + GST_BUFFER_PTS(buffer) = pts; + gst_libcamera_pad_set_latency(srcpad, latency); } else { GST_BUFFER_PTS(buffer) = 0; }