[gstreamer-bugs] [Bug 599292] Synchronizing two RTP streams from different devices using RTCP is inaccurate.

GStreamer (bugzilla.gnome.org) bugzilla at gnome.org
Wed Jan 20 01:53:50 PST 2010


https://bugzilla.gnome.org/show_bug.cgi?id=599292
  GStreamer | gst-plugins-good | git

--- Comment #9 from Per Smitt <slow.racoon at gmail.com> 2010-01-20 09:53:44 UTC ---
There were a few mistakes in the previous patch, so I have made this one to try
to be a bit more concise.

The original problem comes from trying to synchronize an RTP stream with
another RTP stream from another device using RTCP. Let us assume that the other
device is perfect to be able to focus entirely on the issue with GStreamer
here.

Both devices share a common wall-clock to ensure that the NTP clock is
"exactly" the same on both devices.

However, in GStreamer the rtpmanager does not read what the clock really is but
rather calculates the NTP time from a running-time and an NTP base-time.
Unfortunately this is not very accurate and on an embedded system the time this
calculated time can differ from real time with several tenth of seconds.

As a matter of fact the NTP time is calculated using two different formulas.
One is used when sending RTP packets and one is used when sending RTCP.  If
these two formulas were used at the exact same point in time two different
timestamps would have been obtained.

RTCP formula:
base_time = GST_ELEMENT_CAST (rtpsession)->base_time;
ntpnsbase = rtpsession->priv->ntpnsbase;
rt = gst_clock_get_time (clock) - base_time;
ntpns = rt + ntpnsbase;

RTP formula:
ntpnstime =
    gst_segment_to_running_time (&rtpsession->send_rtp_seg, GST_FORMAT_TIME,
    timestamp);
ntpnstime += priv->ntpnsbase;

When sending the RTCP packet, the RTP timestamp is based on a substraction
between the NTP time the last RTP packet was sent and the current NTP time.
Since these NTP times are skewing the resulting RTP timestamp is wrong and
causing a ~200ms offset in the synchronization.

Solution attempt:
When the RTP packets are sent the buffer timestamp is saved together with the
last RTP timestamp.

When sending the RTCP packet the NTP time is polled from the system clock, to
get an exact value. The pipeline clock is also polled to get the current time
of the pipeline, which can be compared with the saved buffer timestamp.

The times then sent with the RTCP are the exact NTP time and an RTP time which
is calculated as:
RTP timestamp = last RTP timestamp + pipeline time - last buffer timestamp
The diff pipeline time - last buffer timestamp will give us the exact time that
has passed since the last RTP packet, thus giving us two very exact times for
the RTCP

When verifying using wireshark and looking at 2 RTP packets and 1 RTCP packets
the times were accurate down to 100 microseconds.

Diff between two RTP packets
UTC Diff: 3.487038
RTP Diff: 3.487044444444444444

Diff between RTP and RTCP packet
UTC Diff: 2.328304
RTP Diff: 2.328355555555555556

-- 
Configure bugmail: https://bugzilla.gnome.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.




More information about the Gstreamer-bugs mailing list