stream: add signals for new RTP/RTCP encoders
authorAleix Conchillo FlaquƩ <aleix@oblong.com>
Fri, 16 May 2014 01:15:04 +0000 (18:15 -0700)
committerWim Taymans <wtaymans@redhat.com>
Fri, 16 May 2014 14:27:52 +0000 (16:27 +0200)
New signals to allow the user to configure the dynamically created
encoders.

https://bugzilla.gnome.org/show_bug.cgi?id=730228

gst/rtsp-server/rtsp-stream.c

index 85b4ee0..7317553 100644 (file)
@@ -148,6 +148,13 @@ enum
   PROP_LAST
 };
 
+enum
+{
+  SIGNAL_NEW_RTP_ENCODER,
+  SIGNAL_NEW_RTCP_ENCODER,
+  SIGNAL_LAST
+};
+
 GST_DEBUG_CATEGORY_STATIC (rtsp_stream_debug);
 #define GST_CAT_DEFAULT rtsp_stream_debug
 
@@ -160,6 +167,8 @@ static void gst_rtsp_stream_set_property (GObject * object, guint propid,
 
 static void gst_rtsp_stream_finalize (GObject * obj);
 
+static guint gst_rtsp_stream_signals[SIGNAL_LAST] = { 0 };
+
 G_DEFINE_TYPE (GstRTSPStream, gst_rtsp_stream, G_TYPE_OBJECT);
 
 static void
@@ -190,6 +199,16 @@ gst_rtsp_stream_class_init (GstRTSPStreamClass * klass)
           "Allowed lower transport protocols", GST_TYPE_RTSP_LOWER_TRANS,
           DEFAULT_PROTOCOLS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  gst_rtsp_stream_signals[SIGNAL_NEW_RTP_ENCODER] =
+      g_signal_new ("new-rtp-encoder", G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
+      G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
+
+  gst_rtsp_stream_signals[SIGNAL_NEW_RTCP_ENCODER] =
+      g_signal_new ("new-rtcp-encoder", G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
+      G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
+
   GST_DEBUG_CATEGORY_INIT (rtsp_stream_debug, "rtspstream", 0, "GstRTSPStream");
 
   ssrc_stream_map_key = g_quark_from_static_string ("GstRTSPServer.stream");
@@ -1534,7 +1553,7 @@ static GstElement *
 request_rtp_encoder (GstElement * rtpbin, guint session, GstRTSPStream * stream)
 {
   GstRTSPStreamPrivate *priv = stream->priv;
-  GstElement *enc;
+  GstElement *oldenc, *enc;
   GstPad *pad;
   gchar *name;
 
@@ -1543,12 +1562,17 @@ request_rtp_encoder (GstElement * rtpbin, guint session, GstRTSPStream * stream)
 
   GST_DEBUG_OBJECT (stream, "make RTP encoder for session %u", session);
 
+  oldenc = priv->srtpenc;
   enc = get_rtp_encoder (stream, session);
   name = g_strdup_printf ("rtp_sink_%d", session);
   pad = gst_element_get_request_pad (enc, name);
   g_free (name);
   gst_object_unref (pad);
 
+  if (oldenc == NULL)
+    g_signal_emit (stream, gst_rtsp_stream_signals[SIGNAL_NEW_RTP_ENCODER], 0,
+        enc);
+
   return enc;
 }
 
@@ -1557,7 +1581,7 @@ request_rtcp_encoder (GstElement * rtpbin, guint session,
     GstRTSPStream * stream)
 {
   GstRTSPStreamPrivate *priv = stream->priv;
-  GstElement *enc;
+  GstElement *oldenc, *enc;
   GstPad *pad;
   gchar *name;
 
@@ -1566,12 +1590,17 @@ request_rtcp_encoder (GstElement * rtpbin, guint session,
 
   GST_DEBUG_OBJECT (stream, "make RTCP encoder for session %u", session);
 
+  oldenc = priv->srtpenc;
   enc = get_rtp_encoder (stream, session);
   name = g_strdup_printf ("rtcp_sink_%d", session);
   pad = gst_element_get_request_pad (enc, name);
   g_free (name);
   gst_object_unref (pad);
 
+  if (oldenc == NULL)
+    g_signal_emit (stream, gst_rtsp_stream_signals[SIGNAL_NEW_RTCP_ENCODER], 0,
+        enc);
+
   return enc;
 }