stream: add method to filter transports
authorWim Taymans <wim.taymans@gmail.com>
Mon, 18 Nov 2013 10:18:15 +0000 (11:18 +0100)
committerWim Taymans <wim.taymans@gmail.com>
Mon, 18 Nov 2013 10:18:15 +0000 (11:18 +0100)
Add a method to safely iterate and collect the stream transports

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

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

index 09dc4b46040f6a1f59fed24e47c41873e38340df..6e9218df80a87e543f234c5bba2f6c46f2a28521 100644 (file)
@@ -2064,3 +2064,70 @@ gst_rtsp_stream_get_rtcp_socket (GstRTSPStream * stream, GSocketFamily family)
 
   return socket;
 }
+
+/**
+ * gst_rtsp_stream_transport_filter:
+ * @stream: a #GstRTSPStream
+ * @func: (scope call): a callback
+ * @user_data: user data passed to @func
+ *
+ * Call @func for each transport managed by @stream. The result value of @func
+ * determines what happens to the transport. @func will be called with @stream
+ * locked so no further actions on @stream can be performed from @func.
+ *
+ * If @func returns #GST_RTSP_FILTER_REMOVE, the transport will be removed from
+ * @stream.
+ *
+ * If @func returns #GST_RTSP_FILTER_KEEP, the transport will remain in @stream.
+ *
+ * If @func returns #GST_RTSP_FILTER_REF, the transport will remain in @stream but
+ * will also be added with an additional ref to the result #GList of this
+ * function..
+ *
+ * When @func is %NULL, #GST_RTSP_FILTER_REF will be assumed for each transport.
+ *
+ * Returns: (element-type GstRTSPStreamTransport) (transfer full): a #GList with all
+ * transports for which @func returned #GST_RTSP_FILTER_REF. After usage, each
+ * element in the #GList should be unreffed before the list is freed.
+ */
+GList *
+gst_rtsp_stream_transport_filter (GstRTSPStream * stream,
+    GstRTSPStreamTransportFilterFunc func, gpointer user_data)
+{
+  GstRTSPStreamPrivate *priv;
+  GList *result, *walk, *next;
+
+  g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), NULL);
+
+  priv = stream->priv;
+
+  result = NULL;
+
+  g_mutex_lock (&priv->lock);
+  for (walk = priv->transports; walk; walk = next) {
+    GstRTSPStreamTransport *trans = walk->data;
+    GstRTSPFilterResult res;
+
+    next = g_list_next (walk);
+
+    if (func)
+      res = func (stream, trans, user_data);
+    else
+      res = GST_RTSP_FILTER_REF;
+
+    switch (res) {
+      case GST_RTSP_FILTER_REMOVE:
+        update_transport (stream, trans, FALSE);
+        break;
+      case GST_RTSP_FILTER_REF:
+        result = g_list_prepend (result, g_object_ref (trans));
+        break;
+      case GST_RTSP_FILTER_KEEP:
+      default:
+        break;
+    }
+  }
+  g_mutex_unlock (&priv->lock);
+
+  return result;
+}
index 09fffeb93dac118f07d85c8cdbf87b8e2b1bf3b8..7bd46814cb6582e01e07cd320b7ccb474c4f886c 100644 (file)
@@ -43,6 +43,7 @@ typedef struct _GstRTSPStreamPrivate GstRTSPStreamPrivate;
 
 #include "rtsp-stream-transport.h"
 #include "rtsp-address-pool.h"
+#include "rtsp-session.h"
 
 /**
  * GstRTSPStream:
@@ -127,6 +128,35 @@ GSocket *         gst_rtsp_stream_get_rtp_socket   (GstRTSPStream *stream,
 GSocket *         gst_rtsp_stream_get_rtcp_socket  (GstRTSPStream *stream,
                                                     GSocketFamily family);
 
+/**
+ * GstRTSPStreamTransportFilterFunc:
+ * @stream: a #GstRTSPStream object
+ * @trans: a #GstRTSPStreamTransport in @stream
+ * @user_data: user data that has been given to gst_rtsp_stream_transport_filter()
+ *
+ * This function will be called by the gst_rtsp_stream_transport_filter(). An
+ * implementation should return a value of #GstRTSPFilterResult.
+ *
+ * When this function returns #GST_RTSP_FILTER_REMOVE, @trans will be removed
+ * from @stream.
+ *
+ * A return value of #GST_RTSP_FILTER_KEEP will leave @trans untouched in
+ * @stream.
+ *
+ * A value of #GST_RTSP_FILTER_REF will add @trans to the result #GList of
+ * gst_rtsp_stream_transport_filter().
+ *
+ * Returns: a #GstRTSPFilterResult.
+ */
+typedef GstRTSPFilterResult (*GstRTSPStreamTransportFilterFunc) (GstRTSPStream *stream,
+                                                                 GstRTSPStreamTransport *trans,
+                                                                 gpointer user_data);
+
+GList *                gst_rtsp_stream_transport_filter  (GstRTSPStream *stream,
+                                                          GstRTSPStreamTransportFilterFunc func,
+                                                          gpointer user_data);
+
+
 G_END_DECLS
 
 #endif /* __GST_RTSP_STREAM_H__ */