Magistratsbeamter
Magistratsbeamter

Reputation: 112

Server/Client UDP Packets synchronisation

I have one computer which sends exactly every 5 millisecond a UDP packet with measurement data.

Another computer, with an high speed line scan camera included, receives these packets and fills the packetdata as additional data into the endless camera image.

The problem is that the packets did not arrive every 5 milliseconds. Thats OK. I know that network packets have jitter. Sometimes 10 ms delay, sometimes there is no delay between two packets. So its not a good idea to fill the UDP data into that endless image at the moment they arrive.

Time --------------------------------------------------------------------> 
UDP Packets: A   B  C     D    E   F       G  H     I  J      K ....
Cam Lines:   012345678901234567890123456789012345678901234567890 ...
Optimal:     A    B    C    D    E    F    G    H    I    J    K ...

Does anyone know an goot synchronisation algorithm to solve this problem? One difficulty is the fact that this is an endless running system and the synchronisation has to be self adjusting.

Upvotes: 1

Views: 955

Answers (1)

TJD
TJD

Reputation: 11896

With any streaming system like this where you have inter packet jitter, you want to implement a jitter buffer and decouple the playback from the data receive. Receive your packets in a buffer (size depends on how much jitter you might have). Don't start playing any data out until your buffer is half full (or some other threshold you choose). Then you have a playback thread that just reads from the jitter buffer every 5ms and does the output.

Upvotes: 4

Related Questions