mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
rtpjitterbuffer: refactor lost event sending
Also make sure we only increment the expected seqnum and last output timestamp.
This commit is contained in:
parent
f49981a597
commit
26402e1c21
1 changed files with 54 additions and 57 deletions
|
@ -1673,6 +1673,54 @@ calculate_packet_spacing (GstRtpJitterBuffer * jitterbuffer, guint32 rtptime,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GstFlowReturn
|
||||||
|
send_lost_event (GstRtpJitterBuffer * jitterbuffer, guint seqnum,
|
||||||
|
guint lost_packets, GstClockTime timestamp, GstClockTime duration,
|
||||||
|
gboolean late)
|
||||||
|
{
|
||||||
|
GstRtpJitterBufferPrivate *priv = jitterbuffer->priv;
|
||||||
|
|
||||||
|
/* we had a gap and thus we lost some packets. Create an event for this. */
|
||||||
|
if (lost_packets > 1)
|
||||||
|
GST_DEBUG_OBJECT (jitterbuffer, "Packets #%d -> #%d lost", seqnum,
|
||||||
|
seqnum + lost_packets - 1);
|
||||||
|
else
|
||||||
|
GST_DEBUG_OBJECT (jitterbuffer, "Packet #%d lost", seqnum);
|
||||||
|
|
||||||
|
priv->num_late += lost_packets;
|
||||||
|
priv->discont = TRUE;
|
||||||
|
|
||||||
|
/* update our expected next packet but make sure the seqnum increases */
|
||||||
|
if (seqnum + lost_packets > priv->next_seqnum) {
|
||||||
|
priv->next_seqnum = (seqnum + lost_packets) & 0xffff;
|
||||||
|
priv->last_popped_seqnum = seqnum;
|
||||||
|
priv->last_out_time = timestamp;
|
||||||
|
}
|
||||||
|
if (priv->do_lost) {
|
||||||
|
GstEvent *event;
|
||||||
|
|
||||||
|
/* create paket lost event */
|
||||||
|
event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM,
|
||||||
|
gst_structure_new ("GstRTPPacketLost",
|
||||||
|
"seqnum", G_TYPE_UINT, (guint) seqnum,
|
||||||
|
"timestamp", G_TYPE_UINT64, timestamp,
|
||||||
|
"duration", G_TYPE_UINT64, duration,
|
||||||
|
"late", G_TYPE_BOOLEAN, late, NULL));
|
||||||
|
JBUF_UNLOCK (priv);
|
||||||
|
gst_pad_push_event (priv->srcpad, event);
|
||||||
|
JBUF_LOCK_CHECK (priv, flushing);
|
||||||
|
}
|
||||||
|
return GST_FLOW_OK;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
flushing:
|
||||||
|
{
|
||||||
|
GST_DEBUG_OBJECT (jitterbuffer, "we are flushing");
|
||||||
|
return GST_FLOW_FLUSHING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
calculate_expected (GstRtpJitterBuffer * jitterbuffer, guint32 expected,
|
calculate_expected (GstRtpJitterBuffer * jitterbuffer, guint32 expected,
|
||||||
guint16 seqnum, GstClockTime dts, gint gap)
|
guint16 seqnum, GstClockTime dts, gint gap)
|
||||||
|
@ -2264,70 +2312,19 @@ do_lost_timeout (GstRtpJitterBuffer * jitterbuffer, TimerData * timer,
|
||||||
GstClockTime now)
|
GstClockTime now)
|
||||||
{
|
{
|
||||||
GstRtpJitterBufferPrivate *priv = jitterbuffer->priv;
|
GstRtpJitterBufferPrivate *priv = jitterbuffer->priv;
|
||||||
GstClockTime duration = GST_CLOCK_TIME_NONE;
|
GstClockTime duration, timestamp;
|
||||||
guint32 lost_packets = 1;
|
guint seqnum;
|
||||||
gboolean lost_packets_late = FALSE;
|
|
||||||
|
|
||||||
#if 0
|
seqnum = timer->seqnum;
|
||||||
if (clock_jitter > 0
|
timestamp = apply_offset (jitterbuffer, timer->timeout);
|
||||||
&& clock_jitter > (priv->latency_ns + priv->peer_latency)) {
|
duration = GST_CLOCK_TIME_NONE;
|
||||||
GstClockTimeDiff total_duration;
|
|
||||||
GstClockTime out_time_diff;
|
|
||||||
|
|
||||||
out_time_diff =
|
|
||||||
apply_offset (jitterbuffer, timer->timeout) - timer->timeout;
|
|
||||||
total_duration = MIN (out_time_diff, clock_jitter);
|
|
||||||
|
|
||||||
if (duration > 0)
|
|
||||||
lost_packets = total_duration / duration;
|
|
||||||
else
|
|
||||||
lost_packets = gap;
|
|
||||||
total_duration = lost_packets * duration;
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (jitterbuffer,
|
|
||||||
"Current sync_time has expired a long time ago (+%" GST_TIME_FORMAT
|
|
||||||
") Cover up %d lost packets with duration %" GST_TIME_FORMAT,
|
|
||||||
GST_TIME_ARGS (clock_jitter),
|
|
||||||
lost_packets, GST_TIME_ARGS (total_duration));
|
|
||||||
|
|
||||||
duration = total_duration;
|
|
||||||
lost_packets_late = TRUE;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* we had a gap and thus we lost some packets. Create an event for this. */
|
|
||||||
if (lost_packets > 1)
|
|
||||||
GST_DEBUG_OBJECT (jitterbuffer, "Packets #%d -> #%d lost", timer->seqnum,
|
|
||||||
timer->seqnum + lost_packets - 1);
|
|
||||||
else
|
|
||||||
GST_DEBUG_OBJECT (jitterbuffer, "Packet #%d lost", timer->seqnum);
|
|
||||||
|
|
||||||
priv->num_late += lost_packets;
|
|
||||||
priv->discont = TRUE;
|
|
||||||
|
|
||||||
/* update our expected next packet */
|
|
||||||
priv->last_popped_seqnum = timer->seqnum;
|
|
||||||
priv->last_out_time = apply_offset (jitterbuffer, timer->timeout);
|
|
||||||
if (timer->seqnum + lost_packets > priv->next_seqnum)
|
|
||||||
priv->next_seqnum = (timer->seqnum + lost_packets) & 0xffff;
|
|
||||||
/* remove timer now */
|
/* remove timer now */
|
||||||
remove_timer (jitterbuffer, timer);
|
remove_timer (jitterbuffer, timer);
|
||||||
JBUF_SIGNAL_EVENT (priv);
|
JBUF_SIGNAL_EVENT (priv);
|
||||||
|
|
||||||
if (priv->do_lost) {
|
send_lost_event (jitterbuffer, seqnum, 1, timestamp, duration, FALSE);
|
||||||
GstEvent *event;
|
|
||||||
|
|
||||||
/* create paket lost event */
|
|
||||||
event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM,
|
|
||||||
gst_structure_new ("GstRTPPacketLost",
|
|
||||||
"seqnum", G_TYPE_UINT, (guint) priv->last_popped_seqnum,
|
|
||||||
"timestamp", G_TYPE_UINT64, priv->last_out_time,
|
|
||||||
"duration", G_TYPE_UINT64, duration,
|
|
||||||
"late", G_TYPE_BOOLEAN, lost_packets_late, NULL));
|
|
||||||
JBUF_UNLOCK (priv);
|
|
||||||
gst_pad_push_event (priv->srcpad, event);
|
|
||||||
JBUF_LOCK (priv);
|
|
||||||
}
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue