mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-05 23:18:52 +00:00
Allow custom session pools to override the session id allocation algorithms
Add some comments.
This commit is contained in:
parent
f00188b50e
commit
a3522af4f8
2 changed files with 40 additions and 3 deletions
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
static void gst_rtsp_session_pool_finalize (GObject * object);
|
static void gst_rtsp_session_pool_finalize (GObject * object);
|
||||||
|
|
||||||
|
static gchar * create_session_id (GstRTSPSessionPool *pool);
|
||||||
|
|
||||||
G_DEFINE_TYPE (GstRTSPSessionPool, gst_rtsp_session_pool, G_TYPE_OBJECT);
|
G_DEFINE_TYPE (GstRTSPSessionPool, gst_rtsp_session_pool, G_TYPE_OBJECT);
|
||||||
|
|
||||||
|
@ -34,6 +35,8 @@ gst_rtsp_session_pool_class_init (GstRTSPSessionPoolClass * klass)
|
||||||
gobject_class = G_OBJECT_CLASS (klass);
|
gobject_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
gobject_class->finalize = gst_rtsp_session_pool_finalize;
|
gobject_class->finalize = gst_rtsp_session_pool_finalize;
|
||||||
|
|
||||||
|
klass->create_session_id = create_session_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -59,6 +62,8 @@ gst_rtsp_session_pool_finalize (GObject * object)
|
||||||
* gst_rtsp_session_pool_new:
|
* gst_rtsp_session_pool_new:
|
||||||
*
|
*
|
||||||
* Create a new #GstRTSPSessionPool instance.
|
* Create a new #GstRTSPSessionPool instance.
|
||||||
|
*
|
||||||
|
* Returns: A new #GstRTSPSessionPool. g_object_unref() after usage.
|
||||||
*/
|
*/
|
||||||
GstRTSPSessionPool *
|
GstRTSPSessionPool *
|
||||||
gst_rtsp_session_pool_new (void)
|
gst_rtsp_session_pool_new (void)
|
||||||
|
@ -98,7 +103,7 @@ gst_rtsp_session_pool_find (GstRTSPSessionPool *pool, const gchar *sessionid)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
create_session_id (void)
|
create_session_id (GstRTSPSessionPool *pool)
|
||||||
{
|
{
|
||||||
gchar id[16];
|
gchar id[16];
|
||||||
gint i;
|
gint i;
|
||||||
|
@ -122,14 +127,23 @@ GstRTSPSession *
|
||||||
gst_rtsp_session_pool_create (GstRTSPSessionPool *pool)
|
gst_rtsp_session_pool_create (GstRTSPSessionPool *pool)
|
||||||
{
|
{
|
||||||
GstRTSPSession *result = NULL;
|
GstRTSPSession *result = NULL;
|
||||||
gchar *id;
|
GstRTSPSessionPoolClass *klass;
|
||||||
|
gchar *id = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_RTSP_SESSION_POOL (pool), NULL);
|
g_return_val_if_fail (GST_IS_RTSP_SESSION_POOL (pool), NULL);
|
||||||
|
|
||||||
|
klass = GST_RTSP_SESSION_POOL_GET_CLASS (pool);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* start by creating a new random session id, we assume that this is random
|
/* start by creating a new random session id, we assume that this is random
|
||||||
* enough to not cause a collision, which we will check later */
|
* enough to not cause a collision, which we will check later */
|
||||||
id = create_session_id ();
|
if (klass->create_session_id)
|
||||||
|
id = klass->create_session_id (pool);
|
||||||
|
else
|
||||||
|
goto no_function;
|
||||||
|
|
||||||
|
if (id == NULL)
|
||||||
|
goto no_session;
|
||||||
|
|
||||||
g_mutex_lock (pool->lock);
|
g_mutex_lock (pool->lock);
|
||||||
/* check if the sessionid existed */
|
/* check if the sessionid existed */
|
||||||
|
@ -151,6 +165,18 @@ gst_rtsp_session_pool_create (GstRTSPSessionPool *pool)
|
||||||
} while (result == NULL);
|
} while (result == NULL);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
no_function:
|
||||||
|
{
|
||||||
|
g_warning ("no create_session_id vmethod in GstRTSPSessionPool %p", pool);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
no_session:
|
||||||
|
{
|
||||||
|
g_warning ("can't create session id with GstRTSPSessionPool %p", pool);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,6 +41,9 @@ typedef struct _GstRTSPSessionPoolClass GstRTSPSessionPoolClass;
|
||||||
/**
|
/**
|
||||||
* GstRTSPSessionPool:
|
* GstRTSPSessionPool:
|
||||||
*
|
*
|
||||||
|
* @lock: locking the session hashtable
|
||||||
|
* @session: hashtable of sessions indexed by the session id.
|
||||||
|
*
|
||||||
* An object that keeps track of the active sessions.
|
* An object that keeps track of the active sessions.
|
||||||
*/
|
*/
|
||||||
struct _GstRTSPSessionPool {
|
struct _GstRTSPSessionPool {
|
||||||
|
@ -50,8 +53,16 @@ struct _GstRTSPSessionPool {
|
||||||
GHashTable *sessions;
|
GHashTable *sessions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstRTSPSessionPoolClass:
|
||||||
|
*
|
||||||
|
* @create_session_id: create a new random session id. Subclasses should not
|
||||||
|
* check if the session exists.
|
||||||
|
*/
|
||||||
struct _GstRTSPSessionPoolClass {
|
struct _GstRTSPSessionPoolClass {
|
||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
|
|
||||||
|
gchar * (*create_session_id) (GstRTSPSessionPool *pool);
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gst_rtsp_session_pool_get_type (void);
|
GType gst_rtsp_session_pool_get_type (void);
|
||||||
|
|
Loading…
Reference in a new issue