From 03b62267727c99210add9c816b3e0ee15cbf5be1 Mon Sep 17 00:00:00 2001 From: Ognyan Tonchev Date: Fri, 25 Oct 2024 12:02:54 +0200 Subject: [PATCH] rtpmanager: skip RTPSources which are not ready in the RTCP generation If a stream has an 'irregular' frame rate (e.g. metadata) RTCP SR may be generated way too early, before the RTPSource has received the first packet after Latency was configured in the pipeline. We skip such RTPSources in the RTCP generation. Part-of: --- .../gst-plugins-good/gst/rtpmanager/rtpsession.c | 16 ++++++++++++---- .../gst-plugins-good/gst/rtpmanager/rtpsource.c | 7 +++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/subprojects/gst-plugins-good/gst/rtpmanager/rtpsession.c b/subprojects/gst-plugins-good/gst/rtpmanager/rtpsession.c index c7cad94569..73431aec18 100644 --- a/subprojects/gst-plugins-good/gst/rtpmanager/rtpsession.c +++ b/subprojects/gst-plugins-good/gst/rtpmanager/rtpsession.c @@ -3823,7 +3823,7 @@ typedef struct gboolean timeout_inactive_sources; } ReportData; -static void +static gboolean session_start_rtcp (RTPSession * sess, ReportData * data) { GstRTCPPacket *packet = &data->packet; @@ -3848,8 +3848,11 @@ session_start_rtcp (RTPSession * sess, ReportData * data) gst_rtcp_buffer_add_packet (rtcp, GST_RTCP_TYPE_SR, packet); /* get latest stats */ - rtp_source_get_new_sr (own, data->ntpnstime, data->running_time, - &ntptime, &rtptime, &packet_count, &octet_count); + if (!rtp_source_get_new_sr (own, data->ntpnstime, data->running_time, + &ntptime, &rtptime, &packet_count, &octet_count)) { + gst_rtcp_buffer_unmap (&data->rtcpbuf); + return FALSE; + } /* store stats */ rtp_source_process_sr (own, data->current_time, ntptime, rtptime, packet_count, octet_count); @@ -3865,6 +3868,8 @@ session_start_rtcp (RTPSession * sess, ReportData * data) gst_rtcp_buffer_add_packet (rtcp, GST_RTCP_TYPE_RR, packet); gst_rtcp_packet_rr_set_ssrc (packet, own->ssrc); } + + return TRUE; } /* construct a Sender or Receiver Report */ @@ -4545,7 +4550,10 @@ generate_rtcp (const gchar * key, RTPSource * source, ReportData * data) data->source = source; /* open packet */ - session_start_rtcp (sess, data); + if (!session_start_rtcp (sess, data)) { + GST_WARNING ("source %08x can not generate RTCP", source->ssrc); + return; + } if (source->marked_bye) { /* send BYE */ diff --git a/subprojects/gst-plugins-good/gst/rtpmanager/rtpsource.c b/subprojects/gst-plugins-good/gst/rtpmanager/rtpsource.c index a188d9f87a..5398e1440b 100644 --- a/subprojects/gst-plugins-good/gst/rtpmanager/rtpsource.c +++ b/subprojects/gst-plugins-good/gst/rtpmanager/rtpsource.c @@ -1708,6 +1708,13 @@ rtp_source_get_new_sr (RTPSource * src, guint64 ntpnstime, } if (src->clock_rate != -1) { + /* if no running time has been set yet we wait until we get one */ + if (src->last_rtime == -1) { + GST_WARNING ("running time not set, can not create SR for SSRC %u", + src->ssrc); + return FALSE; + } + /* get the diff between the clock running_time and the buffer running_time. * This is the elapsed time, as measured against the pipeline clock, between * when the rtp timestamp was observed and the current running_time.