jitterbuffer: estimate inter packet spacing

When we see two packets with consecutive seqnums and a different RTP time, use
the DTS difference as the inter packet spacing estimate.
This commit is contained in:
Wim Taymans 2013-08-01 12:07:11 +02:00
parent 255b7106f5
commit fe32e80c92

View file

@ -150,6 +150,10 @@ struct _GstRtpJitterBufferPrivate
GstClockTime last_out_time;
GstClockTime last_out_dts;
GstClockTime last_out_pts;
/* last valid input timestamp and rtptime pair */
GstClockTime last_in_dts;
GstClockTime last_in_rtptime;
GstClockTime packet_spacing;
/* the next expected seqnum we receive */
guint32 next_in_seqnum;
@ -902,6 +906,9 @@ gst_rtp_jitter_buffer_flush_stop (GstRtpJitterBuffer * jitterbuffer)
priv->last_out_dts = -1;
priv->last_out_pts = -1;
priv->next_seqnum = -1;
priv->last_in_rtptime = -1;
priv->last_in_dts = GST_CLOCK_TIME_NONE;
priv->packet_spacing = 0;
priv->next_in_seqnum = -1;
priv->clock_rate = -1;
priv->eos = FALSE;
@ -1278,6 +1285,7 @@ gst_rtp_jitter_buffer_chain (GstPad * pad, GstObject * parent,
GstRtpJitterBuffer *jitterbuffer;
GstRtpJitterBufferPrivate *priv;
guint16 seqnum;
guint32 rtptime;
GstFlowReturn ret = GST_FLOW_OK;
GstClockTime dts, pts;
guint64 latency_ts;
@ -1295,6 +1303,7 @@ gst_rtp_jitter_buffer_chain (GstPad * pad, GstObject * parent,
pt = gst_rtp_buffer_get_payload_type (&rtp);
seqnum = gst_rtp_buffer_get_seq (&rtp);
rtptime = gst_rtp_buffer_get_timestamp (&rtp);
gst_rtp_buffer_unmap (&rtp);
/* make sure we have PTS and DTS set */
@ -1382,6 +1391,23 @@ gst_rtp_jitter_buffer_chain (GstPad * pad, GstObject * parent,
priv->last_popped_seqnum = -1;
priv->next_seqnum = seqnum;
}
/* reset spacing estimation when gap */
priv->last_in_rtptime = -1;
priv->last_in_dts = -1;
} else {
/* packet is expected, we need consecutive seqnums with a different
* rtptime to estimate the packet spacing. */
if (priv->last_in_rtptime != rtptime) {
/* rtptime changed, check dts diff */
if (priv->last_in_dts != -1 && dts != -1 && dts > priv->last_in_dts) {
priv->packet_spacing = dts - priv->last_in_dts;
GST_DEBUG_OBJECT (jitterbuffer,
"new packet spacing %" GST_TIME_FORMAT,
GST_TIME_ARGS (priv->packet_spacing));
}
priv->last_in_rtptime = rtptime;
priv->last_in_dts = dts;
}
}
}
priv->next_in_seqnum = (seqnum + 1) & 0xffff;