diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2009-09-01 12:41:36 +0200 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2009-09-01 12:48:28 +0200 |
commit | 8d924611e74ba8b6c36fe24db5b3648850751bf7 (patch) | |
tree | 4eb643c5a3ee40f993f787c7cad00789dd5848b2 /gst/rtpmanager/rtpjitterbuffer.c | |
parent | bfb1260af45db7572a33e49b7b4e9a4be38d30e3 (diff) |
jitterbuffer: make sure time does not go backwards
When we construct a timestamp that would result in a timestamp that is earlier
than when the packet was received, reset the skew calculation as this is
probably a sign that the sender restarted or paused.
Fixes #593354
Diffstat (limited to 'gst/rtpmanager/rtpjitterbuffer.c')
-rw-r--r-- | gst/rtpmanager/rtpjitterbuffer.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/gst/rtpmanager/rtpjitterbuffer.c b/gst/rtpmanager/rtpjitterbuffer.c index a38c2141..86629e87 100644 --- a/gst/rtpmanager/rtpjitterbuffer.c +++ b/gst/rtpmanager/rtpjitterbuffer.c @@ -183,7 +183,7 @@ rtp_jitter_buffer_resync (RTPJitterBuffer * jbuf, GstClockTime time, * * Both the window and the weighting used for averaging influence the accuracy * of the drift estimation. Finding the correct parameters turns out to be a - * compromise between accuracy and inertia. + * compromise between accuracy and inertia. * * We use a 2 second window or up to 512 data points, which is statistically big * enough to catch spikes (FIXME, detect spikes). @@ -195,7 +195,7 @@ rtp_jitter_buffer_resync (RTPJitterBuffer * jbuf, GstClockTime time, */ static GstClockTime calculate_skew (RTPJitterBuffer * jbuf, guint32 rtptime, GstClockTime time, - guint32 clock_rate) + guint32 clock_rate, GstClockTime max_delay) { guint64 ext_rtptime; guint64 send_diff, recv_diff; @@ -278,7 +278,7 @@ calculate_skew (RTPJitterBuffer * jbuf, guint32 rtptime, GstClockTime time, * changed too quickly we have to resync because the server likely restarted * its timestamps. */ if (ABS (delta - jbuf->skew) > GST_SECOND) { - GST_WARNING ("delta %" GST_TIME_FORMAT " too big, reset skew", + GST_WARNING ("delta - skew: %" GST_TIME_FORMAT " too big, reset skew", GST_TIME_ARGS (delta - jbuf->skew)); rtp_jitter_buffer_resync (jbuf, time, gstrtptime, ext_rtptime, TRUE); send_diff = 0; @@ -386,6 +386,18 @@ no_skew: out_time = jbuf->prev_out_time; } } + + if (out_time + max_delay < time) { + /* if we are going to produce a timestamp that is later than the input + * timestamp, we need to reset the jitterbuffer. Likely the server paused + * temporarily */ + GST_DEBUG ("out %" GST_TIME_FORMAT " + %" G_GUINT64_FORMAT " < time %" + GST_TIME_FORMAT ", reset jitterbuffer", GST_TIME_ARGS (out_time), + max_delay, GST_TIME_ARGS (time)); + rtp_jitter_buffer_resync (jbuf, time, gstrtptime, ext_rtptime, TRUE); + out_time = time; + send_diff = 0; + } } else out_time = -1; @@ -404,6 +416,7 @@ no_skew: * @buf: a buffer * @time: a running_time when this buffer was received in nanoseconds * @clock_rate: the clock-rate of the payload of @buf + * @max_delay: the maximum lateness of @buf * @tail: TRUE when the tail element changed. * * Inserts @buf into the packet queue of @jbuf. The sequence number of the @@ -415,7 +428,8 @@ no_skew: */ gboolean rtp_jitter_buffer_insert (RTPJitterBuffer * jbuf, GstBuffer * buf, - GstClockTime time, guint32 clock_rate, gboolean * tail) + GstClockTime time, guint32 clock_rate, GstClockTime max_delay, + gboolean * tail) { GList *list; guint32 rtptime; @@ -449,7 +463,7 @@ rtp_jitter_buffer_insert (RTPJitterBuffer * jbuf, GstBuffer * buf, * receive time, this function will retimestamp @buf with the skew corrected * running time. */ rtptime = gst_rtp_buffer_get_timestamp (buf); - time = calculate_skew (jbuf, rtptime, time, clock_rate); + time = calculate_skew (jbuf, rtptime, time, clock_rate, max_delay); GST_BUFFER_TIMESTAMP (buf) = time; /* It's more likely that the packet was inserted in the front of the buffer */ |