From a106950f7089a2a4b133d70dd79f2106e4c012bd Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 18 Nov 2013 11:18:15 +0100 Subject: [PATCH] stream: add method to filter transports 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 | 67 +++++++++++++++++++++++++++++++++++++++++++ gst/rtsp-server/rtsp-stream.h | 30 +++++++++++++++++++ 2 files changed, 97 insertions(+) diff --git a/gst/rtsp-server/rtsp-stream.c b/gst/rtsp-server/rtsp-stream.c index 09dc4b4..6e9218d 100644 --- a/gst/rtsp-server/rtsp-stream.c +++ b/gst/rtsp-server/rtsp-stream.c @@ -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; +} diff --git a/gst/rtsp-server/rtsp-stream.h b/gst/rtsp-server/rtsp-stream.h index 09fffeb..7bd4681 100644 --- a/gst/rtsp-server/rtsp-stream.h +++ b/gst/rtsp-server/rtsp-stream.h @@ -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__ */ -- 2.7.4