From 12a6b9613bd081f16719734a1706c8f2b9d6b36f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Thu, 1 Sep 2011 16:25:21 -0400 Subject: [PATCH] rtpsession: Put the PLI requests in each RTPSource Also refactor a bit and put all the keyframe request code in one place inside rtpsession.c https://bugzilla.gnome.org/show_bug.cgi?id=658419 --- gst/rtpmanager/gstrtpsession.c | 12 ++++------ gst/rtpmanager/rtpsession.c | 40 ++++++++++++++++++---------------- gst/rtpmanager/rtpsession.h | 6 ++--- gst/rtpmanager/rtpsource.h | 2 ++ 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/gst/rtpmanager/gstrtpsession.c b/gst/rtpmanager/gstrtpsession.c index 030a9e4bc1..fd5944aeb7 100644 --- a/gst/rtpmanager/gstrtpsession.c +++ b/gst/rtpmanager/gstrtpsession.c @@ -1389,7 +1389,6 @@ gst_rtp_session_request_remote_key_unit (GstRtpSession * rtpsession, guint32 ssrc, guint payload, gboolean all_headers) { GstCaps *caps; - gboolean requested = FALSE; caps = gst_rtp_session_get_caps_for_pt (rtpsession, payload); @@ -1401,15 +1400,12 @@ gst_rtp_session_request_remote_key_unit (GstRtpSession * rtpsession, gst_caps_unref (caps); - if (pli) { - rtp_session_request_key_unit (rtpsession->priv->session, ssrc); - rtp_session_request_early_rtcp (rtpsession->priv->session, - gst_clock_get_time (rtpsession->priv->sysclock), 200 * GST_MSECOND); - requested = TRUE; - } + if (pli) + return rtp_session_request_key_unit (rtpsession->priv->session, ssrc, + gst_clock_get_time (rtpsession->priv->sysclock)); } - return requested; + return FALSE; } static gboolean diff --git a/gst/rtpmanager/rtpsession.c b/gst/rtpmanager/rtpsession.c index 9a7d2da6b5..17b1b02741 100644 --- a/gst/rtpmanager/rtpsession.c +++ b/gst/rtpmanager/rtpsession.c @@ -568,7 +568,6 @@ rtp_session_init (RTPSession * sess) sess->rtcp_immediate_feedback_threshold = DEFAULT_RTCP_IMMEDIATE_FEEDBACK_THRESHOLD; - sess->rtcp_pli_requests = g_array_new (FALSE, FALSE, sizeof (guint32)); sess->last_keyframe_request = GST_CLOCK_TIME_NONE; GST_DEBUG ("%p: session using SSRC: %08x", sess, sess->source->ssrc); @@ -591,8 +590,6 @@ rtp_session_finalize (GObject * object) g_hash_table_destroy (sess->cnames); g_object_unref (sess->source); - g_array_free (sess->rtcp_pli_requests, TRUE); - G_OBJECT_CLASS (rtp_session_parent_class)->finalize (object); } @@ -3301,19 +3298,22 @@ rtp_session_request_early_rtcp (RTPSession * sess, GstClockTime current_time, dont_send: RTP_SESSION_UNLOCK (sess); - } -void -rtp_session_request_key_unit (RTPSession * sess, guint32 ssrc) +gboolean +rtp_session_request_key_unit (RTPSession * sess, guint32 ssrc, GstClockTime now) { - guint i; + RTPSource *src = g_hash_table_lookup (sess->ssrcs[sess->mask_idx], + GUINT_TO_POINTER (ssrc)); - for (i = 0; i < sess->rtcp_pli_requests->len; i++) - if (ssrc == g_array_index (sess->rtcp_pli_requests, guint32, i)) - return; + if (!src) + return FALSE; - g_array_append_val (sess->rtcp_pli_requests, ssrc); + src->send_pli = TRUE; + + rtp_session_request_early_rtcp (sess, now, 200 * GST_MSECOND); + + return TRUE; } static gboolean @@ -3336,16 +3336,19 @@ rtp_session_on_sending_rtcp (RTPSession * sess, GstBuffer * buffer, gboolean early) { gboolean ret = FALSE; + GHashTableIter iter; + gpointer key, value; RTP_SESSION_LOCK (sess); - while (sess->rtcp_pli_requests->len) { - GstRTCPPacket rtcppacket; - guint media_ssrc = g_array_index (sess->rtcp_pli_requests, guint32, 0); - RTPSource *media_src = g_hash_table_lookup (sess->ssrcs[sess->mask_idx], - GUINT_TO_POINTER (media_ssrc)); + g_hash_table_iter_init (&iter, sess->ssrcs[sess->mask_idx]); - if (media_src && !rtp_source_has_retained (media_src, + while (g_hash_table_iter_next (&iter, &key, &value)) { + guint media_ssrc = GPOINTER_TO_UINT (key); + RTPSource *media_src = value; + GstRTCPPacket rtcppacket; + + if (media_src->send_pli && !rtp_source_has_retained (media_src, has_pli_compare_func, NULL)) { if (gst_rtcp_buffer_add_packet (buffer, GST_RTCP_TYPE_PSFB, &rtcppacket)) { gst_rtcp_packet_fb_set_type (&rtcppacket, GST_RTCP_PSFB_TYPE_PLI); @@ -3360,8 +3363,7 @@ rtp_session_on_sending_rtcp (RTPSession * sess, GstBuffer * buffer, break; } } - - g_array_remove_index (sess->rtcp_pli_requests, 0); + media_src->send_pli = FALSE; } RTP_SESSION_UNLOCK (sess); diff --git a/gst/rtpmanager/rtpsession.h b/gst/rtpmanager/rtpsession.h index 617737554c..741d54beb4 100644 --- a/gst/rtpmanager/rtpsession.h +++ b/gst/rtpmanager/rtpsession.h @@ -235,7 +235,6 @@ struct _RTPSession { GstClockTime rtcp_feedback_retention_window; guint rtcp_immediate_feedback_threshold; - GArray *rtcp_pli_requests; GstClockTime last_keyframe_request; gboolean last_keyframe_all_headers; }; @@ -350,7 +349,8 @@ void rtp_session_request_early_rtcp (RTPSession * sess, GstClockT GstClockTimeDiff max_delay); /* Notify session of a request for a new key unit */ -void rtp_session_request_key_unit (RTPSession * sess, - guint32 ssrc); +gboolean rtp_session_request_key_unit (RTPSession * sess, + guint32 ssrc, + GstClockTime now); #endif /* __RTP_SESSION_H__ */ diff --git a/gst/rtpmanager/rtpsource.h b/gst/rtpmanager/rtpsource.h index 6db0a6a678..861ffdeccf 100644 --- a/gst/rtpmanager/rtpsource.h +++ b/gst/rtpmanager/rtpsource.h @@ -172,6 +172,8 @@ struct _RTPSource { GList *conflicting_addresses; GQueue *retained_feedback; + + gboolean send_pli; }; struct _RTPSourceClass {