From 8fc8b7ee3376485d924572e850c556b0d58ddeac Mon Sep 17 00:00:00 2001 From: Linus Svensson Date: Tue, 16 Oct 2018 12:38:46 +0200 Subject: [PATCH] rtpsession: Implement reset Reset RTPSession when rtpsession changes state from PAUSED to READY. Without this change, a stored last_rtptime in RTPSource could interfere with RTP timestamp generation in RTCP Sender Report. Fixes #510 --- gst/rtpmanager/gstrtpsession.c | 1 + gst/rtpmanager/rtpsession.c | 41 ++++++++++++++++++++++++++++++++++ gst/rtpmanager/rtpsession.h | 1 + gst/rtpmanager/rtpsource.c | 4 +++- 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/gst/rtpmanager/gstrtpsession.c b/gst/rtpmanager/gstrtpsession.c index 6c1bba07ad..a90a172d05 100644 --- a/gst/rtpmanager/gstrtpsession.c +++ b/gst/rtpmanager/gstrtpsession.c @@ -1270,6 +1270,7 @@ gst_rtp_session_change_state (GstElement * element, GstStateChange transition) case GST_STATE_CHANGE_PAUSED_TO_READY: /* downstream is now releasing the dataflow and we can join. */ join_rtcp_thread (rtpsession); + rtp_session_reset (rtpsession->priv->session); break; case GST_STATE_CHANGE_READY_TO_NULL: break; diff --git a/gst/rtpmanager/rtpsession.c b/gst/rtpmanager/rtpsession.c index bc2e52762b..2afc0cf379 100644 --- a/gst/rtpmanager/rtpsession.c +++ b/gst/rtpmanager/rtpsession.c @@ -1060,6 +1060,47 @@ rtp_session_new (void) return sess; } +/** + * rtp_session_reset: + * @sess: an #RTPSession + * + * Reset the sources of @sess. + */ +void +rtp_session_reset (RTPSession * sess) +{ + g_return_if_fail (RTP_IS_SESSION (sess)); + + /* remove all sources */ + g_hash_table_remove_all (sess->ssrcs[sess->mask_idx]); + sess->total_sources = 0; + sess->stats.sender_sources = 0; + sess->stats.internal_sender_sources = 0; + sess->stats.internal_sources = 0; + sess->stats.active_sources = 0; + + sess->generation = 0; + sess->first_rtcp = TRUE; + sess->next_rtcp_check_time = GST_CLOCK_TIME_NONE; + sess->last_rtcp_check_time = GST_CLOCK_TIME_NONE; + sess->last_rtcp_send_time = GST_CLOCK_TIME_NONE; + sess->last_rtcp_interval = GST_CLOCK_TIME_NONE; + sess->next_early_rtcp_time = GST_CLOCK_TIME_NONE; + sess->scheduled_bye = FALSE; + + /* reset session stats */ + sess->stats.bye_members = 0; + sess->stats.nacks_dropped = 0; + sess->stats.nacks_sent = 0; + sess->stats.nacks_received = 0; + + sess->is_doing_ptp = TRUE; + + g_list_free_full (sess->conflicting_addresses, + (GDestroyNotify) rtp_conflicting_address_free); + sess->conflicting_addresses = NULL; +} + /** * rtp_session_set_callbacks: * @sess: an #RTPSession diff --git a/gst/rtpmanager/rtpsession.h b/gst/rtpmanager/rtpsession.h index e849d81f85..e8cc12c8d5 100644 --- a/gst/rtpmanager/rtpsession.h +++ b/gst/rtpmanager/rtpsession.h @@ -334,6 +334,7 @@ GType rtp_session_get_type (void); /* create and configure */ RTPSession* rtp_session_new (void); +void rtp_session_reset (RTPSession *sess); void rtp_session_set_callbacks (RTPSession *sess, RTPSessionCallbacks *callbacks, gpointer user_data); diff --git a/gst/rtpmanager/rtpsource.c b/gst/rtpmanager/rtpsource.c index d726408c69..740f15f931 100644 --- a/gst/rtpmanager/rtpsource.c +++ b/gst/rtpmanager/rtpsource.c @@ -255,6 +255,9 @@ rtp_source_reset (RTPSource * src) src->bye_reason = NULL; src->sent_bye = FALSE; g_hash_table_remove_all (src->reported_in_sr_of); + g_queue_foreach (src->retained_feedback, (GFunc) gst_buffer_unref, NULL); + g_queue_clear (src->retained_feedback); + src->last_rtptime = -1; src->stats.cycles = -1; src->stats.jitter = 0; @@ -294,7 +297,6 @@ rtp_source_init (RTPSource * src) src->clock_rate = -1; src->packets = g_queue_new (); src->seqnum_offset = -1; - src->last_rtptime = -1; src->retained_feedback = g_queue_new (); src->nacks = g_array_new (FALSE, FALSE, sizeof (guint32));