How to read the UVC payload header on Linux

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
rossihwang
Level 3
Level 3
5 questions asked 50 sign-ins 25 replies posted

My device is fx3.

- I tried read UVC header via v4l2(https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/pixfmt-meta-uvc.html)

- The procedure is something like that in librealsense(https://github.com/IntelRealSense/librealsense/blob/master/src/linux/backend-v4l2.h). Open the video capture and meta device synchronously, after streamon, read video capture and meta one by one.

- In my experiment, the meta buffer is zero length as below shown

vidcap, buf: index: 0, byteused: 1843200, length: 1843200, ts: 90818755
meta, buf: index: 0, bytesused: 0, length: 1024, flags: 12000, ts: 90818755
vidcap, buf: index: 1, byteused: 1843200, length: 1843200, ts: 90818787
meta, buf: index: 1, bytesused: 0, length: 1024, flags: 12000, ts: 90818787
vidcap, buf: index: 2, byteused: 1843200, length: 1843200, ts: 90818823
meta, buf: index: 2, bytesused: 0, length: 1024, flags: 12000, ts: 90818823
vidcap, buf: index: 0, byteused: 1843200, length: 1843200, ts: 90818855
meta, buf: index: 0, bytesused: 0, length: 1024, flags: 12000, ts: 90818855
vidcap, buf: index: 1, byteused: 1843200, length: 1843200, ts: 90818891
meta, buf: index: 1, bytesused: 0, length: 1024, flags: 12000, ts: 90818891
vidcap, buf: index: 2, byteused: 1843200, length: 1843200, ts: 90818923
meta, buf: index: 2, bytesused: 0, length: 1024, flags: 12000, ts: 90818923
vidcap, buf: index: 0, byteused: 1843200, length: 1843200, ts: 90818955
meta, buf: index: 0, bytesused: 0, length: 1024, flags: 12000, ts: 90818955
vidcap, buf: index: 1, byteused: 1843200, length: 1843200, ts: 90818991
meta, buf: index: 1, bytesused: 0, length: 1024, flags: 12000, ts: 90818991
vidcap, buf: index: 2, byteused: 1843200, length: 1843200, ts: 90819023
meta, buf: index: 2, bytesused: 0, length: 1024, flags: 12000, ts: 90819023
vidcap, buf: index: 0, byteused: 1843200, length: 1843200, ts: 90819059
meta, buf: index: 0, bytesused: 0, length: 1024, flags: 12000, ts: 90819059

 

Any suggestions, Thanks in advance.

 

Regards

Rossi

0 Likes
1 Solution

Hello Rossi,

As you will be aware that the standard UVC header payload is appended to the start of each buffer. The buffer received can be parsed to get the header length and parse different fields to get the  header information.

Similar, implementation is seen here 

Regards,
Rashi

View solution in original post

0 Likes
6 Replies
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

Please let me know the metadata added to the UVC header from FX3. From the link shared, it looks like Meta data is not the same the UVC header but is in addition to the UVC header.

Kindly refer to V4L2-ctl app to understand how to read the UVC header from the Host app.

Regards,
Rashi
0 Likes

Hi,

Thank Rashi for your fast reply.

The added UVC header in my test is the "12 bytes standard UVC header" as that in example an75779

/* UVC Header to be prefixed at the top of each 16 KB video data buffer. */
uint8_t volatile glUVCHeader[CY_FX_UVC_MAX_HEADER] = {
0x0C, /* Header Length */
0x8C, /* Bit field header field */
0x00, 0x00, 0x00, 0x00, /* Presentation time stamp field */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* Source clock reference field */
};
 
For the v4l2-utils, I found it is not fully supporting metadata even the standard UVC header though it has some code parsing the data struct "uvc_meta_buf" in https://github.com/gjasny/v4l-utils/blob/master/utils/v4l2-ctl/v4l2-ctl-meta.cpp. Or maybe some misunderstanding on my side, could you show me the command to display the UVC header of fx3 via v4l2-ctl?
 
 
In addition, I found librealsense had done some modifications on the kernel to enable metadata output, https://github.com/IntelRealSense/librealsense/blob/master/scripts/realsense-metadata-focal-master.p.... I'm not sure whether it is also needed for the standard header?
 
Thanks
 
Regards
Rossi
0 Likes

Hello Rossi,

As you will be aware that the standard UVC header payload is appended to the start of each buffer. The buffer received can be parsed to get the header length and parse different fields to get the  header information.

Similar, implementation is seen here 

Regards,
Rashi
0 Likes

Hi Rashi

As I use the v4l2 interface, it seems impossible to access the raw buffer of the UVC since v4l2 doesn't expose it to me. Do I have to modify the driver like librealsense did?

Regards

Rossi

0 Likes
rossihwang
Level 3
Level 3
5 questions asked 50 sign-ins 25 replies posted

Hi Rashi

Finally, I find out why there's no buffer read. As the comment in the link you provided above https://github.com/torvalds/linux/blob/master/drivers/media/usb/uvc/uvc_video.c#L1300. the UVC driver does some validations on the SCR data. The an75779 sends constant SCR which violates the validation.

Regards

Rossi 

0 Likes

Hello Rossi,

Glad to hear that the link was helpful

Regards,
Rashi
0 Likes