diff mbox

[1/4] v4l: Define video buffer flags for timestamp types

Message ID 1353017207-370-1-git-send-email-sakari.ailus@iki.fi (mailing list archive)
State New, archived
Headers show

Commit Message

Sakari Ailus Nov. 15, 2012, 10:06 p.m. UTC
Define video buffer flags for different timestamp types. Everything up to
now have used either realtime clock or monotonic clock, without a way to
tell which clock the timestamp was taken from.

Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 Documentation/DocBook/media/v4l/io.xml |   25 +++++++++++++++++++++++++
 include/uapi/linux/videodev2.h         |    4 ++++
 2 files changed, 29 insertions(+), 0 deletions(-)

Comments

Hans Verkuil Nov. 16, 2012, 1:51 p.m. UTC | #1
On Thu November 15 2012 23:06:44 Sakari Ailus wrote:
> Define video buffer flags for different timestamp types. Everything up to
> now have used either realtime clock or monotonic clock, without a way to
> tell which clock the timestamp was taken from.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  Documentation/DocBook/media/v4l/io.xml |   25 +++++++++++++++++++++++++
>  include/uapi/linux/videodev2.h         |    4 ++++
>  2 files changed, 29 insertions(+), 0 deletions(-)
> 
> diff --git a/Documentation/DocBook/media/v4l/io.xml b/Documentation/DocBook/media/v4l/io.xml
> index 7e2f3d7..d598f2c 100644
> --- a/Documentation/DocBook/media/v4l/io.xml
> +++ b/Documentation/DocBook/media/v4l/io.xml
> @@ -938,6 +938,31 @@ Typically applications shall use this flag for output buffers if the data
>  in this buffer has not been created by the CPU but by some DMA-capable unit,
>  in which case caches have not been used.</entry>
>  	  </row>
> +	  <row>
> +	    <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_MASK</constant></entry>
> +	    <entry>0xe000</entry>
> +	    <entry>Mask for timestamp types below. To test the
> +	    timestamp type, mask out bits not belonging to timestamp
> +	    type by performing a logical and operation with buffer
> +	    flags and timestamp mask.</tt> </entry>
> +	  </row>
> +	  <row>
> +	    <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN</constant></entry>
> +	    <entry>0x0000</entry>
> +	    <entry>Unknown timestamp type. This type is used by
> +	    drivers before Linux 3.8 and may be either monotonic (see
> +	    below) or realtime. Monotonic clock has been favoured in
> +	    embedded systems whereas most of the drivers use the
> +	    realtime clock.</entry>

Isn't 'wallclock time' a better expression? It is probably a good idea as well
to add the userspace call that gives the same clock: gettimeofday or
clock_gettime(CLOCK_REALTIME) for the wallclock time and clock_gettime(CLOCK_MONOTONIC)
for the monotonic time. That way apps can do the same call and compare it to the
timestamp received.

> +	  </row>
> +	  <row>
> +	    <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC</constant></entry>
> +	    <entry>0x2000</entry>
> +	    <entry>The buffer timestamp has been taken from the
> +	    <constant>CLOCK_MONOTONIC</constant> clock. To access the
> +	    same clock outside V4L2, use <tt>clock_gettime(2)</tt>

Ah, you mentioned it here already for the monotonic clock :-)

> +	    .</entry>
> +	  </row>
>  	</tbody>
>        </tgroup>
>      </table>
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index 2fff7ff..410ea9f 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -686,6 +686,10 @@ struct v4l2_buffer {
>  /* Cache handling flags */
>  #define V4L2_BUF_FLAG_NO_CACHE_INVALIDATE	0x0800
>  #define V4L2_BUF_FLAG_NO_CACHE_CLEAN		0x1000
> +/* Timestamp type */
> +#define V4L2_BUF_FLAG_TIMESTAMP_MASK		0xe000
> +#define V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN		0x0000
> +#define V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC	0x2000
>  
>  /*
>   *	O V E R L A Y   P R E V I E W
> 

Regards,

	Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sakari Ailus Nov. 16, 2012, 3:20 p.m. UTC | #2
Hi Hans,

Thanks for the comments!

On Fri, Nov 16, 2012 at 02:51:29PM +0100, Hans Verkuil wrote:
> On Thu November 15 2012 23:06:44 Sakari Ailus wrote:
> > diff --git a/Documentation/DocBook/media/v4l/io.xml b/Documentation/DocBook/media/v4l/io.xml
> > index 7e2f3d7..d598f2c 100644
> > --- a/Documentation/DocBook/media/v4l/io.xml
> > +++ b/Documentation/DocBook/media/v4l/io.xml
> > @@ -938,6 +938,31 @@ Typically applications shall use this flag for output buffers if the data
> >  in this buffer has not been created by the CPU but by some DMA-capable unit,
> >  in which case caches have not been used.</entry>
> >  	  </row>
> > +	  <row>
> > +	    <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_MASK</constant></entry>
> > +	    <entry>0xe000</entry>
> > +	    <entry>Mask for timestamp types below. To test the
> > +	    timestamp type, mask out bits not belonging to timestamp
> > +	    type by performing a logical and operation with buffer
> > +	    flags and timestamp mask.</tt> </entry>
> > +	  </row>
> > +	  <row>
> > +	    <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN</constant></entry>
> > +	    <entry>0x0000</entry>
> > +	    <entry>Unknown timestamp type. This type is used by
> > +	    drivers before Linux 3.8 and may be either monotonic (see
> > +	    below) or realtime. Monotonic clock has been favoured in
> > +	    embedded systems whereas most of the drivers use the
> > +	    realtime clock.</entry>
> 
> Isn't 'wallclock time' a better expression? It is probably a good idea as
> well to add the userspace call that gives the same clock: gettimeofday or
> clock_gettime(CLOCK_REALTIME) for the wallclock time and
> clock_gettime(CLOCK_MONOTONIC) for the monotonic time. That way apps can
> do the same call and compare it to the timestamp received.

I'll add a reference to clock_gettime() and change realtime to wall clock
time. I wonder if I should also add that the unknown timestamp means either
of the two, or can we allow different kinds of unknown timestamps in the
future. Probably we should limit this to realtime and monotonic.
Hans Verkuil Nov. 16, 2012, 3:58 p.m. UTC | #3
On Fri November 16 2012 16:20:03 Sakari Ailus wrote:
> Hi Hans,
> 
> Thanks for the comments!
> 
> On Fri, Nov 16, 2012 at 02:51:29PM +0100, Hans Verkuil wrote:
> > On Thu November 15 2012 23:06:44 Sakari Ailus wrote:
> > > diff --git a/Documentation/DocBook/media/v4l/io.xml b/Documentation/DocBook/media/v4l/io.xml
> > > index 7e2f3d7..d598f2c 100644
> > > --- a/Documentation/DocBook/media/v4l/io.xml
> > > +++ b/Documentation/DocBook/media/v4l/io.xml
> > > @@ -938,6 +938,31 @@ Typically applications shall use this flag for output buffers if the data
> > >  in this buffer has not been created by the CPU but by some DMA-capable unit,
> > >  in which case caches have not been used.</entry>
> > >  	  </row>
> > > +	  <row>
> > > +	    <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_MASK</constant></entry>
> > > +	    <entry>0xe000</entry>
> > > +	    <entry>Mask for timestamp types below. To test the
> > > +	    timestamp type, mask out bits not belonging to timestamp
> > > +	    type by performing a logical and operation with buffer
> > > +	    flags and timestamp mask.</tt> </entry>
> > > +	  </row>
> > > +	  <row>
> > > +	    <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN</constant></entry>
> > > +	    <entry>0x0000</entry>
> > > +	    <entry>Unknown timestamp type. This type is used by
> > > +	    drivers before Linux 3.8 and may be either monotonic (see
> > > +	    below) or realtime. Monotonic clock has been favoured in
> > > +	    embedded systems whereas most of the drivers use the
> > > +	    realtime clock.</entry>
> > 
> > Isn't 'wallclock time' a better expression? It is probably a good idea as
> > well to add the userspace call that gives the same clock: gettimeofday or
> > clock_gettime(CLOCK_REALTIME) for the wallclock time and
> > clock_gettime(CLOCK_MONOTONIC) for the monotonic time. That way apps can
> > do the same call and compare it to the timestamp received.
> 
> I'll add a reference to clock_gettime() and change realtime to wall clock
> time. I wonder if I should also add that the unknown timestamp means either
> of the two, or can we allow different kinds of unknown timestamps in the
> future.

No. UNKNOWN should never be used in the future. It is specific to the pre
timestamp flag era where the timestamp is really only one of two options.

Regards,

	Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/Documentation/DocBook/media/v4l/io.xml b/Documentation/DocBook/media/v4l/io.xml
index 7e2f3d7..d598f2c 100644
--- a/Documentation/DocBook/media/v4l/io.xml
+++ b/Documentation/DocBook/media/v4l/io.xml
@@ -938,6 +938,31 @@  Typically applications shall use this flag for output buffers if the data
 in this buffer has not been created by the CPU but by some DMA-capable unit,
 in which case caches have not been used.</entry>
 	  </row>
+	  <row>
+	    <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_MASK</constant></entry>
+	    <entry>0xe000</entry>
+	    <entry>Mask for timestamp types below. To test the
+	    timestamp type, mask out bits not belonging to timestamp
+	    type by performing a logical and operation with buffer
+	    flags and timestamp mask.</tt> </entry>
+	  </row>
+	  <row>
+	    <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN</constant></entry>
+	    <entry>0x0000</entry>
+	    <entry>Unknown timestamp type. This type is used by
+	    drivers before Linux 3.8 and may be either monotonic (see
+	    below) or realtime. Monotonic clock has been favoured in
+	    embedded systems whereas most of the drivers use the
+	    realtime clock.</entry>
+	  </row>
+	  <row>
+	    <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC</constant></entry>
+	    <entry>0x2000</entry>
+	    <entry>The buffer timestamp has been taken from the
+	    <constant>CLOCK_MONOTONIC</constant> clock. To access the
+	    same clock outside V4L2, use <tt>clock_gettime(2)</tt>
+	    .</entry>
+	  </row>
 	</tbody>
       </tgroup>
     </table>
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 2fff7ff..410ea9f 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -686,6 +686,10 @@  struct v4l2_buffer {
 /* Cache handling flags */
 #define V4L2_BUF_FLAG_NO_CACHE_INVALIDATE	0x0800
 #define V4L2_BUF_FLAG_NO_CACHE_CLEAN		0x1000
+/* Timestamp type */
+#define V4L2_BUF_FLAG_TIMESTAMP_MASK		0xe000
+#define V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN		0x0000
+#define V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC	0x2000
 
 /*
  *	O V E R L A Y   P R E V I E W