I have an app based on sample 12_camera_v4l2_cuda which takes frames from a v4l2 device and writes them to a V4L2_MEMORY_DMABUF for use with nvbuf_utils. I recently updated to kernel 4.9 (specifically l4t r32.2.1) and I noticed that the v4l2 timestamps are no longer being populated by VIDIOC_DQBUF.
I know quite a lot has changed with the update to 4.9, is there something I am missing to get the v4l2 timestamps to work?
Using the vb2_v4l2_buffer instead of the v4l2_buffer.
struct vb2_v4l2_buffer {
struct vb2_buffer vb2_buf;
__u32 flags;
__u32 field;
struct v4l2_timecode timecode;
__u32 sequence;
};
struct vb2_buffer {
struct vb2_queue *vb2_queue;
unsigned int index;
unsigned int type;
unsigned int memory;
unsigned int num_planes;
struct vb2_plane planes[VB2_MAX_PLANES];
u64 timestamp;
/* private: internal use only
*
* state: current buffer state; do not change
* queued_entry: entry on the queued buffers list, which holds
* all buffers queued from userspace
* done_entry: entry on the list that stores all buffers ready
* to be dequeued to userspace
*/
enum vb2_buffer_state state;
struct list_head queued_entry;
struct list_head done_entry;
#ifdef CONFIG_VIDEO_ADV_DEBUG
/*
* Counters for how often these buffer-related ops are
* called. Used to check for unbalanced ops.
*/
u32 cnt_mem_alloc;
u32 cnt_mem_put;
u32 cnt_mem_get_dmabuf;
u32 cnt_mem_get_userptr;
u32 cnt_mem_put_userptr;
u32 cnt_mem_prepare;
u32 cnt_mem_finish;
u32 cnt_mem_attach_dmabuf;
u32 cnt_mem_detach_dmabuf;
u32 cnt_mem_map_dmabuf;
u32 cnt_mem_unmap_dmabuf;
u32 cnt_mem_vaddr;
u32 cnt_mem_cookie;
u32 cnt_mem_num_users;
u32 cnt_mem_mmap;
u32 cnt_buf_init;
u32 cnt_buf_prepare;
u32 cnt_buf_finish;
u32 cnt_buf_cleanup;
u32 cnt_buf_queue;
/* This counts the number of calls to vb2_buffer_done() */
u32 cnt_buf_done;
#endif
};
vb2_buffer is defined in videobuf2-core.h which is only available in the kernel source. Trying to include it in user space causes a whole host of issues.
When that failed I spent some time trying to cherry pick out the struct definitions (vb2_buffer, vb2_queue, vb2_plane, etc) but that quickly got down to some includes only available in the kernel source.
I don’t think that using vb2_buffer (or vb2_v4l2_buffer) is an option in user space.
I added the flag, but the timestamp is still zero.
Just to be clear I am still using a v4l2_buffer with ioctl VIDIOC_DQBUF just like sample 12_camera_v4l2_cuda since I was unable to include the definition for vb2_buffer.
In my app I was excited to see that timecode.seconds was incrementing, however the value continued to increment past 60 which shouldn’t be possible since I am setting it with a modulus of 60. The other fields (hours, minutes, and userbits) were all 0. Could there be something downstream that is using the timecode field already?
I mean have the APP to get the timecode instead to modify the kernel driver.
Modify the 12_camera_v4l2_cuda to get the v4l2_buf.timecode for the frame timestamp as WAR.
@ShaneCCC timecode isn’t going to work for my application. I am using the timestamps to do a rough synchronization of two V4L2 streams so I really need the microseconds/nanoseconds.
Due to the structure of the timestamp in the vb2_buffer change to u64. It’s different with timestamp struct in the v4l2_buffer.
VI driver set the timestamp by timespec_to_ns(ts), could you check if it’s validate time in the v4l2_buf.timestamp by u64
I can get the timestamp from the v4l2-ctl by --verbose
nvidia@nvidia-desktop:~$ v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=RG10 --set-ctrl bypass_mode=0 --stream-mmap --stream-count=10 -d /dev/video1 --verbose
VIDIOC_QUERYCAP: ok
VIDIOC_S_EXT_CTRLS: ok
VIDIOC_G_FMT: ok
VIDIOC_S_FMT: ok
Format Video Capture:
Width/Height : 2592/1944
Pixel Format : 'RG10'
Field : None
Bytes per Line : 5376
Size Image : 10450944
Colorspace : sRGB
Transfer Function : Default (maps to sRGB)
YCbCr/HSV Encoding: Default (maps to ITU-R 601)
Quantization : Default (maps to Full Range)
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
Field : None
Sequence : 0
Length : 10450944
Bytesused: 10450944
Timestamp: 104.523741s (Monotonic, End-of-Frame)
Index : 1
Type : Video Capture
Flags : mapped
Field : None
Sequence : 1
Length : 10450944
Bytesused: 10450944
Timestamp: 104.557072s (Monotonic, End-of-Frame)
Index : 2
Type : Video Capture
Flags : mapped
Field : None
Sequence : 2
Length : 10450944
Bytesused: 10450944
Timestamp: 104.590403s (Monotonic, End-of-Frame)
Index : 3
Type : Video Capture
Flags : mapped
Field : None
Sequence : 3
Length : 10450944
Bytesused: 10450944
Timestamp: 104.623734s (Monotonic, End-of-Frame)
in the VI4 driver, it’ll convert by ns_to_timespec() to fill-in timespec,
could you please enable that debug prints to check sof_ts still return correct values.
thanks
@ShaneCCC I am getting 0 for timestamp with v4l2-ctl also:
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: 0.000000s (Monotonic, End-of-Frame)
Index : 1
Type : Video Capture
Flags : mapped
Field : None
Sequence : 1
Length : 1843200
Bytesused: 1843200
Timestamp: 0.000000s (Monotonic, End-of-Frame)
Index : 2
Type : Video Capture
Flags : mapped
Field : None
Sequence : 2
Length : 1843200
Bytesused: 1843200
Timestamp: 0.000000s (Monotonic, End-of-Frame)
Index : 3
Type : Video Capture
Flags : mapped
Field : None
Sequence : 3
Length : 1843200
Bytesused: 1843200
Timestamp: 0.000000s (Monotonic, End-of-Frame)
Index : 0
Type : Video Capture
Flags : mapped
Field : None
Sequence : 4
Length : 1843200
Bytesused: 1843200
Timestamp: 0.000000s (Monotonic, End-of-Frame)
Index : 1
Type : Video Capture
Flags : mapped
Field : None
Sequence : 5
Length : 1843200
Bytesused: 1843200
Timestamp: 0.000000s (Monotonic, End-of-Frame)
Index : 2
Type : Video Capture
Flags : mapped
Field : None
Sequence : 6
Length : 1843200
Bytesused: 1843200
Timestamp: 0.000000s (Monotonic, End-of-Frame)
Index : 3
Type : Video Capture
Flags : mapped
Field : None
Sequence : 7
Length : 1843200
Bytesused: 1843200
Timestamp: 0.000000s (Monotonic, End-of-Frame)
Index : 0
Type : Video Capture
Flags : mapped
Field : None
Sequence : 8
Length : 1843200
Bytesused: 1843200
Timestamp: 0.000000s (Monotonic, End-of-Frame)
Index : 1
Type : Video Capture
Flags : mapped
Field : None
Sequence : 9
Length : 1843200
Bytesused: 1843200
Timestamp: 0.000000s (Monotonic, End-of-Frame)
VIDIOC_STREAMOFF: ok