mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 20:21:24 +00:00
jitterbuffer: rework resync handling
Add a need-resync state, this is when we need to try to lock on to a time/RTPtime pair. Always check the RTP timestamps and if they go backwards, mark ourselves as need-resync. Only resync when need-resync is TRUE and we have a valid time. Otherwise we keep the old values. This avoids locking on to an invalid time and causing us to timestamp everything with -1. Fixes https://bugzilla.gnome.org/show_bug.cgi?id=730417
This commit is contained in:
parent
bd392d72ee
commit
2e7f5c08cf
2 changed files with 21 additions and 23 deletions
|
@ -219,6 +219,7 @@ rtp_jitter_buffer_reset_skew (RTPJitterBuffer * jbuf)
|
|||
jbuf->skew = 0;
|
||||
jbuf->prev_send_diff = -1;
|
||||
jbuf->prev_out_time = -1;
|
||||
jbuf->need_resync = TRUE;
|
||||
GST_DEBUG ("reset skew correction");
|
||||
}
|
||||
|
||||
|
@ -251,6 +252,7 @@ rtp_jitter_buffer_resync (RTPJitterBuffer * jbuf, GstClockTime time,
|
|||
jbuf->window_size = 0;
|
||||
jbuf->skew = 0;
|
||||
}
|
||||
jbuf->need_resync = FALSE;
|
||||
}
|
||||
|
||||
static guint64
|
||||
|
@ -425,33 +427,28 @@ calculate_skew (RTPJitterBuffer * jbuf, guint32 rtptime, GstClockTime time)
|
|||
/* keep track of the last extended rtptime */
|
||||
jbuf->last_rtptime = ext_rtptime;
|
||||
|
||||
/* first time, lock on to time and gstrtptime */
|
||||
if (G_UNLIKELY (jbuf->base_time == -1)) {
|
||||
jbuf->base_time = time;
|
||||
jbuf->prev_out_time = -1;
|
||||
GST_DEBUG ("Taking new base time %" GST_TIME_FORMAT, GST_TIME_ARGS (time));
|
||||
}
|
||||
if (G_UNLIKELY (jbuf->base_rtptime == -1)) {
|
||||
jbuf->base_rtptime = gstrtptime;
|
||||
jbuf->base_extrtp = ext_rtptime;
|
||||
jbuf->prev_send_diff = -1;
|
||||
GST_DEBUG ("Taking new base rtptime %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (gstrtptime));
|
||||
send_diff = 0;
|
||||
if (G_LIKELY (jbuf->base_rtptime != -1)) {
|
||||
/* check elapsed time in RTP units */
|
||||
if (G_LIKELY (gstrtptime >= jbuf->base_rtptime)) {
|
||||
send_diff = gstrtptime - jbuf->base_rtptime;
|
||||
} else {
|
||||
/* elapsed time at sender, timestamps can go backwards and thus be
|
||||
* smaller than our base time, schedule to take a new base time in
|
||||
* that case. */
|
||||
GST_WARNING ("backward timestamps at server, schedule resync");
|
||||
jbuf->need_resync = TRUE;
|
||||
send_diff = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (G_LIKELY (gstrtptime >= jbuf->base_rtptime))
|
||||
send_diff = gstrtptime - jbuf->base_rtptime;
|
||||
else if (time != -1) {
|
||||
/* elapsed time at sender, timestamps can go backwards and thus be smaller
|
||||
* than our base time, take a new base time in that case. */
|
||||
GST_WARNING ("backward timestamps at server, taking new base time");
|
||||
/* need resync, lock on to time and gstrtptime if we can, otherwise we
|
||||
* do with the previous values */
|
||||
if (G_UNLIKELY (jbuf->need_resync && time != -1)) {
|
||||
GST_WARNING ("resync to time %" GST_TIME_FORMAT ", rtptime %"
|
||||
GST_TIME_FORMAT, GST_TIME_ARGS (time), GST_TIME_ARGS (gstrtptime));
|
||||
rtp_jitter_buffer_resync (jbuf, time, gstrtptime, ext_rtptime, FALSE);
|
||||
send_diff = 0;
|
||||
} else {
|
||||
GST_WARNING ("backward timestamps at server but no timestamps");
|
||||
send_diff = 0;
|
||||
/* at least try to get a new timestamp.. */
|
||||
jbuf->base_time = -1;
|
||||
}
|
||||
|
||||
GST_DEBUG ("extrtp %" G_GUINT64_FORMAT ", gstrtp %" GST_TIME_FORMAT ", base %"
|
||||
|
|
|
@ -86,6 +86,7 @@ struct _RTPJitterBuffer {
|
|||
guint64 high_level;
|
||||
|
||||
/* for calculating skew */
|
||||
gboolean need_resync;
|
||||
GstClockTime base_time;
|
||||
GstClockTime base_rtptime;
|
||||
guint32 clock_rate;
|
||||
|
|
Loading…
Reference in a new issue