rtsp-stream: add getter for payload type
authorAleix Conchillo Flaque <aleix@oblong.com>
Fri, 15 Nov 2013 20:14:32 +0000 (12:14 -0800)
committerWim Taymans <wtaymans@redhat.com>
Fri, 22 Nov 2013 10:19:35 +0000 (11:19 +0100)
* gst/rtsp-server/rtsp-stream.c: add new method gst_rtsp_stream_get_pt.

* gst/rtsp-server/rtsp-media.c (pad_added_cb): find real payloader
  element and create the stream with this one instead of the dynpay%d
  element.

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

gst/rtsp-server/rtsp-media.c
gst/rtsp-server/rtsp-stream.c
gst/rtsp-server/rtsp-stream.h

index cfa3a25..09628d3 100644 (file)
@@ -67,6 +67,8 @@
 #include <gst/app/gstappsrc.h>
 #include <gst/app/gstappsink.h>
 
+#include <gst/rtp/gstrtpbasepayload.h>
+
 #include "rtsp-media.h"
 
 #define GST_RTSP_MEDIA_GET_PRIVATE(obj)  \
@@ -1529,15 +1531,41 @@ watch_destroyed (GstRTSPMedia * media)
   g_object_unref (media);
 }
 
+static GstElement *
+find_payload_element (GstElement * payloader)
+{
+  GValue item = { 0 };
+  GstIterator *iter;
+  GstElement *element;
+  GstElement *pay = NULL;
+
+  iter = gst_bin_iterate_recurse (GST_BIN (payloader));
+  while (gst_iterator_next (iter, &item) == GST_ITERATOR_OK) {
+    element = (GstElement *) g_value_get_object (&item);
+    if (GST_IS_RTP_BASE_PAYLOAD (element)) {
+      pay = gst_object_ref (element);
+      g_value_unset (&item);
+      break;
+    }
+    g_value_unset (&item);
+  }
+  gst_iterator_free (iter);
+
+  return pay;
+}
+
 /* called from streaming threads */
 static void
 pad_added_cb (GstElement * element, GstPad * pad, GstRTSPMedia * media)
 {
   GstRTSPMediaPrivate *priv = media->priv;
   GstRTSPStream *stream;
+  GstElement *pay;
 
-  /* FIXME, element is likely not a payloader, find the payloader here */
-  stream = gst_rtsp_media_create_stream (media, element, pad);
+  /* find the real payload element */
+  pay = find_payload_element (element);
+  stream = gst_rtsp_media_create_stream (media, pay, pad);
+  gst_object_unref (pay);
 
   g_object_set_data (G_OBJECT (pad), "gst-rtsp-dynpad-stream", stream);
 
index 79471e8..046ca5c 100644 (file)
@@ -307,6 +307,29 @@ gst_rtsp_stream_get_index (GstRTSPStream * stream)
 }
 
 /**
+ * gst_rtsp_stream_get_pt:
+ * @stream: a #GstRTSPStream
+ *
+ * Get the stream payload type.
+ *
+ * Return: the stream payload type.
+ */
+guint
+gst_rtsp_stream_get_pt (GstRTSPStream * stream)
+{
+  GstRTSPStreamPrivate *priv;
+  guint pt;
+
+  g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), -1);
+
+  priv = stream->priv;
+
+  g_object_get (G_OBJECT (priv->payloader), "pt", &pt, NULL);
+
+  return pt;
+}
+
+/**
  * gst_rtsp_stream_get_srcpad:
  * @stream: a #GstRTSPStream
  *
index 7bd4681..2aefdcf 100644 (file)
@@ -66,6 +66,7 @@ GType             gst_rtsp_stream_get_type         (void);
 GstRTSPStream *   gst_rtsp_stream_new              (guint idx, GstElement *payloader,
                                                     GstPad *srcpad);
 guint             gst_rtsp_stream_get_index        (GstRTSPStream *stream);
+guint             gst_rtsp_stream_get_pt           (GstRTSPStream *stream);
 GstPad *          gst_rtsp_stream_get_srcpad       (GstRTSPStream *stream);
 
 void              gst_rtsp_stream_set_control      (GstRTSPStream *stream, const gchar *control);