mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 19:51:11 +00:00
sessionpool: add function to filter sessions
Add generic function to retrieve/remove sessions.
This commit is contained in:
parent
a403469a03
commit
a4c90c28c7
2 changed files with 110 additions and 0 deletions
|
@ -380,6 +380,74 @@ gst_rtsp_session_pool_cleanup (GstRTSPSessionPool *pool)
|
|||
return result;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GstRTSPSessionPool *pool;
|
||||
GstRTSPSessionFilterFunc func;
|
||||
gpointer user_data;
|
||||
GList *list;
|
||||
} FilterData;
|
||||
|
||||
static gboolean
|
||||
filter_func (gchar *sessionid, GstRTSPSession *sess, FilterData *data)
|
||||
{
|
||||
switch (data->func (data->pool, sess, data->user_data)) {
|
||||
case GST_RTSP_FILTER_REMOVE:
|
||||
return TRUE;
|
||||
case GST_RTSP_FILTER_REF:
|
||||
/* keep ref */
|
||||
data->list = g_list_prepend (data->list, g_object_ref (sess));
|
||||
/* fallthrough */
|
||||
default:
|
||||
case GST_RTSP_FILTER_KEEP:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_rtsp_session_pool_filter:
|
||||
* @pool: a #GstRTSPSessionPool
|
||||
* @func: a callback
|
||||
* @user_data: user data passed to @func
|
||||
*
|
||||
* Call @func for each session in @pool. The result value of @func determines
|
||||
* what happens to the session. @func will be called with the session pool
|
||||
* locked so no further actions on @pool can be performed from @func.
|
||||
*
|
||||
* If @func returns #GST_RTSP_FILTER_REMOVE, the session will be removed from
|
||||
* @pool.
|
||||
*
|
||||
* If @func returns #GST_RTSP_FILTER_KEEP, the session will remain in @pool.
|
||||
*
|
||||
* If @func returns #GST_RTSP_FILTER_REF, the session will remain in @pool but
|
||||
* will also be added with an additional ref to the result GList of this
|
||||
* function..
|
||||
*
|
||||
* Returns: a GList with all sessions 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_session_pool_filter (GstRTSPSessionPool *pool,
|
||||
GstRTSPSessionFilterFunc func, gpointer user_data)
|
||||
{
|
||||
FilterData data;
|
||||
|
||||
g_return_val_if_fail (GST_IS_RTSP_SESSION_POOL (pool), NULL);
|
||||
g_return_val_if_fail (func != NULL, NULL);
|
||||
|
||||
data.pool = pool;
|
||||
data.func = func;
|
||||
data.user_data = user_data;
|
||||
data.list = NULL;
|
||||
|
||||
g_mutex_lock (pool->lock);
|
||||
g_hash_table_foreach_remove (pool->sessions, (GHRFunc) filter_func, &data);
|
||||
g_mutex_unlock (pool->lock);
|
||||
|
||||
return data.list;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GSource source;
|
||||
|
|
|
@ -81,6 +81,45 @@ struct _GstRTSPSessionPoolClass {
|
|||
*/
|
||||
typedef gboolean (*GstRTSPSessionPoolFunc) (GstRTSPSessionPool *pool, gpointer user_data);
|
||||
|
||||
/**
|
||||
* GstRTSPFilterResult:
|
||||
* @GST_RTSP_FILTER_REMOVE: Remove session
|
||||
* @GST_RTSP_FILTER_KEEP: Keep session in the pool
|
||||
* @GST_RTSP_FILTER_REF: Ref session in the result list
|
||||
*
|
||||
* Possible return values for gst_rtsp_session_pool_filter().
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GST_RTSP_FILTER_REMOVE,
|
||||
GST_RTSP_FILTER_KEEP,
|
||||
GST_RTSP_FILTER_REF,
|
||||
} GstRTSPFilterResult;
|
||||
|
||||
/**
|
||||
* GstRTSPSessionFilterFunc:
|
||||
* @pool: a #GstRTSPSessionPool object
|
||||
* @session: a #GstRTSPSession in @pool
|
||||
* @user_data: user data that has been given to gst_rtsp_session_pool_filter()
|
||||
*
|
||||
* This function will be called by the gst_rtsp_session_pool_filter(). An
|
||||
* implementation should return a value of #GstRTSPFilterResult.
|
||||
*
|
||||
* When this function returns #GST_RTSP_FILTER_REMOVE, @session will be removed
|
||||
* from @pool.
|
||||
*
|
||||
* A return value of #GST_RTSP_FILTER_KEEP will leave @session untouched in
|
||||
* @pool.
|
||||
*
|
||||
* A value of GST_RTSP_FILTER_REF will add @session to the result #GList of
|
||||
* gst_rtsp_session_pool_filter().
|
||||
*
|
||||
* Returns: a #GstRTSPFilterResult.
|
||||
*/
|
||||
typedef GstRTSPFilterResult (*GstRTSPSessionFilterFunc) (GstRTSPSessionPool *pool,
|
||||
GstRTSPSession *session,
|
||||
gpointer user_data);
|
||||
|
||||
|
||||
GType gst_rtsp_session_pool_get_type (void);
|
||||
|
||||
|
@ -101,6 +140,9 @@ gboolean gst_rtsp_session_pool_remove (GstRTSPSessionPoo
|
|||
GstRTSPSession *sess);
|
||||
|
||||
/* perform session maintenance */
|
||||
GList * gst_rtsp_session_pool_filter (GstRTSPSessionPool *pool,
|
||||
GstRTSPSessionFilterFunc func,
|
||||
gpointer user_data);
|
||||
guint gst_rtsp_session_pool_cleanup (GstRTSPSessionPool *pool);
|
||||
GSource * gst_rtsp_session_pool_create_watch (GstRTSPSessionPool *pool);
|
||||
|
||||
|
|
Loading…
Reference in a new issue