jitterbuffer: timeouts may be called context_wait / 2 too early

Take this into account to determine what packets need sending out.
This commit is contained in:
Mathieu Duponchelle 2019-09-23 21:34:00 +02:00
parent c5d5cdcd9d
commit 5976c9c1e4

View file

@ -783,6 +783,7 @@ impl JitterBuffer {
fn schedule(&self, state: &mut MutexGuard<State>, element: &gst::Element) { fn schedule(&self, state: &mut MutexGuard<State>, element: &gst::Element) {
let settings = self.settings.lock().unwrap().clone(); let settings = self.settings.lock().unwrap().clone();
let latency_ns = settings.latency_ms as u64 * gst::MSECOND; let latency_ns = settings.latency_ms as u64 * gst::MSECOND;
let context_wait_ns = settings.context_wait as u64 * gst::MSECOND;
drop(settings); drop(settings);
let now = self.get_current_running_time(element); let now = self.get_current_running_time(element);
@ -839,7 +840,8 @@ impl JitterBuffer {
/* Check earliest PTS as we have just taken the lock */ /* Check earliest PTS as we have just taken the lock */
if state.earliest_pts.is_some() if state.earliest_pts.is_some()
&& state.earliest_pts + latency_ns - state.packet_spacing < now && state.earliest_pts + latency_ns - state.packet_spacing - context_wait_ns / 2
< now
{ {
loop { loop {
let (head_pts, head_seq) = state.jbuf.borrow().peek(); let (head_pts, head_seq) = state.jbuf.borrow().peek();
@ -869,7 +871,10 @@ impl JitterBuffer {
if state.pending_future_cancel.is_some() if state.pending_future_cancel.is_some()
|| state.earliest_pts.is_none() || state.earliest_pts.is_none()
|| state.earliest_pts + latency_ns - state.packet_spacing >= now || state.earliest_pts + latency_ns
- state.packet_spacing
- context_wait_ns / 2
>= now
{ {
break; break;
} }