Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp295674imm; Tue, 9 Oct 2018 18:26:55 -0700 (PDT) X-Google-Smtp-Source: ACcGV61ohEzBLlHUJU/jseEMj45/B9UWsMiuWc27b5rtE9747dBM/ByY8sRQ6kK1QcbaDAcf9d0u X-Received: by 2002:a17:902:24e7:: with SMTP id l36-v6mr30926461plg.234.1539134815364; Tue, 09 Oct 2018 18:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539134815; cv=none; d=google.com; s=arc-20160816; b=pA7K38MRVQ35DGDSv6vEIn9nWZFX6dTmmIoYF9NC3GGXOJp85tyjfuZJgIZ5Hov6Lr 2Mj1h8eEhYgzHF+/pkNsH2DqdxOVUHON82LBZIR6guZ1ItiLMSF9GNDaow7iuaxH4oSS YQC4qvD/QNmAzmm5Q87bDtdIbZzwKPC1h9zQLn0ysatpDWHsVESg31hQeOS/JBp/nVJq FMxV8BQcg24b2MRHpgwhmD2KN8nMQB5v/Yj5Nx/ukPqUr2enZMY4fuPps5axxHTjoKl5 TBo+z9BkKe5zxC+d1h6xfw7D1777z2sLnTHx7ljm4PiS9ww1zjbguOcdO4fax51vL0DK CkoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject; bh=5aWxahNgHcHmGsGCj9cIga/oKmGaYp6NN0jUK6IrA5M=; b=wJysLs1eGk244JmtTuLLh6T0SHlQ+GE+7phKMXG0GXmqybl1QrjYyYbyrOJRmoTQKp YwKd4aHngFaLdDQbN9YlEcQqggrP2NOtEu+xjRSlI+UfCInNea7WEz2vJWS/XSiqNp7X 2tpi+Do3cRxjPavAYNwSbckmmI3HHvcUOBggqWFhnXSuDEdwJrsegQoO2pqk0M6z1E7U i+rNIETjSBHRzLP71FVl6tG8tYRpIMBQZ+KIDlyYrEA/4AWnpabzkB5Ps9fkVyeAFEbO VVSw2lE62HHlwUCPkpdlhXc/gjK4pEOQ1Mj/qmaL4qgW8p0sdZp2ud7dtKqozzUQCrA3 eFYQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t19-v6si25828193pfm.152.2018.10.09.18.26.40; Tue, 09 Oct 2018 18:26:55 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726689AbeJJIqB (ORCPT + 99 others); Wed, 10 Oct 2018 04:46:01 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:33668 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725789AbeJJIqA (ORCPT ); Wed, 10 Oct 2018 04:46:00 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: koike) with ESMTPSA id 22023260A95 Subject: Re: [PATCH] media: vivid: Improve timestamping To: Gabriel Francisco Mandaji , Hans Verkuil , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: lkcamp@lists.libreplanetbr.org References: <20181010004921.GA6532@gfm-note> From: Helen Koike Openpgp: preference=signencrypt Autocrypt: addr=helen.koike@collabora.com; keydata= xsFNBFmOMD4BEADb2nC8O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P F4MD67guCrqrGWSynwzvwWNybEVWV/hykKLa5xtnG6uGUGSO1lnwxUAR17eGWqNwGXYCHpAP zboVPGxw4aUcR80AEQEAAcLBfAQYAQoAJhYhBKh9ADrOsi1cSAdZPMB+rCj3IWJdBQJZjjDJ AhsMBQkCxLJmAAoJEMB+rCj3IWJdY34QAMVy70677f9vXJsYVndP1xmnMYqnI5CEViQ3GP9W k8I2q8nUN3NHyjWe5Ro/UKlj03REymVdtSq7xBRAINQmfgVELvOBEJY6cO8JAujPl4EiJ0kL Y7D0+WfRrMvs/pR9jG7h3e3oG080ezRIkh9amGi1rj/uG39vpBc5avNpvOqqdwyCIyAQuG/Z 00CcD92WMQH3LmZkHJ0A5amZmVp/2NhWFIXnzMGCG+pnenYkYTs+nPwpEeF9aURlT3RQ6MEX te5bno0pQAZmJGlfxzPeId4BXGIlyCBGa8AYVcAH4byD/Lj1CWMuF/n+PQOloCMTUQsWuHJG WAFfICCspjVwzVDZMr3W3dKesrufYdXM0yVlXc39Zvx2sI94tMPaaFGvk758TQohg28OlPFD AxxgkCTrLa8OeJxNJFAz4cmmCWiZbm3SSYLzVFkNozQujL8c3y2U5yM3Tq7RmU9Djxh4s10p OoTFbIyky1af/kDLOBTNMXSNJ95+CDyH4g6rHhYJcjUribIgChGr7eLiSdQCpoyjcOe6n7ua NDLkOLQPocgjJb/AE46aMq67SVffqOTtLZZNPrSKnw/RVt7kbpRrcz5a45oX1x2kwYBBa//G cNC+diAifR6fnbn0lFc5oop99E0SCa0F4V/PYh6myRcqYH8huntTFLvBSYnG/tBYAeu1 Message-ID: <06d3f4d3-f864-6cca-9c3a-45909f7188da@collabora.com> Date: Tue, 9 Oct 2018 22:26:11 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <20181010004921.GA6532@gfm-note> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Gabriel, Thanks for your patch. On 10/9/18 9:49 PM, Gabriel Francisco Mandaji wrote: > 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; If I understand correctly, soe_time here is the elapsed time (the delta between the beginning of the frame and the end of it), so I thing naming it etime or frame_time or delta_time would be clearer, because soe stands for "start of exposure" and doesn't seem to be the right meaning. > + 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; Could you move the dev->vid_cap_seq_count to the top? I got confused if it was multiplying only the denominator, I think moving to the top makes it clearer (or add parenthesis). > } > > /* > @@ -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(); > Thanks Helen