Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp270141imm; Tue, 9 Oct 2018 17:56:21 -0700 (PDT) X-Google-Smtp-Source: ACcGV62M/dGSs6pIRkVJv/kr8vHwnr1l2LiUXBJg7gs/tk5F6Yiib94zrb7v+KbkTT02sjd9sJAx X-Received: by 2002:a17:902:8ec2:: with SMTP id x2-v6mr31138181plo.157.1539132981704; Tue, 09 Oct 2018 17:56:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539132981; cv=none; d=google.com; s=arc-20160816; b=oSTqIF8+oX1dV1sJxPuHAtTQ+omVjSj0Yv4FjT6dZnf8tjZcCSqm5bjQKGYjhVeQGh X/UiWxcLb9W+VfVL4WoITjVNjSpieWDoNvXbVzHjF9L1jdPBvgfu7RPW5BDfzn1bYJH9 4eX9W7tZIsa4SbVqATi7i9VSsw7KoBvjeZy/yQcbgt8pr6rAip+gZfNY0bucWN0PGTer S5gECH8JuyPQ+EHbQxtj3eVxxZx7DDZP1la9QtiVJ8LOBY6Ckw2R5ZDGosrI+x/h2tzT JvyUdR0c+XmBC4e/rpg3dvPwPkc+e2bscix+Rgq8g4ZlzWErGGbXG7jLyq8izq7lEszv a47w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=S/y2QgbBWQ1jkuNfRAfJafUQ0B5BUpKTSPeonJXg4yU=; b=LeqdtgOqpFDOIUMz9oPriGmpQXwkbgbjXT3LehUN5l8ORRUfufppFegjtd1bW5icDT SthGSq4g9M2x+Hu+yo9+peFBe8iZEOJiPmWRVYtzluWoHoDvF+9PbHdPZ/xGMSegm1AO R4gCj8/sJpW2Y1KwHwrgyHtc0q2F/3DTYyt07lWLeG13Tyfx8uM73+CEpuFV3SCajdwo ZoN6rpW5JmIe045YWN8d5toDKeHKPpY3jaFPUwLnau2mcAOjolwYa4RCOzNe9kksi7Aa N3POJDLsnc/SXp9WOA+qnAuo3VQ+eUK51uz++Z63juL6LzayAg9uWI9XN2tLvPIugciV QHcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=A5S+egAE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11-v6si20622932pgi.121.2018.10.09.17.56.06; Tue, 09 Oct 2018 17:56:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=A5S+egAE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726897AbeJJII7 (ORCPT + 99 others); Wed, 10 Oct 2018 04:08:59 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:41840 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725860AbeJJII7 (ORCPT ); Wed, 10 Oct 2018 04:08:59 -0400 Received: by mail-qk1-f196.google.com with SMTP id 23-v6so2178273qkh.8; Tue, 09 Oct 2018 17:49:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=S/y2QgbBWQ1jkuNfRAfJafUQ0B5BUpKTSPeonJXg4yU=; b=A5S+egAEDwLKARBsSYBK1PTB6a9F0a8mzeHewhKP4vwPyGqz/qjrOl6SEsOXt+jiWQ r6n4rvuJz4q3cuUhpj+zAwcileb567/fhfbQDSCNoD1hxZGqzRW/Ly98nalAeao9H4jo SwPAyTi+SXK1TnbU5ts91ZQirOeWRMJoRwxiF9rmOsI0DjudZXlR1p7gCCFVFAQT6VrF yhlpB1wTD3U2FG9CP5vXFDdLSy9e2ANLmShggoYWdJrYz75Owlniq3j6sRNGRGmMky4i pjP4lV6Pj8O7Bbrp7O2weqcheRpEC8FzHeHWomwnPdwqv5ZcNUy1os6G+RsVeWnOYLi2 wQSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=S/y2QgbBWQ1jkuNfRAfJafUQ0B5BUpKTSPeonJXg4yU=; b=fWeXSwpDr1JxbHzH5EPL8iqQ+U6stO3NOH3WmJfj+OgzkCzLwkzTIk+W2ZErsbZGlu 5n0YMxAMh0p+r5pMO9L+U2BKKxiU1ffW7cLms0L2CmbUGcRKQ/hku993K8NBA4F6ZwpY yOfSdFqYlQWynolSKH17Vs1HgOxAarp6S1F1ll/CU+UC733PyXYlyLtM7Zw+PgbMmnws YS+OdnvN/+E0/WIzPeY65yR+0f42uEznBje6tYGpyyBJZzzu72d8RdZcKW8KMclvJq5L iGYUxzGjRl6qFBOhbSGdBzFYHvNH/OlKkBSU95keEq3mN3XDJCqv0KMZiDkWOio4tqtN +ylA== X-Gm-Message-State: ABuFfohXma3+IAcofIhYgR7ZFtGB1QvqdIqV0qqeSp75pDfcONnZs9Z4 uclfPkzc5SJxNbZOIAB7tiE= X-Received: by 2002:a37:5003:: with SMTP id e3-v6mr13630512qkb.102.1539132564852; Tue, 09 Oct 2018 17:49:24 -0700 (PDT) Received: from gfm-note (wifi-177-220-84-73.wifi.ic.unicamp.br. [177.220.84.73]) by smtp.gmail.com with ESMTPSA id i27-v6sm12708827qti.57.2018.10.09.17.49.24 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 17:49:24 -0700 (PDT) Date: Tue, 9 Oct 2018 21:49:21 -0300 From: Gabriel Francisco Mandaji To: Hans Verkuil , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: lkcamp@lists.libreplanetbr.org Subject: [PATCH] media: vivid: Improve timestamping Message-ID: <20181010004921.GA6532@gfm-note> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Simulate a more precise timestamp by calculating it based on the current framerate. Signed-off-by: Gabriel Francisco Mandaji --- drivers/media/platform/vivid/vivid-core.h | 1 + drivers/media/platform/vivid/vivid-kthread-cap.c | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/vivid/vivid-core.h b/drivers/media/platform/vivid/vivid-core.h index cd4c823..cbdadd8 100644 --- a/drivers/media/platform/vivid/vivid-core.h +++ b/drivers/media/platform/vivid/vivid-core.h @@ -384,6 +384,7 @@ struct vivid_dev { /* thread for generating video capture stream */ struct task_struct *kthread_vid_cap; unsigned long jiffies_vid_cap; + u64 cap_stream_start; u32 cap_seq_offset; u32 cap_seq_count; bool cap_seq_resync; diff --git a/drivers/media/platform/vivid/vivid-kthread-cap.c b/drivers/media/platform/vivid/vivid-kthread-cap.c index f06003b..0793b15 100644 --- a/drivers/media/platform/vivid/vivid-kthread-cap.c +++ b/drivers/media/platform/vivid/vivid-kthread-cap.c @@ -416,6 +416,7 @@ static void vivid_fillbuff(struct vivid_dev *dev, struct vivid_buffer *buf) char str[100]; s32 gain; bool is_loop = false; + u64 soe_time = 0; if (dev->loop_video && dev->can_loop_video && ((vivid_is_svid_cap(dev) && @@ -426,11 +427,11 @@ static void vivid_fillbuff(struct vivid_dev *dev, struct vivid_buffer *buf) buf->vb.sequence = dev->vid_cap_seq_count; /* - * Take the timestamp now if the timestamp source is set to - * "Start of Exposure". + * Store the current time to calculate the delta if source is set to + * "End of Frame". */ - if (dev->tstamp_src_is_soe) - buf->vb.vb2_buf.timestamp = ktime_get_ns(); + if (!dev->tstamp_src_is_soe) + soe_time = ktime_get_ns(); if (dev->field_cap == V4L2_FIELD_ALTERNATE) { /* * 60 Hz standards start with the bottom field, 50 Hz standards @@ -556,12 +557,18 @@ static void vivid_fillbuff(struct vivid_dev *dev, struct vivid_buffer *buf) } /* - * If "End of Frame" is specified at the timestamp source, then take - * the timestamp now. + * If "End of Frame", then calculate the "exposition time" and add + * it to the timestamp. */ if (!dev->tstamp_src_is_soe) - buf->vb.vb2_buf.timestamp = ktime_get_ns(); - buf->vb.vb2_buf.timestamp += dev->time_wrap_offset; + soe_time = ktime_get_ns() - soe_time; + buf->vb.vb2_buf.timestamp = dev->timeperframe_vid_cap.numerator * + 1000000000 / + dev->timeperframe_vid_cap.denominator * + dev->vid_cap_seq_count + + dev->cap_stream_start + + soe_time + + dev->time_wrap_offset; } /* @@ -759,6 +766,7 @@ static int vivid_thread_vid_cap(void *data) dev->cap_seq_count = 0; dev->cap_seq_resync = false; dev->jiffies_vid_cap = jiffies; + dev->cap_stream_start = ktime_get_ns(); for (;;) { try_to_freeze(); -- 1.9.1