By default, I noticed with an IMX378 that:
v4l2-ctl -d /dev/video0 --set-fmt-video=width=4056,height=3040,pixelformat=RG10 \
--set-ctrl frame_length=3200 \
--set-ctrl coarse_time=3000 \
--set-ctrl gain=100 \
--set-ctrl bypass_mode=0 \
--stream-mmap --stream-skip=1 --stream-count=1 --stream-to=test.raw --verbose
Gives us Monotonic + End of Frame timestamps:
...
VIDIOC_STREAMON: ok
Index : 0
Type : Video Capture
Flags : mapped, done
Field : None
Sequence : 0
Length : 24903680
Bytesused: 24903680
Timestamp: 4367.209302s (Monotonic, End-of-Frame)
Index : 1
Type : Video Capture
Flags : mapped, done
Field : None
Sequence : 1
Length : 24903680
Bytesused: 24903680
Timestamp: 4367.242628s (Monotonic, End-of-Frame)
VIDIOC_STREAMOFF: ok
I’m interested in knowing how we can switch this to both realtime clock and start of exposure (V4L2_BUF_FLAG_TSTAMP_SRC_SOE)?
The only obvious reference to V4L2_BUF_FLAG_TSTAMP_SRC_EOF I see is the following in:
/usr/src/kernel/kernel-4.4/drivers/media/platform/tegra/camera/vi/channel.c
...
chan->queue.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
chan->queue.io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ | VB2_USERPTR;
chan->queue.lock = &chan->video_lock;
chan->queue.drv_priv = chan;
chan->queue.buf_struct_size = sizeof(struct tegra_channel_buffer);
chan->queue.ops = &tegra_channel_queue_qops;
#if defined(CONFIG_VIDEOBUF2_DMA_CONTIG)
chan->queue.mem_ops = &vb2_dma_contig_memops;
#endif
chan->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
| V4L2_BUF_FLAG_TSTAMP_SRC_EOF;
...
if we change this to:
chan->queue.timestamp_flags = V4L2_BUF_FLAG_TSTAMP_SRC_SOE;
we see:
nvidia@jetson-randy2:~$ date
Thu Jan 17 15:52:24 UTC 2019
nvidia@jetson-randy2:~$ v4l2-ctl -d /dev/video0 --set-fmt-video=width=4056,height=3040,pixelformat=RG10 \
> --set-ctrl frame_length=3200 \
> --set-ctrl coarse_time=3000 \
> --set-ctrl gain=100 \
> --set-ctrl bypass_mode=0 \
> --stream-mmap --stream-skip=1 --stream-count=1 --stream-to=test.raw --verbos
VIDIOC_QUERYCAP: ok
VIDIOC_S_EXT_CTRLS: ok
VIDIOC_G_FMT: ok
VIDIOC_S_FMT: ok
Format Video Capture:
Width/Height : 4056/3040
Pixel Format : 'RG10'
Field : None
Bytes per Line : 8192
Size Image : 24903680
Colorspace : sRGB
Transfer Function : Default
YCbCr Encoding : Default
Quantization : Default
Flags :
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, done
Field : None
Sequence : 0
Length : 24903680
Bytesused: 24903680
Timestamp: 970.640632s (Unknown, Start-of-Exposure)
Index : 1
Type : Video Capture
Flags : mapped, done
Field : None
Sequence : 1
Length : 24903680
Bytesused: 24903680
Timestamp: 970.673958s (Unknown, Start-of-Exposure)
VIDIOC_STREAMOFF: ok
From: https://linuxtv.org/downloads/v4l-dvb-apis/uapi/v4l/buffer.html#buffer-flags
V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN 0x00000000
Unknown timestamp type. This type is used by drivers before Linux 3.9 and may be either monotonic (see below) or realtime (wall clock). Monotonic clock has been favoured in embedded systems whereas most of the drivers use the realtime clock. Either kinds of timestamps are available in user space via clock_gettime() using clock IDs CLOCK_MONOTONIC and CLOCK_REALTIME, respectively.
Which seems correct. However, if we move the date back 2 minutes, we’d expect the timestamp to be less than 970.673958s if the timestamping is using the realtime clock and not a monotonic clock:
nvidia@jetson-randy2:~$ sudo date -s "17 Jan 2019 15:50:00"
Thu Jan 17 15:50:00 UTC 2019
nvidia@jetson-randy2:~$ v4l2-ctl -d /dev/video0 --set-fmt-video=width=4056,height=3040,pixelformat=RG10 --set-ctrl frame_length=3200 --set-ctrl coarse_time=3000 --set-ctrl gain=100 --set-ctrl bypass_mode=0 --stream-mmap --stream-skip=1 --stream-count=1 --stream-to=test.raw --verbos
VIDIOC_QUERYCAP: ok
VIDIOC_S_EXT_CTRLS: ok
VIDIOC_G_FMT: ok
VIDIOC_S_FMT: ok
Format Video Capture:
Width/Height : 4056/3040
Pixel Format : 'RG10'
Field : None
Bytes per Line : 8192
Size Image : 24903680
Colorspace : sRGB
Transfer Function : Default
YCbCr Encoding : Default
Quantization : Default
Flags :
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, done
Field : None
Sequence : 0
Length : 24903680
Bytesused: 24903680
Timestamp: 1014.709862s (Unknown, Start-of-Exposure)
Index : 1
Type : Video Capture
Flags : mapped, done
Field : None
Sequence : 1
Length : 24903680
Bytesused: 24903680
Timestamp: 1014.743188s (Unknown, Start-of-Exposure)
VIDIOC_STREAMOFF: ok
nvidia@jetson-randy2:~$ date
Thu Jan 17 15:50:04 UTC 2019
which doesn’t seem to be the case. Perhaps I am overlooking something here. How do we get the V4L2 to timestamp the start of frames using the realtime clock?