Skip to contentSkip to conversation

media: uvcvideo: Support borderline implementation of hw timestamping

PATCH In review Ricardo Ribalda 2 participants 2 messages Aug 17, 2021 – Aug 19, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: uvcvideo: Support borderline implementation of hw timestamping

Some cameras do not set pts and src if there is no camera data in the buffer. They do this without clearing the PTS and SCR bits of the header. This is probably done due to a strict/borderline interpretation of the standard:

"STC must be captured when the first video data of a video frame is put on the USB bus."

Eg:
buffer: 0xa7755c00 len 000012 header:0x8c stc 00000000 sof 0000 pts 00000000
buffer: 0xa7755c00 len 000012 header:0x8c stc 00000000 sof 0000 pts 00000000
buffer: 0xa7755c00 len 000668 header:0x8c stc 73779dba sof 070c pts 7376d37a

Support those cameras by only decoding the clock if there is camera data in the buffer.

---
 drivers/media/usb/uvc/uvc_video.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/media/usb/uvc/uvc_video.c +12 -0
index e16464606b14..6d0e474671a2 100644
@@ -490,6 +490,18 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf,
 	if (len < header_size)
 		return;
 
+	/*
+	 * Some cameras when there is no camera data in a buffer, do not
+	 * handle properly the pts and scr. This can be due to an borderline
+	 * interpretation of the standard: "STC must be captured when the
+	 * first video data of a video frame is put on the USB bus."
+	 * Due to their internal design, their firmware cannot clear the
+	 * UVC_STREAM_PTS and UVC_STREAM_SCR bits. Which forces us to use the
+	 * length of the buffer to decide if pts and scr are valid or not.
+	 */
+	if (len == header_size)
+		return;
+
 	/* Extract the timestamps:
 	 *
 	 * - store the frame PTS in the buffer structure
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
maintainer
#1 lore raw

Hi Ricardo,

Thank you for the patch.

Quoted 8 lines · Ricardo Ribalda

Some cameras do not set pts and src if there is no camera data in the buffer. They do this without clearing the PTS and SCR bits of the header. This is probably done due to a strict/borderline interpretation of the standard:

"STC must be captured when the first video data of a video frame is put on the USB bus."

Quoted 7 lines

Eg:
buffer: 0xa7755c00 len 000012 header:0x8c stc 00000000 sof 0000 pts 00000000
buffer: 0xa7755c00 len 000012 header:0x8c stc 00000000 sof 0000 pts 00000000
buffer: 0xa7755c00 len 000668 header:0x8c stc 73779dba sof 070c pts 7376d37a

Support those cameras by only decoding the clock if there is camera data in the buffer.

Which cameras do you know to be affected ?

Quoted 15 lines
---
 drivers/media/usb/uvc/uvc_video.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/media/usb/uvc/uvc_video.c +2 -0
index e16464606b14..6d0e474671a2 100644
@@ -490,6 +490,18 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf,
 	if (len < header_size)
 		return;
 
+	/*
+	 * Some cameras when there is no camera data in a buffer, do not

drivers/media/usb/uvc/uvc_video.c uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, · line 504

Quoted 10 lines
drivers/media/usb/uvc/uvc_video.c +10 -0
+	 * handle properly the pts and scr. This can be due to an borderline
+	 * interpretation of the standard: "STC must be captured when the
+	 * first video data of a video frame is put on the USB bus."
+	 * Due to their internal design, their firmware cannot clear the
+	 * UVC_STREAM_PTS and UVC_STREAM_SCR bits. Which forces us to use the
+	 * length of the buffer to decide if pts and scr are valid or not.
+	 */
+	if (len == header_size)
+		return;
+

Won't this prevent using timestamp data provided by cameras that behave properly ?

Quoted 3 lines
drivers/media/usb/uvc/uvc_video.c +0 -0
 	/* Extract the timestamps:
 	 *
 	 * - store the frame PTS in the buffer structure
Signature · 3 lines
Regards,

Laurent Pinchart