[libcamera-devel,2/3] libcamera: v4l2_videodevice: Clarify setting of v4l2_buffer timestamp
diff mbox series

Message ID 20220317104740.569310-3-umang.jain@ideasonboard.com
State Accepted
Delegated to: Umang Jain
Headers show
Series
  • v4l2_videodevice: Small fixup & clarifications
Related show

Commit Message

Umang Jain March 17, 2022, 10:47 a.m. UTC
Add a comment to clarify why we set v4l2_buffer timestamp while
queuing the buffer (VIDIOC_QBUF). The timstamps are required to
be supplied for memory-to-memory devices for output streams which
then are copied to capture stream buffers with the help of
V4L2_BUF_FLAG_TIMESTAMP_COPY (set by the driver).

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 src/libcamera/v4l2_videodevice.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Laurent Pinchart March 23, 2022, 12:13 a.m. UTC | #1
Hi Umang,

Thank you for the patch.

On Thu, Mar 17, 2022 at 04:17:39PM +0530, Umang Jain via libcamera-devel wrote:
> Add a comment to clarify why we set v4l2_buffer timestamp while
> queuing the buffer (VIDIOC_QBUF). The timstamps are required to
> be supplied for memory-to-memory devices for output streams which
> then are copied to capture stream buffers with the help of
> V4L2_BUF_FLAG_TIMESTAMP_COPY (set by the driver).
> 
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>  src/libcamera/v4l2_videodevice.cpp | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index 5580269f..a6c54b19 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -1600,6 +1600,14 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)
>  			buf.length = planes[0].length;
>  		}
>  
> +		/*
> +		 * Timestamps are to be supplied if the device is a mem-to-mem
> +		 * device. The drivers will have V4L2_BUF_FLAG_TIMESTAMP_COPY
> +		 * set hence these timestamps will be copied from the output
> +		 * buffers to capture buffers. If the device is not mem-to-men,

s/mem-to-men/mem-to-mem/

> +		 * there is no harm in setting the timestamps as they will be
> +		 * ignored (and over-written).

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +		 */
>  		buf.timestamp.tv_sec = metadata.timestamp / 1000000000;
>  		buf.timestamp.tv_usec = (metadata.timestamp / 1000) % 1000000;
>  	}
Kieran Bingham March 23, 2022, 10:33 a.m. UTC | #2
Quoting Laurent Pinchart via libcamera-devel (2022-03-23 00:13:59)
> Hi Umang,
> 
> Thank you for the patch.
> 
> On Thu, Mar 17, 2022 at 04:17:39PM +0530, Umang Jain via libcamera-devel wrote:
> > Add a comment to clarify why we set v4l2_buffer timestamp while
> > queuing the buffer (VIDIOC_QBUF). The timstamps are required to
> > be supplied for memory-to-memory devices for output streams which
> > then are copied to capture stream buffers with the help of
> > V4L2_BUF_FLAG_TIMESTAMP_COPY (set by the driver).
> > 
> > Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> > ---
> >  src/libcamera/v4l2_videodevice.cpp | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> > index 5580269f..a6c54b19 100644
> > --- a/src/libcamera/v4l2_videodevice.cpp
> > +++ b/src/libcamera/v4l2_videodevice.cpp
> > @@ -1600,6 +1600,14 @@ int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)
> >                       buf.length = planes[0].length;
> >               }
> >  
> > +             /*
> > +              * Timestamps are to be supplied if the device is a mem-to-mem
> > +              * device. The drivers will have V4L2_BUF_FLAG_TIMESTAMP_COPY
> > +              * set hence these timestamps will be copied from the output
> > +              * buffers to capture buffers. If the device is not mem-to-men,
> 
> s/mem-to-men/mem-to-mem/
> 
> > +              * there is no harm in setting the timestamps as they will be
> > +              * ignored (and over-written).
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> 
> > +              */
> >               buf.timestamp.tv_sec = metadata.timestamp / 1000000000;
> >               buf.timestamp.tv_usec = (metadata.timestamp / 1000) % 1000000;
> >       }
> 
> -- 
> Regards,
> 
> Laurent Pinchart

Patch
diff mbox series

diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index 5580269f..a6c54b19 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -1600,6 +1600,14 @@  int V4L2VideoDevice::queueBuffer(FrameBuffer *buffer)
 			buf.length = planes[0].length;
 		}
 
+		/*
+		 * Timestamps are to be supplied if the device is a mem-to-mem
+		 * device. The drivers will have V4L2_BUF_FLAG_TIMESTAMP_COPY
+		 * set hence these timestamps will be copied from the output
+		 * buffers to capture buffers. If the device is not mem-to-men,
+		 * there is no harm in setting the timestamps as they will be
+		 * ignored (and over-written).
+		 */
 		buf.timestamp.tv_sec = metadata.timestamp / 1000000000;
 		buf.timestamp.tv_usec = (metadata.timestamp / 1000) % 1000000;
 	}