public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@iki.fi>
To: Hans Verkuil <hverkuil@xs4all.nl>, linux-media@vger.kernel.org
Cc: k.debski@samsung.com, laurent.pinchart@ideasonboard.com
Subject: Re: [PATH v6 06/10] v4l: Handle buffer timestamp flags correctly
Date: Sat, 01 Mar 2014 18:51:00 +0200	[thread overview]
Message-ID: <53120FF4.2050108@iki.fi> (raw)
In-Reply-To: <5311EE75.1000305@xs4all.nl>

Hi Hans,

Thanks for the comments.

Hans Verkuil wrote:
> On 03/01/2014 02:17 PM, Sakari Ailus wrote:
>> For COPY timestamps, buffer timestamp source flags will traverse the queue
>> untouched.
>>
>> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
>> ---
>>  drivers/media/v4l2-core/videobuf2-core.c |   26 +++++++++++++++++++++++++-
>>  1 file changed, 25 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
>> index 3dda083..7afeb6b 100644
>> --- a/drivers/media/v4l2-core/videobuf2-core.c
>> +++ b/drivers/media/v4l2-core/videobuf2-core.c
>> @@ -488,7 +488,22 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
>>  	 * Clear any buffer state related flags.
>>  	 */
>>  	b->flags &= ~V4L2_BUFFER_MASK_FLAGS;
>> -	b->flags |= q->timestamp_flags;
>> +	if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) ==
>> +	    V4L2_BUF_FLAG_TIMESTAMP_COPY) {
>> +		/*
>> +		 * For COPY timestamps, we just set the timestamp type
>> +		 * here. The timestamp source is already in b->flags.
>> +		 */
>> +		b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK;
>> +	} else {
>> +		/*
>> +		 * For non-COPY timestamps, drop timestamp source and
>> +		 * obtain the timestamp type and source from the
>> +		 * queue.
>> +		 */
>> +		b->flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
>> +		b->flags |= q->timestamp_flags;
>> +	}
> 
> It's correct, but I would do it a bit differently:
> 
> 	b->flags &= ~V4L2_BUFFER_MASK_FLAGS;
> 	b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK;
> 	if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
> 	    V4L2_BUF_FLAG_TIMESTAMP_COPY) {
> 		/*
> 		 * For non-COPY timestamps, drop timestamp source and
> 		 * obtain the timestamp type and source from the
> 		 * queue.
> 		 */
> 		b->flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
> 		b->flags |= q->timestamp_flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
> 	}
> 
> That way it is clearer that the timestamp type is always set and that it is
> just the timestamp source that has special handling.

I was actually pondering between the above and what ended up into the
code. ;-) I'll fix that and change the comment to say:

		/*
		 * For non-COPY timestamps, drop timestamp source bits
		 * and obtain the timestamp source from the queue.
		 */
> 
>>  
>>  	switch (vb->state) {
>>  	case VB2_BUF_STATE_QUEUED:
>> @@ -1031,6 +1046,15 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
>>  
>>  	/* Zero flags that the vb2 core handles */
>>  	vb->v4l2_buf.flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
>> +	if ((vb->vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
>> +	    V4L2_BUF_FLAG_TIMESTAMP_COPY) {
>> +		/*
>> +		 * Non-COPY timestamps will get their timestamp and
>> +		 * timestamp source flags from the queue.
>> +		 */
>> +		vb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
>> +	}
> 
> This should be:
> 
> 	if ((vb->vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) !=
> 	    V4L2_BUF_FLAG_TIMESTAMP_COPY || !V4L2_TYPE_IS_OUTPUT(b->type)) {
> 
> Capture buffers also need to clear the TSTAMP_SRC flags as they will get it
> from the output queue. In other words: capture buffers never set the timestamp
> source flags, only output buffers can do that if timestamps are copied.

Good point. I'll also change the comment accordingly:

		/*
		 * Non-COPY timestamps and non-OUTPUT queues will get
		 * their timestamp and timestamp source flags from the
		 * queue.
		 */

> As an aside: the more I think about it, the more I believe that we're not quite
> doing the right thing when it comes to copying timestamps. The problem is that
> TIMESTAMP_COPY is part of the timestamp type mask. It should be a separate bit.
> That way output buffers supply both type and source, and capture buffers give
> those back to the application. Right now you can't copy the timestamp type since
> COPY is part of those types.

Is that a real problem? The timestamp types are related to clocks and in
that sense, "copy" is one of them: it's anything the program queueing it
to the OUTPUT queue has specified. In other words, I don't think the
combination of monotonic (or realtime) and copy would be meaningful.

> We did not really think that through.

At least I don't see a problem with how it's currently implemented. :-)

-- 
Kind regards,

Sakari Ailus
sakari.ailus@iki.fi

  reply	other threads:[~2014-03-01 16:47 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-01 13:16 [PATCH v6 00/10] Fix buffer timestamp documentation, add new timestamp flags Sakari Ailus
2014-03-01 13:16 ` [PATH v6 01/10] vb2: fix timecode and flags handling for output buffers Sakari Ailus
2014-03-01 13:16 ` [PATH v6 02/10] v4l: Document timestamp behaviour to correspond to reality Sakari Ailus
2014-03-01 13:17 ` [PATH v6 03/10] v4l: Use full 32 bits for buffer flags Sakari Ailus
2014-03-01 13:17 ` [PATH v6 04/10] v4l: Rename vb2_queue.timestamp_type as timestamp_flags Sakari Ailus
2014-03-01 13:43   ` Hans Verkuil
2014-03-01 13:17 ` [PATH v6 05/10] v4l: Add timestamp source flags, mask and document them Sakari Ailus
2014-03-01 13:39   ` Hans Verkuil
2014-03-01 16:22     ` Sakari Ailus
2014-03-01 16:13   ` [PATH v6 05.1/11] v4l: Timestamp flags will soon contain timestamp source, not just type Sakari Ailus
2014-03-01 13:17 ` [PATH v6 06/10] v4l: Handle buffer timestamp flags correctly Sakari Ailus
2014-03-01 14:28   ` Hans Verkuil
2014-03-01 16:51     ` Sakari Ailus [this message]
2014-03-02  7:24       ` Hans Verkuil
2014-03-01 16:59     ` [PATH v6.1 " Sakari Ailus
2014-03-02  7:12       ` Hans Verkuil
2014-03-01 13:17 ` [PATH v6 07/10] uvcvideo: Tell the user space we're using start-of-exposure timestamps Sakari Ailus
2014-03-01 13:17 ` [PATH v6 08/10] exynos-gsc, m2m-deinterlace, mx2_emmaprp: Copy v4l2_buffer data from src to dst Sakari Ailus
2014-03-01 13:17 ` [PATH v6 09/10] v4l: Copy timestamp source flags to destination on m2m devices Sakari Ailus
2014-03-01 13:17 ` [PATH v6 10/10] v4l: Document timestamp buffer flag behaviour Sakari Ailus
2014-03-01 13:42   ` 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=53120FF4.2050108@iki.fi \
    --to=sakari.ailus@iki.fi \
    --cc=hverkuil@xs4all.nl \
    --cc=k.debski@samsung.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    /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