jitterbuffer: improve SR packet handling

Implement 3 different cases for handling the SR:

 1) we don't have enough timing information to handle the SR packet and
    we need to wait a little for more RTP packets. In that case we keep
    the SR packet around and retry when we get an RTP packet in the
    chain function.

 2) the SR packet has a too old timestamp and should be discarded. It is
    labeled invalid and the last_sr is cleared.

 3) the SR packet is ok and there is enough timing information, proceed
    with processing the SR packet.

Before this patch, case 2) and 1) were handled in the same way,
resulting that SR packets with too old timestamps were checked over and
over again for each RTP packet.
This commit is contained in:
Wim Taymans 2014-06-25 14:34:21 +02:00
parent f7aeb57858
commit ca9cfd40dd

View File

@ -3063,7 +3063,7 @@ do_handle_sync (GstRtpJitterBuffer * jitterbuffer)
guint64 last_rtptime;
guint64 clock_base;
guint64 ext_rtptime, diff;
gboolean drop = FALSE;
gboolean valid = TRUE, keep = FALSE;
priv = jitterbuffer->priv;
@ -3080,13 +3080,15 @@ do_handle_sync (GstRtpJitterBuffer * jitterbuffer)
ext_rtptime, base_rtptime, clock_rate, clock_base, last_rtptime);
if (base_rtptime == -1 || clock_rate == -1 || base_time == -1) {
GST_DEBUG_OBJECT (jitterbuffer, "dropping, no RTP values");
drop = TRUE;
/* we keep this SR packet for later. When we get a valid RTP packet the
* above values will be set and we can try to use the SR packet */
GST_DEBUG_OBJECT (jitterbuffer, "keeping for later, no RTP values");
keep = TRUE;
} else {
/* we can't accept anything that happened before we did the last resync */
if (base_rtptime > ext_rtptime) {
GST_DEBUG_OBJECT (jitterbuffer, "dropping, older than base time");
drop = TRUE;
valid = FALSE;
} else {
/* the SR RTP timestamp must be something close to what we last observed
* in the jitterbuffer */
@ -3108,7 +3110,9 @@ do_handle_sync (GstRtpJitterBuffer * jitterbuffer)
}
}
if (!drop) {
if (keep) {
GST_DEBUG_OBJECT (jitterbuffer, "keeping RTCP packet for later");
} else if (valid) {
GstStructure *s;
s = gst_structure_new ("application/x-rtp-sync",
@ -3128,6 +3132,7 @@ do_handle_sync (GstRtpJitterBuffer * jitterbuffer)
gst_structure_free (s);
} else {
GST_DEBUG_OBJECT (jitterbuffer, "dropping RTCP packet");
gst_buffer_replace (&priv->last_sr, NULL);
}
}