Skip to content

Instantly share code, notes, and snippets.

@simonkim
Last active January 25, 2024 16:40
Show Gist options
  • Save simonkim/a9a3aa4f1ca04448c64212b3b079d107 to your computer and use it in GitHub Desktop.
Save simonkim/a9a3aa4f1ca04448c64212b3b079d107 to your computer and use it in GitHub Desktop.
RTP - Synchronizing media streams

RTP Note

Synchronizing media streams

Implementation of NTP is not required to use RTP.

An implementation is not required to run the Network Time Protocol in order to use RTP. -- 4. Byte Order, Alignment, and Time Format, RFC 3550 RTP: A Transport Protocol for Real-Time Applications

However, if NTP timestamp implemented in RTCP, it can be used to synchronize media streams even from different host!

... Instead, for each medium the RTP timestamp is related to the sampling instant by pairing it with a timestamp from a reference clock (wallclock) that represents the time when the data corresponding to the RTP timestamp was sampled. The reference clock is shared by all media to be synchronized. The timestamp pairs are not transmitted in every data packet, but at a lower rate in RTCP SR packets as described in Section 6.4. ... The audio and video may even be transmitted by different hosts if the reference clocks on the two hosts are synchronized by some means such as NTP. A receiver can then synchronize presentation of the audio and video packets by relating their RTP timestamps using the timestamp pairs in RTCP SR packets. -- 5.1 RTP Fixed Header Fields, RFC 3550 RTP: A Transport Protocol for Real-Time Applications

RTP Mixer

Mixer: Receives streams of RTP data packets from one or more sources, possibly changes the data format, combines the streams in some manner and then forwards the combined stream. Since the timing among multiple input sources will not generally be synchronized, the mixer will make timing adjustments among the streams and generate its own timing for the combined stream, so it is the synchronization source. --7. RTP Translators and Mixers, RFC 3550 RTP: A Transport Protocol for Real-Time Applications

Example setup of RTP Mixer

Receiver->Mixer: Mix and give it to me
Note right of Mixer: Mix...
SSRC1-->Mixer: stream
SSRC2-->Mixer: stream
SSRC3-->Mixer: stream
Note right of Mixer: ... and Go!
Mixer-->Receiver: mixed stream

Diagram in js-sequence-diagrams syntax

Mixer Implementations, or similar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment