server: use a threadpool for the mainloops

This commit is contained in:
Wim Taymans 2012-11-12 15:29:39 +01:00
parent c431592976
commit 8523c9ca92
2 changed files with 11 additions and 5 deletions

View file

@ -58,6 +58,8 @@ G_DEFINE_TYPE (GstRTSPServer, gst_rtsp_server, G_TYPE_OBJECT);
GST_DEBUG_CATEGORY_STATIC (rtsp_server_debug); GST_DEBUG_CATEGORY_STATIC (rtsp_server_debug);
#define GST_CAT_DEFAULT rtsp_server_debug #define GST_CAT_DEFAULT rtsp_server_debug
typedef struct _ClientContext ClientContext;
static guint gst_rtsp_server_signals[SIGNAL_LAST] = { 0 }; static guint gst_rtsp_server_signals[SIGNAL_LAST] = { 0 };
static void gst_rtsp_server_get_property (GObject * object, guint propid, static void gst_rtsp_server_get_property (GObject * object, guint propid,
@ -66,6 +68,7 @@ static void gst_rtsp_server_set_property (GObject * object, guint propid,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
static void gst_rtsp_server_finalize (GObject * object); static void gst_rtsp_server_finalize (GObject * object);
static gpointer do_loop (ClientContext * ctx);
static GstRTSPClient *default_create_client (GstRTSPServer * server); static GstRTSPClient *default_create_client (GstRTSPServer * server);
static gboolean default_accept_client (GstRTSPServer * server, static gboolean default_accept_client (GstRTSPServer * server,
GstRTSPClient * client, GSocket * socket, GError ** error); GstRTSPClient * client, GSocket * socket, GError ** error);
@ -160,6 +163,8 @@ gst_rtsp_server_class_init (GstRTSPServerClass * klass)
klass->create_client = default_create_client; klass->create_client = default_create_client;
klass->accept_client = default_accept_client; klass->accept_client = default_accept_client;
klass->pool = g_thread_pool_new ((GFunc) do_loop, klass, -1, FALSE, NULL);
GST_DEBUG_CATEGORY_INIT (rtsp_server_debug, "rtspserver", 0, "GstRTSPServer"); GST_DEBUG_CATEGORY_INIT (rtsp_server_debug, "rtspserver", 0, "GstRTSPServer");
} }
@ -749,13 +754,13 @@ close_error:
} }
} }
typedef struct struct _ClientContext
{ {
GstRTSPServer *server; GstRTSPServer *server;
GMainLoop *loop; GMainLoop *loop;
GMainContext *context; GMainContext *context;
GstRTSPClient *client; GstRTSPClient *client;
} ClientContext; };
static void static void
free_client_context (ClientContext * ctx) free_client_context (ClientContext * ctx)
@ -837,10 +842,9 @@ manage_client (GstRTSPServer * server, GstRTSPClient * client)
GST_RTSP_SERVER_UNLOCK (server); GST_RTSP_SERVER_UNLOCK (server);
if (ctx->loop) { if (ctx->loop) {
GThread *thread; GstRTSPServerClass *klass = GST_RTSP_SERVER_GET_CLASS (server);
thread = g_thread_new ("MainLoop Thread", (GThreadFunc) do_loop, ctx); g_thread_pool_push (klass->pool, ctx, NULL);
g_thread_unref (thread);
} }
} }

View file

@ -89,6 +89,8 @@ struct _GstRTSPServer {
struct _GstRTSPServerClass { struct _GstRTSPServerClass {
GObjectClass parent_class; GObjectClass parent_class;
GThreadPool *pool;
GstRTSPClient * (*create_client) (GstRTSPServer *server); GstRTSPClient * (*create_client) (GstRTSPServer *server);
gboolean (*accept_client) (GstRTSPServer *server, GstRTSPClient *client, gboolean (*accept_client) (GstRTSPServer *server, GstRTSPClient *client,
GSocket *socket, GError **error); GSocket *socket, GError **error);