rtpsession: Send GstForceKeyUnit event in response to received RTCP PLI
authorOlivier CrĂȘte <olivier.crete@collabora.co.uk>
Wed, 23 Jun 2010 20:43:24 +0000 (16:43 -0400)
committerWim Taymans <wim.taymans@collabora.co.uk>
Tue, 1 Feb 2011 17:28:51 +0000 (18:28 +0100)
gst/rtpmanager/gstrtpsession.c
gst/rtpmanager/rtpsession.c
gst/rtpmanager/rtpsession.h

index cc784c8..994c53b 100644 (file)
@@ -257,6 +257,8 @@ static GstFlowReturn gst_rtp_session_sync_rtcp (RTPSession * sess,
 static gint gst_rtp_session_clock_rate (RTPSession * sess, guint8 payload,
     gpointer user_data);
 static void gst_rtp_session_reconsider (RTPSession * sess, gpointer user_data);
+static void gst_rtp_session_request_key_unit (RTPSession * sess,
+    gboolean all_headers, gpointer user_data);
 
 static RTPSessionCallbacks callbacks = {
   gst_rtp_session_process_rtp,
@@ -264,7 +266,8 @@ static RTPSessionCallbacks callbacks = {
   gst_rtp_session_sync_rtcp,
   gst_rtp_session_send_rtcp,
   gst_rtp_session_clock_rate,
-  gst_rtp_session_reconsider
+  gst_rtp_session_reconsider,
+  gst_rtp_session_request_key_unit
 };
 
 /* GObject vmethods */
@@ -2143,3 +2146,16 @@ wrong_pad:
     return;
   }
 }
+
+static void
+gst_rtp_session_request_key_unit (RTPSession * sess,
+    gboolean all_headers, gpointer user_data)
+{
+  GstRtpSession *rtpsession = GST_RTP_SESSION (user_data);
+  GstEvent *event;
+
+  event = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM,
+      gst_structure_new ("GstForceKeyUnit",
+          "all-headers", G_TYPE_BOOLEAN, all_headers, NULL));
+  gst_pad_push_event (rtpsession->send_rtp_sink, event);
+}
index 32973c0..d3a7a54 100644 (file)
@@ -769,6 +769,10 @@ rtp_session_set_callbacks (RTPSession * sess, RTPSessionCallbacks * callbacks,
     sess->callbacks.reconsider = callbacks->reconsider;
     sess->reconsider_user_data = user_data;
   }
+  if (callbacks->request_key_unit) {
+    sess->callbacks.request_key_unit = callbacks->request_key_unit;
+    sess->request_key_unit_user_data = user_data;
+  }
 }
 
 /**
@@ -2042,6 +2046,25 @@ rtp_session_process_feedback (RTPSession * sess, GstRTCPPacket * packet,
     if (src)
       rtp_source_retain_rtcp_packet (src, packet, arrival->running_time);
   }
+
+  if (rtp_source_get_ssrc (sess->source) == media_ssrc) {
+    switch (type) {
+      case GST_RTCP_TYPE_PSFB:
+        switch (fbtype) {
+          case GST_RTCP_PSFB_TYPE_PLI:
+            if (sess->callbacks.request_key_unit)
+              sess->callbacks.request_key_unit (sess, FALSE,
+                  sess->request_key_unit_user_data);
+            break;
+          default:
+            break;
+        }
+        break;
+      case GST_RTCP_TYPE_RTPFB:
+      default:
+        break;
+    }
+  }
 }
 
 /**
index 3113247..0cc1f6b 100644 (file)
@@ -121,12 +121,26 @@ typedef gint (*RTPSessionClockRate) (RTPSession *sess, guint8 payload, gpointer
 typedef void (*RTPSessionReconsider) (RTPSession *sess, gpointer user_data);
 
 /**
+ * RTPSessionRequestKeyUnit:
+ * @sess: an #RTPSession
+ * @all_headers: %TRUE if "all-headers" property should be set on the key unit
+ *  request
+ * @user_data: user data specified when registering
+*
+ * Asks the encoder to produce a key unit as soon as possibly within the
+ * bandwidth constraints
+ */
+typedef void (*RTPSessionRequestKeyUnit) (RTPSession *sess,
+    gboolean all_headers, gpointer user_data);
+
+/**
  * RTPSessionCallbacks:
  * @RTPSessionProcessRTP: callback to process RTP packets
  * @RTPSessionSendRTP: callback for sending RTP packets
  * @RTPSessionSendRTCP: callback for sending RTCP packets
  * @RTPSessionSyncRTCP: callback for handling SR packets
  * @RTPSessionReconsider: callback for reconsidering the timeout
+ * @RTPSessionRequestKeyUnit: callback for requesting a new key unit
  *
  * These callbacks can be installed on the session manager to get notification
  * when RTP and RTCP packets are ready for further processing. These callbacks
@@ -139,6 +153,7 @@ typedef struct {
   RTPSessionSendRTCP    send_rtcp;
   RTPSessionClockRate   clock_rate;
   RTPSessionReconsider  reconsider;
+  RTPSessionRequestKeyUnit request_key_unit;
 } RTPSessionCallbacks;
 
 /**
@@ -197,6 +212,7 @@ struct _RTPSession {
   gpointer              sync_rtcp_user_data;
   gpointer              clock_rate_user_data;
   gpointer              reconsider_user_data;
+  gpointer              request_key_unit_user_data;
 
   RTPSessionStats stats;