Hi Paul,

> I see two fields in v4l2_buffer, which are used for time stamps: timecode
> and timestamp. The timecode field lacks sufficient resolution for our
> purpose, because it was designed with analog video standards in mind.
> Besides, it seems that something similar to timecode is already being
> embedded in MPEG stream by the camera. The timestamp field looks almost
> perfect for our purpose - resolution could be better, but a microsecond is
> good enough.

Agreed. Let's use the timestamp field.

> The most comprehensive solution, following the spirit of V4L2 
> specs, would involve camera and PC clock synchronization. In practical
> terms, it would mean finding the system time (Tn) of creation of SOF packet
> number n and using SOF counter value (m) and System Time Clock (Tm) from
> scrSourceClock and dwPresentationTime (Tp) to calculate frame creation time
> (t) in PC system time:
>
> t = Tn + (m-n)*125us + ((Tm-Tp)%dwClockFrequency)/dwClockFrequency 
> (sketchy)
>
> Before I go any further, it would help to find out the following:
>
> 1) Are we getting both dwPresentationTime and scrSourceClock in the Payload
> Header (controlled by bits 2 and 3 of bmHeaderInfo)? It seems that cameras
> without microphone may not provide them (page 34 of USB Class Definition
> for Video Devices).

I tested various webcams. One of them didn't include the PTS and SCR fields in 
any packet. All others did.

> 2) More importantly, is the camera SOF counter the same as host SOF
> counter? Possibility of different counting is mentioned on page 33 of USB
> Class Definition for Video Devices. If counters are different, finding the
> offset may be very difficult.

The specification doesn't call for a single counter, so we unfortunately can't 
rely on that.

As the device SOF counter and the host SOF counter have different values, the 
above formula will be very difficult to use. The PTS and SCR fields have been 
designed to synchronise multiple video and audio streams from a single 
device. Synchronising video streams from separate devices seem to be outside 
the scope of the UVC specification :-/

On the other hand, some webcams might synchronise their SOF counter with the 
host SOF counter. For those devices, the driver might be able to synchronise 
multiple webcams. I had a look at the USB stack source code, and found no way 
to get the host time at which a SOF packet is issued. That could be a 
problem.

Chapter 5.12 in the USB 2.0 specification discuss clock synchronisation 
issues, you might find some help there.

Best regards,

Laurent Pinchart
_______________________________________________
Linux-uvc-devel mailing list
Linux-uvc-devel@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/linux-uvc-devel

Reply via email to