struct v4l2_requestbuffersThe sizeof(struct v4l2_requestbuffers) is 16 bytes running in kernel, while 20 bytes running in user compiled native program. I checked the structure size in detail and found that the sizeof(enum v4l2_buf_type) and sizeof(enum v4l2_memory) are both 1. The actual size of this structure is 4 + 1 + 1 + 8 = 14 bytes. The two continuous enum occupy 4 bytes for DWORD alignment.
{
__u32 count;
enum v4l2_buf_type type;
enum v4l2_memory memory;
__u32 reserved[2];
};
In user compiled native program, the sizeof(enum) is 4. Total sizeof(struct) is 20 bytes. Only the size will not cause big problems. But the variable VIDIOC_REQBUFS will be affected by the size of the structure. See following _IOWR definition.
#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))That causes the VIDIOC_REQBUFS can't be matched in the kernel code.
To fix the problem, change the structure to the following:
struct v4l2_requestbuffersFor DWORD alignment, both enum will occupy 4 bytes although each one is 1 byte long in kernel.
{
__u32 count;
enum v4l2_buf_type type;
__u32 reserved[2];
enum v4l2_memory memory;
};