Similar post to this.
I am aware that the V4L2 EOF time stamps are from monotonic clock, from drivers/media/platform/tegra/camera/vi/channel.c.
chan->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
| V4L2_BUF_FLAG_TSTAMP_SRC_EOF;
ret = vb2_queue_init(&chan->queue);
I am attempting to correlate these monotonic timestamps to CLOCK_REALTIME since I have other sensors on my system I want to sync with. At user-space frame dequeue, I calculated offset_ns by doing
offset_ns = clock_gettime(CLOCK_REALTIME, &real_ts) - clock_gettime(CLOCK_MONOTONIC, &mono_ts)
and then adding that offset to V4L2 mono buffer timestamp. I see that my converted timestamp is ~20 seconds ahead of CLOCK_REALTIME.
Next, in an attempt to understand where the offset is coming from, I printed mono time immediately after the last buffer from V4L2 is received. I confirmed that I also see this 20 second offset in V4L2.
v4l2-ctl -V --stream-mmap --stream-count=10 -d /dev/video0 --verbose; python3 -c 'import time; print(time.monotonic_ns()/1.0e9);'
VIDIOC_QUERYCAP: ok
VIDIOC_G_FMT: ok
Format Video Capture:
Width/Height : 1920/1536
Pixel Format : 'UYVY' (UYVY 4:2:2)
Field : None
Bytes per Line : 3840
Size Image : 5898240
Colorspace : sRGB
Transfer Function : Default (maps to sRGB)
YCbCr/HSV Encoding: Default (maps to ITU-R 601)
Quantization : Default (maps to Limited Range)
Flags :
VIDIOC_REQBUFS returned 0 (Success)
VIDIOC_QUERYBUF returned 0 (Success)
VIDIOC_QUERYBUF returned 0 (Success)
VIDIOC_QUERYBUF returned 0 (Success)
VIDIOC_QUERYBUF returned 0 (Success)
VIDIOC_QBUF returned 0 (Success)
VIDIOC_QBUF returned 0 (Success)
VIDIOC_QBUF returned 0 (Success)
VIDIOC_QBUF returned 0 (Success)
VIDIOC_STREAMON returned 0 (Success)
cap dqbuf: 0 seq: 0 bytesused: 5898240 ts: 8420.476914 (ts-monotonic, ts-src-eof)
cap dqbuf: 1 seq: 1 bytesused: 5898240 ts: 8420.516914 delta: 40.000 ms (ts-monotonic, ts-src-eof)
cap dqbuf: 2 seq: 2 bytesused: 5898240 ts: 8420.556915 delta: 40.001 ms (ts-monotonic, ts-src-eof)
cap dqbuf: 3 seq: 3 bytesused: 5898240 ts: 8420.596915 delta: 40.000 ms (ts-monotonic, ts-src-eof)
cap dqbuf: 0 seq: 4 bytesused: 5898240 ts: 8420.636915 delta: 40.000 ms fps: 25.00 (ts-monotonic, ts-src-eof)
cap dqbuf: 1 seq: 5 bytesused: 5898240 ts: 8420.676916 delta: 40.001 ms fps: 25.00 (ts-monotonic, ts-src-eof)
cap dqbuf: 2 seq: 6 bytesused: 5898240 ts: 8420.716916 delta: 40.000 ms fps: 25.00 (ts-monotonic, ts-src-eof)
cap dqbuf: 3 seq: 7 bytesused: 5898240 ts: 8420.756916 delta: 40.000 ms fps: 25.00 (ts-monotonic, ts-src-eof)
cap dqbuf: 0 seq: 8 bytesused: 5898240 ts: 8420.796917 delta: 40.001 ms fps: 25.00 (ts-monotonic, ts-src-eof)
cap dqbuf: 1 seq: 9 bytesused: 5898240 ts: 8420.836917 delta: 40.000 ms fps: 25.00 (ts-monotonic, ts-src-eof)
8401.219419104
Other posts mention looking at the offset to the system time looking at offset_ns
in cat /sys/devices/system/clocksource/clocksource0/offset_ns. However, I do not have this in my path.
So I want to understand what the best way is to correlate the monotonic timestamp from RTCPU with clock realtime on my system.
Thanks