V4l2 Timestamp always 0 after VIDIOC_DQBUF (l4t r32.2.1)

@JerryChang ns_to_timespec() looks like it is returning properly:

[   36.709037] tegra-vi4 15700000.vi: Create Surface with imgW=1280, imgH=720, memFmt=203
[   36.717641] tegra-vi4 15700000.vi: vi_notify_wait++
[   36.748527] video4linux video0: vi_notify_wait: ts->tv_sec=36 ts->tv_nsec=640100032
[   36.748533] video4linux video0: vi_notify_wait: vi4 got SOF syncpt buf[ffffffc19d865000]
[   36.748538] tegra-vi4 15700000.vi: vi_notify_wait--
[   36.748558] tegra-vi4 15700000.vi: vi_notify_wait++
[   36.781599] video4linux video0: vi_notify_wait: ts->tv_sec=36 ts->tv_nsec=673130272
[   36.781609] video4linux video0: vi_notify_wait: vi4 got SOF syncpt buf[ffffffc19d864400]
[   36.781617] tegra-vi4 15700000.vi: vi_notify_wait--
[   36.781643] tegra-vi4 15700000.vi: vi_notify_wait++
[   36.814628] video4linux video0: vi_notify_wait: ts->tv_sec=36 ts->tv_nsec=706160544
[   36.814640] video4linux video0: vi_notify_wait: vi4 got SOF syncpt buf[ffffffc19d867800]
[   36.814650] tegra-vi4 15700000.vi: vi_notify_wait--
[   36.814746] tegra-vi4 15700000.vi: vi_notify_wait++
[   36.847654] video4linux video0: vi_notify_wait: ts->tv_sec=36 ts->tv_nsec=739190784
[   36.847667] video4linux video0: vi_notify_wait: vi4 got SOF syncpt buf[ffffffc19d867000]
[   36.847677] tegra-vi4 15700000.vi: vi_notify_wait--
[   36.847720] tegra-vi4 15700000.vi: vi_notify_wait++
[   36.880701] video4linux video0: vi_notify_wait: ts->tv_sec=36 ts->tv_nsec=772221024
[   36.880709] video4linux video0: vi_notify_wait: vi4 got SOF syncpt buf[ffffffc19d865000]
[   36.880717] tegra-vi4 15700000.vi: vi_notify_wait--
[   36.880754] tegra-vi4 15700000.vi: vi_notify_wait++
[   36.913709] video4linux video0: vi_notify_wait: ts->tv_sec=36 ts->tv_nsec=805251296
[   36.913718] video4linux video0: vi_notify_wait: vi4 got SOF syncpt buf[ffffffc19d864400]
[   36.913727] tegra-vi4 15700000.vi: vi_notify_wait--
[   36.913766] tegra-vi4 15700000.vi: vi_notify_wait++
[   36.946780] video4linux video0: vi_notify_wait: ts->tv_sec=36 ts->tv_nsec=838281568
[   36.946797] video4linux video0: vi_notify_wait: vi4 got SOF syncpt buf[ffffffc19d867800]
[   36.946808] tegra-vi4 15700000.vi: vi_notify_wait--
[   36.946868] tegra-vi4 15700000.vi: vi_notify_wait++
[   36.979808] video4linux video0: vi_notify_wait: ts->tv_sec=36 ts->tv_nsec=871311808
[   36.979824] video4linux video0: vi_notify_wait: vi4 got SOF syncpt buf[ffffffc19d867000]
[   36.979838] tegra-vi4 15700000.vi: vi_notify_wait--
[   36.979895] tegra-vi4 15700000.vi: vi_notify_wait++
[   37.012888] video4linux video0: vi_notify_wait: ts->tv_sec=36 ts->tv_nsec=904342048
[   37.012912] video4linux video0: vi_notify_wait: vi4 got SOF syncpt buf[ffffffc19d865000]
[   37.012930] tegra-vi4 15700000.vi: vi_notify_wait--
[   37.013010] tegra-vi4 15700000.vi: vi_notify_wait++
[   37.045914] video4linux video0: vi_notify_wait: ts->tv_sec=36 ts->tv_nsec=937372320
[   37.045939] video4linux video0: vi_notify_wait: vi4 got SOF syncpt buf[ffffffc19d864400]
[   37.045958] tegra-vi4 15700000.vi: vi_notify_wait--
[   37.046033] tegra-vi4 15700000.vi: vi_notify_wait++
[   37.078966] video4linux video0: vi_notify_wait: ts->tv_sec=36 ts->tv_nsec=970402592
[   37.078988] video4linux video0: vi_notify_wait: vi4 got SOF syncpt buf[ffffffc19d867800]
[   37.079004] tegra-vi4 15700000.vi: vi_notify_wait--
[   37.079081] tegra-vi4 15700000.vi: vi_notify_wait++
[   37.111974] video4linux video0: vi_notify_wait: ts->tv_sec=37 ts->tv_nsec=3432832
[   37.111995] video4linux video0: vi_notify_wait: vi4 got SOF syncpt buf[ffffffc19d867000]
[   37.112011] tegra-vi4 15700000.vi: vi_notify_wait--
[   37.112085] tegra-vi4 15700000.vi: vi_notify_wait++
[   37.144913] video4linux video0: vi_notify_wait: ts->tv_sec=37 ts->tv_nsec=36463104
[   37.144925] video4linux video0: vi_notify_wait: vi4 got SOF syncpt buf[ffffffc19d865000]
[   37.144935] tegra-vi4 15700000.vi: vi_notify_wait--

Here’s the diff for reference:

diff --git a/drivers/media/platform/tegra/camera/vi/vi4_fops.c b/drivers/media/platform/tegra/camera/vi/vi4_fops.c
index e3c5a2b2e..b19f32c4f 100644
--- a/drivers/media/platform/tegra/camera/vi/vi4_fops.c
+++ b/drivers/media/platform/tegra/camera/vi/vi4_fops.c
@@ -9,6 +9,7 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+#define DEBUG 1
 #include <linux/freezer.h>
 #include <linux/kthread.h>
 #include <linux/nvhost.h>
@@ -172,6 +173,7 @@ static bool vi_notify_wait(struct tegra_channel *chan,
        int i, err;
        u32 thresh[TEGRA_CSI_BLOCKS];
 
+    dev_info(chan->vi->dev, "%s++\n", __func__);
        /*
         * Increment syncpt for ATOMP_FE
         *
@@ -217,6 +219,9 @@ static bool vi_notify_wait(struct tegra_channel *chan,
                                        "no capture status! err = %d\n", err);
                        else {
                                *ts = ns_to_timespec((s64)status.sof_ts);
+                               dev_dbg(&chan->video.dev,
+                                       "%s: ts->tv_sec=%lu ts->tv_nsec=%lu\n",
+                                       __func__, ts->tv_sec, ts->tv_nsec);
 
                                dev_dbg(&chan->video.dev,
                                        "%s: vi4 got SOF syncpt buf[%p]\n",
@@ -225,6 +230,7 @@ static bool vi_notify_wait(struct tegra_channel *chan,
                }
        }
 
+    dev_info(chan->vi->dev, "%s--\n", __func__);
        return true;
 }

Have apply the patch for timestamp from below link

[VI][TX2] missing buffer’s timestamp update for v4l2 buffers. https://devtalk.nvidia.com/default/topic/1057229/

[VI][Nano] missing buffer’s timestamp update for v4l2 buffers. https://devtalk.nvidia.com/default/topic/1062912/

https://elinux.org/L4T_Jetson/r32.2.1_patch

That looks promising! Will test shortly

That fixed it! Looks like the patch was already included in r32.3.

VIDIOC_QUERYCAP: ok
VIDIOC_G_FMT: ok
VIDIOC_S_FMT: ok
Format Video Capture:
	Width/Height      : 1280/720
	Pixel Format      : 'UYVY'
	Field             : None
	Bytes per Line    : 2560
	Size Image        : 1843200
	Colorspace        : SMPTE 170M
	Transfer Function : Default (maps to Rec. 709)
	YCbCr/HSV Encoding: Default (maps to ITU-R 601)
	Quantization      : Default (maps to Limited Range)
	Flags             : 
New timings found
VIDIOC_REQBUFS: ok
VIDIOC_QUERYBUF: ok
VIDIOC_QBUF: ok
VIDIOC_QUERYBUF: ok
VIDIOC_QBUF: ok
VIDIOC_QUERYBUF: ok
VIDIOC_QBUF: ok
VIDIOC_QUERYBUF: ok
VIDIOC_QBUF: ok
VIDIOC_STREAMON: ok
	Index    : 0
	Type     : Video Capture
	Flags    : mapped
	Field    : None
	Sequence : 0
	Length   : 1843200
	Bytesused: 1843200
	Timestamp: 212.763733s (Monotonic, End-of-Frame)

	Index    : 1
	Type     : Video Capture
	Flags    : mapped
	Field    : None
	Sequence : 1
	Length   : 1843200
	Bytesused: 1843200
	Timestamp: 212.796763s (Monotonic, End-of-Frame)

	Index    : 2
	Type     : Video Capture
	Flags    : mapped
	Field    : None
	Sequence : 2
	Length   : 1843200
	Bytesused: 1843200
	Timestamp: 212.829794s (Monotonic, End-of-Frame)

	Index    : 3
	Type     : Video Capture
	Flags    : mapped
	Field    : None
	Sequence : 3
	Length   : 1843200
	Bytesused: 1843200
	Timestamp: 212.862824s (Monotonic, End-of-Frame)

	Index    : 0
	Type     : Video Capture
	Flags    : mapped
	Field    : None
	Sequence : 4
	Length   : 1843200
	Bytesused: 1843200
	Timestamp: 212.895854s (Monotonic, End-of-Frame)

	Index    : 1
	Type     : Video Capture
	Flags    : mapped
	Field    : None
	Sequence : 5
	Length   : 1843200
	Bytesused: 1843200
	Timestamp: 212.928884s (Monotonic, End-of-Frame)

	Index    : 2
	Type     : Video Capture
	Flags    : mapped
	Field    : None
	Sequence : 6
	Length   : 1843200
	Bytesused: 1843200
	Timestamp: 212.961914s (Monotonic, End-of-Frame)

	Index    : 3
	Type     : Video Capture
	Flags    : mapped
	Field    : None
	Sequence : 7
	Length   : 1843200
	Bytesused: 1843200
	Timestamp: 212.994945s (Monotonic, End-of-Frame)

	Index    : 0
	Type     : Video Capture
	Flags    : mapped
	Field    : None
	Sequence : 8
	Length   : 1843200
	Bytesused: 1843200
	Timestamp: 213.027975s (Monotonic, End-of-Frame)

	Index    : 1
	Type     : Video Capture
	Flags    : mapped
	Field    : None
	Sequence : 9
	Length   : 1843200
	Bytesused: 1843200
	Timestamp: 213.061005s (Monotonic, End-of-Frame)

VIDIOC_STREAMOFF: ok

Thanks for your help!

Yes, those patch already merge and include in r32.3 release.