session-pool: make vmethod to create a session

Make a vmethod to create a sessions so that subclasses can create
custom session objects
This commit is contained in:
Wim Taymans 2013-07-11 16:28:09 +02:00
parent d357fc55af
commit 8b4c9570fa
2 changed files with 17 additions and 4 deletions

View file

@ -56,6 +56,8 @@ static void gst_rtsp_session_pool_set_property (GObject * object, guint propid,
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); static gchar *create_session_id (GstRTSPSessionPool * pool);
static GstRTSPSession *create_session (GstRTSPSessionPool * pool,
const gchar * id);
G_DEFINE_TYPE (GstRTSPSessionPool, gst_rtsp_session_pool, G_TYPE_OBJECT); G_DEFINE_TYPE (GstRTSPSessionPool, gst_rtsp_session_pool, G_TYPE_OBJECT);
@ -79,6 +81,7 @@ gst_rtsp_session_pool_class_init (GstRTSPSessionPoolClass * klass)
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
klass->create_session_id = create_session_id; klass->create_session_id = create_session_id;
klass->create_session = create_session;
GST_DEBUG_CATEGORY_INIT (rtsp_session_debug, "rtspsessionpool", 0, GST_DEBUG_CATEGORY_INIT (rtsp_session_debug, "rtspsessionpool", 0,
"GstRTSPSessionPool"); "GstRTSPSessionPool");
@ -279,6 +282,12 @@ create_session_id (GstRTSPSessionPool * pool)
return g_strndup (id, 16); return g_strndup (id, 16);
} }
static GstRTSPSession *
create_session (GstRTSPSessionPool * pool, const gchar * id)
{
return gst_rtsp_session_new (id);
}
/** /**
* gst_rtsp_session_pool_create: * gst_rtsp_session_pool_create:
* @pool: a #GstRTSPSessionPool * @pool: a #GstRTSPSessionPool
@ -330,7 +339,10 @@ gst_rtsp_session_pool_create (GstRTSPSessionPool * pool)
goto collision; goto collision;
} else { } else {
/* not found, create session and insert it in the pool */ /* not found, create session and insert it in the pool */
result = gst_rtsp_session_new (id); if (klass->create_session)
result = create_session (pool, id);
if (result == NULL)
goto too_many_sessions;
/* take additional ref for the pool */ /* take additional ref for the pool */
g_object_ref (result); g_object_ref (result);
g_hash_table_insert (priv->sessions, g_hash_table_insert (priv->sessions,

View file

@ -22,7 +22,6 @@
#ifndef __GST_RTSP_SESSION_POOL_H__ #ifndef __GST_RTSP_SESSION_POOL_H__
#define __GST_RTSP_SESSION_POOL_H__ #define __GST_RTSP_SESSION_POOL_H__
G_BEGIN_DECLS G_BEGIN_DECLS
typedef struct _GstRTSPSessionPool GstRTSPSessionPool; typedef struct _GstRTSPSessionPool GstRTSPSessionPool;
@ -57,11 +56,13 @@ struct _GstRTSPSessionPool {
* GstRTSPSessionPoolClass: * GstRTSPSessionPoolClass:
* @create_session_id: create a new random session id. Subclasses can create * @create_session_id: create a new random session id. Subclasses can create
* custom session ids and should not check if the session exists. * custom session ids and should not check if the session exists.
* @create_session: make a new session object.
*/ */
struct _GstRTSPSessionPoolClass { struct _GstRTSPSessionPoolClass {
GObjectClass parent_class; GObjectClass parent_class;
gchar * (*create_session_id) (GstRTSPSessionPool *pool); gchar * (*create_session_id) (GstRTSPSessionPool *pool);
GstRTSPSession * (*create_session) (GstRTSPSessionPool *pool, const gchar *id);
}; };
/** /**
@ -108,7 +109,7 @@ GType gst_rtsp_session_pool_get_type (void);
/* creating a session pool */ /* creating a session pool */
GstRTSPSessionPool * gst_rtsp_session_pool_new (void); GstRTSPSessionPool * gst_rtsp_session_pool_new (void);
/* counting sessionss */ /* counting sessions */
void gst_rtsp_session_pool_set_max_sessions (GstRTSPSessionPool *pool, guint max); void gst_rtsp_session_pool_set_max_sessions (GstRTSPSessionPool *pool, guint max);
guint gst_rtsp_session_pool_get_max_sessions (GstRTSPSessionPool *pool); guint gst_rtsp_session_pool_get_max_sessions (GstRTSPSessionPool *pool);