linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: Junghak Sung <jh1009.sung@samsung.com>,
	linux-media@vger.kernel.org, mchehab@osg.samsung.com,
	laurent.pinchart@ideasonboard.com, sakari.ailus@iki.fi,
	pawel@osciak.com
Cc: inki.dae@samsung.com, sw0312.kim@samsung.com,
	nenggun.kim@samsung.com, sangbae90.lee@samsung.com,
	rany.kwon@samsung.com
Subject: Re: [RFC PATCH v9 1/6] media: videobuf2: Move timestamp to vb2_buffer
Date: Thu, 05 Nov 2015 08:50:02 +0100	[thread overview]
Message-ID: <563B0A2A.3030905@xs4all.nl> (raw)
In-Reply-To: <563AC908.9070708@samsung.com>

On 11/05/2015 04:12 AM, Junghak Sung wrote:
>>> diff --git a/drivers/media/platform/vivid/vivid-kthread-cap.c b/drivers/media/platform/vivid/vivid-kthread-cap.c
>>> index 83cc6d3..b0ad054 100644
>>> --- a/drivers/media/platform/vivid/vivid-kthread-cap.c
>>> +++ b/drivers/media/platform/vivid/vivid-kthread-cap.c
>>> @@ -441,7 +441,7 @@ static void vivid_fillbuff(struct vivid_dev *dev, struct vivid_buffer *buf)
>>>   	 * "Start of Exposure".
>>>   	 */
>>>   	if (dev->tstamp_src_is_soe)
>>> -		v4l2_get_timestamp(&buf->vb.timestamp);
>>> +		buf->vb.vb2_buf.timestamp = ktime_get_ns();
>>>   	if (dev->field_cap == V4L2_FIELD_ALTERNATE) {
>>>   		/*
>>>   		 * 60 Hz standards start with the bottom field, 50 Hz standards
>>> @@ -558,8 +558,9 @@ static void vivid_fillbuff(struct vivid_dev *dev, struct vivid_buffer *buf)
>>>   	 * the timestamp now.
>>>   	 */
>>>   	if (!dev->tstamp_src_is_soe)
>>> -		v4l2_get_timestamp(&buf->vb.timestamp);
>>> -	buf->vb.timestamp.tv_sec += dev->time_wrap_offset;
>>> +		buf->vb.vb2_buf.timestamp = ktime_get_ns();
>>> +	buf->vb.vb2_buf.timestamp +=
>>> +			((u64) dev->time_wrap_offset * NSEC_PER_SEC);
>>
>> I'd do this differently: make time_wrap_offset of type u64 and assign it
>> accordingly with nanoseconds. That way you can just do:
>>
>> 	timestamp += dev->time_wrap_offset
>>
>> vivid-ctrls.c also needs to be modified (vivid_streaming_s_ctrl(), VIVID_CID_TIME_WRAP
>> case) to:
>>
>> 	dev->time_wrap_offset = (0x100000000ULL - 16) * NSEC_PER_SEC - ktime_get_ns();
>>
>> The v4l2_get_timestamp() call there can be dropped.
>>
> 
> I agree with your opinion. But it is too hard to read the code
> getting time_wrap_offset.
> How about this way?
> 
>   in vivid_streaming_s_ctrl() of vivid-ctrls.c
>          dev->time_wrap_offset = ktime_get_ns() + 16 * NSEC_PER_SEC;
>   and in vivid_fillbuff() of vivid-kthread-cap.c
> 	buf->vb.vb2_buf.timestamp -= dev->time_wrap_offset;

That doesn't do what I want it to do, which is to wrap around in the struct timeval
where seconds are 32 bits. The code above is actually wrong since I forgot that
tv_sec in struct timeval is signed, so 0x100000000ULL should be 0x80000000ULL.
Also, that code will fail after 2038, so that's no good either.

On a related note I send out a question to Arnd whether a timestamp should be u64
or s64. It's not clear to me which should be used as ktime_get_ns() returns a s64.

Once we return the full 64 bits to userspace, then we have a second wrap around when
the u64 (or s64) wraps. I'll add a second wrap-around control to vivid at that time.

I'll wait for Arnd to answer before fixing the time_wrap_offset calculation since I
need to know whether a timestamp is u64 or s64.

Regards,

	Hans

  reply	other threads:[~2015-11-05  7:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-03 10:16 [RFC PATCH v9] Refactoring Videobuf2 for common use Junghak Sung
2015-11-03 10:16 ` [RFC PATCH v9 1/6] media: videobuf2: Move timestamp to vb2_buffer Junghak Sung
2015-11-04 12:28   ` Hans Verkuil
2015-11-05  3:12     ` Junghak Sung
2015-11-05  7:50       ` Hans Verkuil [this message]
2015-11-03 10:16 ` [RFC PATCH v9 2/6] media: videobuf2: Add set_timestamp to struct vb2_queue Junghak Sung
2015-11-04 12:41   ` Hans Verkuil
2015-11-05  3:19     ` Junghak Sung
2015-11-03 10:16 ` [RFC PATCH v9 3/6] media: videobuf2: Separate vb2_poll() Junghak Sung
2015-11-05  9:55   ` Hans Verkuil
2015-11-03 10:16 ` [RFC PATCH v9 4/6] media: videobuf2: last_buffer_queued is set at fill_v4l2_buffer() Junghak Sung
2015-11-05 10:00   ` Hans Verkuil
2015-11-09  7:48     ` Junghak Sung
2015-11-03 10:16 ` [RFC PATCH v9 5/6] media: videobuf2: Refactor vb2_fileio_data and vb2_thread Junghak Sung
2015-11-05 11:10   ` Hans Verkuil
2015-11-03 10:16 ` [RFC PATCH v9 6/6] media: videobuf2: Move vb2_fileio_data and vb2_thread to core part Junghak Sung
2015-11-05 11:14   ` Hans Verkuil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=563B0A2A.3030905@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=inki.dae@samsung.com \
    --cc=jh1009.sung@samsung.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@osg.samsung.com \
    --cc=nenggun.kim@samsung.com \
    --cc=pawel@osciak.com \
    --cc=rany.kwon@samsung.com \
    --cc=sakari.ailus@iki.fi \
    --cc=sangbae90.lee@samsung.com \
    --cc=sw0312.kim@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).