From 458741e4b28f0dfadba51d2aa56f299bf305f5a6 Mon Sep 17 00:00:00 2001 From: Miguel Paris Date: Thu, 29 Nov 2018 13:02:53 +0100 Subject: [PATCH] rtpsource: properly prune RTCP packets out of feedback_retention_window Closes #522 --- gst/rtpmanager/rtpsession.c | 4 ++-- gst/rtpmanager/rtpsource.c | 27 +++++++++++++++++++++++---- gst/rtpmanager/rtpsource.h | 1 + 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/gst/rtpmanager/rtpsession.c b/gst/rtpmanager/rtpsession.c index aa5e3ef923..98dd887927 100644 --- a/gst/rtpmanager/rtpsession.c +++ b/gst/rtpmanager/rtpsession.c @@ -3644,8 +3644,8 @@ session_cleanup (const gchar * key, RTPSource * source, ReportData * data) /* check for outdated collisions */ if (source->internal) { GST_DEBUG ("Timing out collisions for %x", source->ssrc); - rtp_source_timeout (source, data->current_time, - data->running_time - sess->rtcp_feedback_retention_window); + rtp_source_timeout (source, data->current_time, data->running_time, + sess->rtcp_feedback_retention_window); } /* nothing else to do when without RTCP */ diff --git a/gst/rtpmanager/rtpsource.c b/gst/rtpmanager/rtpsource.c index 30c346669c..4aee4c3dc3 100644 --- a/gst/rtpmanager/rtpsource.c +++ b/gst/rtpmanager/rtpsource.c @@ -1831,17 +1831,33 @@ rtp_source_add_conflicting_address (RTPSource * src, */ void rtp_source_timeout (RTPSource * src, GstClockTime current_time, - GstClockTime feedback_retention_window) + GstClockTime running_time, GstClockTime feedback_retention_window) { GstRTCPPacket *pkt; + GstClockTime max_pts_window; + guint pruned = 0; src->conflicting_addresses = timeout_conflicting_addresses (src->conflicting_addresses, current_time); + if (feedback_retention_window == GST_CLOCK_TIME_NONE || + running_time < feedback_retention_window) { + return; + } + + max_pts_window = running_time - feedback_retention_window; + /* Time out AVPF packets that are older than the desired length */ - while ((pkt = g_queue_peek_tail (src->retained_feedback)) && - GST_BUFFER_PTS (pkt) < feedback_retention_window) - gst_buffer_unref (g_queue_pop_tail (src->retained_feedback)); + while ((pkt = g_queue_peek_head (src->retained_feedback)) && + GST_BUFFER_PTS (pkt) < max_pts_window) { + gst_buffer_unref (g_queue_pop_head (src->retained_feedback)); + pruned++; + } + + GST_LOG_OBJECT (src, + "%u RTCP packets pruned with PTS less than %" GST_TIME_FORMAT + ", queue len: %u", pruned, GST_TIME_ARGS (max_pts_window), + g_queue_get_length (src->retained_feedback)); } static gint @@ -1876,6 +1892,9 @@ rtp_source_retain_rtcp_packet (RTPSource * src, GstRTCPPacket * packet, GST_BUFFER_PTS (buffer) = running_time; g_queue_insert_sorted (src->retained_feedback, buffer, compare_buffers, NULL); + + GST_LOG_OBJECT (src, "RTCP packet retained with PTS: %" GST_TIME_FORMAT, + GST_TIME_ARGS (running_time)); } gboolean diff --git a/gst/rtpmanager/rtpsource.h b/gst/rtpmanager/rtpsource.h index 282267eda6..4a44adb0da 100644 --- a/gst/rtpmanager/rtpsource.h +++ b/gst/rtpmanager/rtpsource.h @@ -288,6 +288,7 @@ void rtp_conflicting_address_free (RTPConflictingAddress * addr); void rtp_source_timeout (RTPSource * src, GstClockTime current_time, + GstClockTime running_time, GstClockTime feedback_retention_window); void rtp_source_retain_rtcp_packet (RTPSource * src,