mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-09 08:55:33 +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 gchar * create_session_id (GstRTSPSessionPool *pool);
|
||||
|
||||
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->finalize = gst_rtsp_session_pool_finalize;
|
||||
|
||||
klass->create_session_id = create_session_id;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -59,6 +62,8 @@ gst_rtsp_session_pool_finalize (GObject * object)
|
|||
* gst_rtsp_session_pool_new:
|
||||
*
|
||||
* Create a new #GstRTSPSessionPool instance.
|
||||
*
|
||||
* Returns: A new #GstRTSPSessionPool. g_object_unref() after usage.
|
||||
*/
|
||||
GstRTSPSessionPool *
|
||||
gst_rtsp_session_pool_new (void)
|
||||
|
@ -98,7 +103,7 @@ gst_rtsp_session_pool_find (GstRTSPSessionPool *pool, const gchar *sessionid)
|
|||
}
|
||||
|
||||
static gchar *
|
||||
create_session_id (void)
|
||||
create_session_id (GstRTSPSessionPool *pool)
|
||||
{
|
||||
gchar id[16];
|
||||
gint i;
|
||||
|
@ -122,14 +127,23 @@ GstRTSPSession *
|
|||
gst_rtsp_session_pool_create (GstRTSPSessionPool *pool)
|
||||
{
|
||||
GstRTSPSession *result = NULL;
|
||||
gchar *id;
|
||||
GstRTSPSessionPoolClass *klass;
|
||||
gchar *id = NULL;
|
||||
|
||||
g_return_val_if_fail (GST_IS_RTSP_SESSION_POOL (pool), NULL);
|
||||
|
||||
klass = GST_RTSP_SESSION_POOL_GET_CLASS (pool);
|
||||
|
||||
do {
|
||||
/* 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 */
|
||||
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);
|
||||
/* check if the sessionid existed */
|
||||
|
@ -151,6 +165,18 @@ gst_rtsp_session_pool_create (GstRTSPSessionPool *pool)
|
|||
} while (result == NULL);
|
||||
|
||||
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:
|
||||
*
|
||||
* @lock: locking the session hashtable
|
||||
* @session: hashtable of sessions indexed by the session id.
|
||||
*
|
||||
* An object that keeps track of the active sessions.
|
||||
*/
|
||||
struct _GstRTSPSessionPool {
|
||||
|
@ -50,8 +53,16 @@ struct _GstRTSPSessionPool {
|
|||
GHashTable *sessions;
|
||||
};
|
||||
|
||||
/**
|
||||
* GstRTSPSessionPoolClass:
|
||||
*
|
||||
* @create_session_id: create a new random session id. Subclasses should not
|
||||
* check if the session exists.
|
||||
*/
|
||||
struct _GstRTSPSessionPoolClass {
|
||||
GObjectClass parent_class;
|
||||
|
||||
gchar * (*create_session_id) (GstRTSPSessionPool *pool);
|
||||
};
|
||||
|
||||
GType gst_rtsp_session_pool_get_type (void);
|
||||
|
|
Loading…
Reference in a new issue