rtsp-server: port to new thread API

This commit is contained in:
Wim Taymans 2012-05-11 09:42:47 +02:00
parent a798e8dcfd
commit 6cc2fb9bfc
9 changed files with 72 additions and 76 deletions

View file

@ -36,7 +36,7 @@
#include "rtsp-sdp.h"
#include "rtsp-params.h"
static GMutex *tunnels_lock;
static GMutex tunnels_lock;
static GHashTable *tunnels;
enum
@ -101,7 +101,7 @@ gst_rtsp_client_class_init (GstRTSPClientClass * klass)
tunnels =
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
tunnels_lock = g_mutex_new ();
g_mutex_init (&tunnels_lock);
GST_DEBUG_CATEGORY_INIT (rtsp_client_debug, "rtspclient", 0, "GstRTSPClient");
}
@ -495,10 +495,10 @@ close_connection (GstRTSPClient * client)
GST_DEBUG ("client %p: closing connection", client);
if ((tunnelid = gst_rtsp_connection_get_tunnelid (client->connection))) {
g_mutex_lock (tunnels_lock);
g_mutex_lock (&tunnels_lock);
/* remove from tunnelids */
g_hash_table_remove (tunnels, tunnelid);
g_mutex_unlock (tunnels_lock);
g_mutex_unlock (&tunnels_lock);
}
gst_rtsp_connection_close (client->connection);
@ -1687,10 +1687,10 @@ closed (GstRTSPWatch * watch, gpointer user_data)
GST_INFO ("client %p: connection closed", client);
if ((tunnelid = gst_rtsp_connection_get_tunnelid (client->connection))) {
g_mutex_lock (tunnels_lock);
g_mutex_lock (&tunnels_lock);
/* remove from tunnelids */
g_hash_table_remove (tunnels, tunnelid);
g_mutex_unlock (tunnels_lock);
g_mutex_unlock (&tunnels_lock);
}
return GST_RTSP_OK;
@ -1738,12 +1738,12 @@ remember_tunnel (GstRTSPClient * client)
GST_INFO ("client %p: inserting tunnel session %s", client, tunnelid);
/* we can't have two clients connecting with the same tunnelid */
g_mutex_lock (tunnels_lock);
g_mutex_lock (&tunnels_lock);
if (g_hash_table_lookup (tunnels, tunnelid))
goto tunnel_existed;
g_hash_table_insert (tunnels, g_strdup (tunnelid), g_object_ref (client));
g_mutex_unlock (tunnels_lock);
g_mutex_unlock (&tunnels_lock);
return TRUE;
@ -1755,7 +1755,7 @@ no_tunnelid:
}
tunnel_existed:
{
g_mutex_unlock (tunnels_lock);
g_mutex_unlock (&tunnels_lock);
GST_ERROR ("client %p: tunnel session %s already existed", client,
tunnelid);
return FALSE;
@ -1815,7 +1815,7 @@ tunnel_complete (GstRTSPWatch * watch, gpointer user_data)
if (tunnelid == NULL)
goto no_tunnelid;
g_mutex_lock (tunnels_lock);
g_mutex_lock (&tunnels_lock);
if (!(oclient = g_hash_table_lookup (tunnels, tunnelid)))
goto no_tunnel;
@ -1826,7 +1826,7 @@ tunnel_complete (GstRTSPWatch * watch, gpointer user_data)
if (oclient->watch == NULL)
goto tunnel_closed;
g_mutex_unlock (tunnels_lock);
g_mutex_unlock (&tunnels_lock);
GST_INFO ("client %p: found tunnel %p (old %p, new %p)", client, oclient,
oclient->connection, client->connection);
@ -1851,13 +1851,13 @@ no_tunnelid:
}
no_tunnel:
{
g_mutex_unlock (tunnels_lock);
g_mutex_unlock (&tunnels_lock);
GST_INFO ("client %p: tunnel session %s not found", client, tunnelid);
return GST_RTSP_ERROR;
}
tunnel_closed:
{
g_mutex_unlock (tunnels_lock);
g_mutex_unlock (&tunnels_lock);
GST_INFO ("client %p: tunnel session %s was closed", client, tunnelid);
g_object_unref (oclient);
return GST_RTSP_ERROR;

View file

@ -158,8 +158,8 @@ gst_rtsp_media_factory_init (GstRTSPMediaFactory * factory)
factory->buffer_size = DEFAULT_BUFFER_SIZE;
factory->multicast_group = g_strdup (DEFAULT_MULTICAST_GROUP);
factory->lock = g_mutex_new ();
factory->medias_lock = g_mutex_new ();
g_mutex_init (&factory->lock);
g_mutex_init (&factory->medias_lock);
factory->medias = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_object_unref);
}
@ -170,10 +170,10 @@ gst_rtsp_media_factory_finalize (GObject * obj)
GstRTSPMediaFactory *factory = GST_RTSP_MEDIA_FACTORY (obj);
g_hash_table_unref (factory->medias);
g_mutex_free (factory->medias_lock);
g_mutex_clear (&factory->medias_lock);
g_free (factory->launch);
g_free (factory->multicast_group);
g_mutex_free (factory->lock);
g_mutex_clear (&factory->lock);
if (factory->auth)
g_object_unref (factory->auth);
@ -568,9 +568,9 @@ compare_media (gpointer key, GstRTSPMedia * media1, GstRTSPMedia * media2)
static void
media_unprepared (GstRTSPMedia * media, GstRTSPMediaFactory * factory)
{
g_mutex_lock (factory->medias_lock);
g_mutex_lock (&factory->medias_lock);
g_hash_table_foreach_remove (factory->medias, (GHRFunc) compare_media, media);
g_mutex_unlock (factory->medias_lock);
g_mutex_unlock (&factory->medias_lock);
}
/**
@ -605,7 +605,7 @@ gst_rtsp_media_factory_construct (GstRTSPMediaFactory * factory,
else
key = NULL;
g_mutex_lock (factory->medias_lock);
g_mutex_lock (&factory->medias_lock);
if (key) {
/* we have a key, see if we find a cached media */
media = g_hash_table_lookup (factory->medias, key);
@ -649,7 +649,7 @@ gst_rtsp_media_factory_construct (GstRTSPMediaFactory * factory,
}
}
}
g_mutex_unlock (factory->medias_lock);
g_mutex_unlock (&factory->medias_lock);
if (key)
g_free (key);

View file

@ -41,7 +41,7 @@ G_BEGIN_DECLS
typedef struct _GstRTSPMediaFactory GstRTSPMediaFactory;
typedef struct _GstRTSPMediaFactoryClass GstRTSPMediaFactoryClass;
#define GST_RTSP_MEDIA_FACTORY_GET_LOCK(f) (GST_RTSP_MEDIA_FACTORY_CAST(f)->lock)
#define GST_RTSP_MEDIA_FACTORY_GET_LOCK(f) (&(GST_RTSP_MEDIA_FACTORY_CAST(f)->lock))
#define GST_RTSP_MEDIA_FACTORY_LOCK(f) (g_mutex_lock(GST_RTSP_MEDIA_FACTORY_GET_LOCK(f)))
#define GST_RTSP_MEDIA_FACTORY_UNLOCK(f) (g_mutex_unlock(GST_RTSP_MEDIA_FACTORY_GET_LOCK(f)))
@ -62,9 +62,9 @@ typedef struct _GstRTSPMediaFactoryClass GstRTSPMediaFactoryClass;
* can contain multiple streams like audio and video.
*/
struct _GstRTSPMediaFactory {
GObject parent;
GObject parent;
GMutex *lock;
GMutex lock;
gchar *launch;
gboolean shared;
gboolean eos_shutdown;
@ -73,7 +73,7 @@ struct _GstRTSPMediaFactory {
guint buffer_size;
gchar *multicast_group;
GMutex *medias_lock;
GMutex medias_lock;
GHashTable *medias;
};

View file

@ -81,7 +81,6 @@ static void
gst_rtsp_media_class_init (GstRTSPMediaClass * klass)
{
GObjectClass *gobject_class;
GError *error = NULL;
gobject_class = G_OBJECT_CLASS (klass);
@ -139,10 +138,8 @@ gst_rtsp_media_class_init (GstRTSPMediaClass * klass)
GST_DEBUG_CATEGORY_INIT (rtsp_media_debug, "rtspmedia", 0, "GstRTSPMedia");
klass->thread = g_thread_create ((GThreadFunc) do_loop, klass, TRUE, &error);
if (error != NULL) {
g_critical ("could not start bus thread: %s", error->message);
}
klass->thread = g_thread_new ("Bus Thread", (GThreadFunc) do_loop, klass);
klass->handle_message = default_handle_message;
klass->unprepare = default_unprepare;
@ -153,8 +150,8 @@ static void
gst_rtsp_media_init (GstRTSPMedia * media)
{
media->streams = g_array_new (FALSE, TRUE, sizeof (GstRTSPMediaStream *));
media->lock = g_mutex_new ();
media->cond = g_cond_new ();
g_mutex_init (&media->lock);
g_cond_init (&media->cond);
media->shared = DEFAULT_SHARED;
media->reusable = DEFAULT_REUSABLE;
@ -235,8 +232,8 @@ gst_rtsp_media_finalize (GObject * obj)
g_source_unref (media->source);
}
g_free (media->multicast_group);
g_mutex_free (media->lock);
g_cond_free (media->cond);
g_mutex_clear (&media->lock);
g_cond_clear (&media->cond);
G_OBJECT_CLASS (gst_rtsp_media_parent_class)->finalize (obj);
}
@ -550,10 +547,10 @@ gst_rtsp_media_set_multicast_group (GstRTSPMedia * media, const gchar * mc)
{
g_return_if_fail (GST_IS_RTSP_MEDIA (media));
g_mutex_lock (media->lock);
g_mutex_lock (&media->lock);
g_free (media->multicast_group);
media->multicast_group = g_strdup (mc);
g_mutex_unlock (media->lock);
g_mutex_unlock (&media->lock);
}
/**
@ -571,9 +568,9 @@ gst_rtsp_media_get_multicast_group (GstRTSPMedia * media)
g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL);
g_mutex_lock (media->lock);
g_mutex_lock (&media->lock);
result = g_strdup (media->multicast_group);
g_mutex_unlock (media->lock);
g_mutex_unlock (&media->lock);
return result;
}
@ -1445,28 +1442,27 @@ unlock_streams (GstRTSPMedia * media)
static void
gst_rtsp_media_set_status (GstRTSPMedia * media, GstRTSPMediaStatus status)
{
g_mutex_lock (media->lock);
g_mutex_lock (&media->lock);
/* never overwrite the error status */
if (media->status != GST_RTSP_MEDIA_STATUS_ERROR)
media->status = status;
GST_DEBUG ("setting new status to %d", status);
g_cond_broadcast (media->cond);
g_mutex_unlock (media->lock);
g_cond_broadcast (&media->cond);
g_mutex_unlock (&media->lock);
}
static GstRTSPMediaStatus
gst_rtsp_media_get_status (GstRTSPMedia * media)
{
GstRTSPMediaStatus result;
GTimeVal timeout;
gint64 end_time;
g_mutex_lock (media->lock);
g_get_current_time (&timeout);
g_time_val_add (&timeout, 20 * G_USEC_PER_SEC);
g_mutex_lock (&media->lock);
end_time = g_get_monotonic_time () + 20 * G_TIME_SPAN_SECOND;
/* while we are preparing, wait */
while (media->status == GST_RTSP_MEDIA_STATUS_PREPARING) {
GST_DEBUG ("waiting for status change");
if (!g_cond_timed_wait (media->cond, media->lock, &timeout)) {
if (!g_cond_wait_until (&media->cond, &media->lock, end_time)) {
GST_DEBUG ("timeout, assuming error status");
media->status = GST_RTSP_MEDIA_STATUS_ERROR;
}
@ -1474,7 +1470,7 @@ gst_rtsp_media_get_status (GstRTSPMedia * media)
/* could be success or error */
result = media->status;
GST_DEBUG ("got status %d", result);
g_mutex_unlock (media->lock);
g_mutex_unlock (&media->lock);
return result;
}

View file

@ -191,8 +191,8 @@ typedef enum {
struct _GstRTSPMedia {
GObject parent;
GMutex *lock;
GCond *cond;
GMutex lock;
GCond cond;
gboolean shared;
gboolean reusable;

View file

@ -164,7 +164,7 @@ gst_rtsp_server_class_init (GstRTSPServerClass * klass)
static void
gst_rtsp_server_init (GstRTSPServer * server)
{
server->lock = g_mutex_new ();
g_mutex_init (&server->lock);
server->address = g_strdup (DEFAULT_ADDRESS);
server->service = g_strdup (DEFAULT_SERVICE);
server->backlog = DEFAULT_BACKLOG;
@ -188,7 +188,7 @@ gst_rtsp_server_finalize (GObject * object)
if (server->auth)
g_object_unref (server->auth);
g_mutex_free (server->lock);
g_mutex_clear (&server->lock);
G_OBJECT_CLASS (gst_rtsp_server_parent_class)->finalize (object);
}

View file

@ -42,7 +42,7 @@ typedef struct _GstRTSPServerClass GstRTSPServerClass;
#define GST_RTSP_SERVER_CAST(obj) ((GstRTSPServer*)(obj))
#define GST_RTSP_SERVER_CLASS_CAST(klass) ((GstRTSPServerClass*)(klass))
#define GST_RTSP_SERVER_GET_LOCK(server) (GST_RTSP_SERVER_CAST(server)->lock)
#define GST_RTSP_SERVER_GET_LOCK(server) (&(GST_RTSP_SERVER_CAST(server)->lock))
#define GST_RTSP_SERVER_LOCK(server) (g_mutex_lock(GST_RTSP_SERVER_GET_LOCK(server)))
#define GST_RTSP_SERVER_UNLOCK(server) (g_mutex_unlock(GST_RTSP_SERVER_GET_LOCK(server)))
@ -55,7 +55,7 @@ typedef struct _GstRTSPServerClass GstRTSPServerClass;
struct _GstRTSPServer {
GObject parent;
GMutex *lock;
GMutex lock;
/* server information */
gchar *address;

View file

@ -77,7 +77,7 @@ gst_rtsp_session_pool_class_init (GstRTSPSessionPoolClass * klass)
static void
gst_rtsp_session_pool_init (GstRTSPSessionPool * pool)
{
pool->lock = g_mutex_new ();
g_mutex_init (&pool->lock);
pool->sessions = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, g_object_unref);
pool->max_sessions = DEFAULT_MAX_SESSIONS;
@ -88,7 +88,7 @@ gst_rtsp_session_pool_finalize (GObject * object)
{
GstRTSPSessionPool *pool = GST_RTSP_SESSION_POOL (object);
g_mutex_free (pool->lock);
g_mutex_clear (&pool->lock);
g_hash_table_unref (pool->sessions);
G_OBJECT_CLASS (gst_rtsp_session_pool_parent_class)->finalize (object);
@ -156,9 +156,9 @@ gst_rtsp_session_pool_set_max_sessions (GstRTSPSessionPool * pool, guint max)
{
g_return_if_fail (GST_IS_RTSP_SESSION_POOL (pool));
g_mutex_lock (pool->lock);
g_mutex_lock (&pool->lock);
pool->max_sessions = max;
g_mutex_unlock (pool->lock);
g_mutex_unlock (&pool->lock);
}
/**
@ -177,9 +177,9 @@ gst_rtsp_session_pool_get_max_sessions (GstRTSPSessionPool * pool)
g_return_val_if_fail (GST_IS_RTSP_SESSION_POOL (pool), 0);
g_mutex_lock (pool->lock);
g_mutex_lock (&pool->lock);
result = pool->max_sessions;
g_mutex_unlock (pool->lock);
g_mutex_unlock (&pool->lock);
return result;
}
@ -199,9 +199,9 @@ gst_rtsp_session_pool_get_n_sessions (GstRTSPSessionPool * pool)
g_return_val_if_fail (GST_IS_RTSP_SESSION_POOL (pool), 0);
g_mutex_lock (pool->lock);
g_mutex_lock (&pool->lock);
result = g_hash_table_size (pool->sessions);
g_mutex_unlock (pool->lock);
g_mutex_unlock (&pool->lock);
return result;
}
@ -225,13 +225,13 @@ gst_rtsp_session_pool_find (GstRTSPSessionPool * pool, const gchar * sessionid)
g_return_val_if_fail (GST_IS_RTSP_SESSION_POOL (pool), NULL);
g_return_val_if_fail (sessionid != NULL, NULL);
g_mutex_lock (pool->lock);
g_mutex_lock (&pool->lock);
result = g_hash_table_lookup (pool->sessions, sessionid);
if (result) {
g_object_ref (result);
gst_rtsp_session_touch (result);
}
g_mutex_unlock (pool->lock);
g_mutex_unlock (&pool->lock);
return result;
}
@ -283,7 +283,7 @@ gst_rtsp_session_pool_create (GstRTSPSessionPool * pool)
if (id == NULL)
goto no_session;
g_mutex_lock (pool->lock);
g_mutex_lock (&pool->lock);
/* check session limit */
if (pool->max_sessions > 0) {
if (g_hash_table_size (pool->sessions) >= pool->max_sessions)
@ -304,7 +304,7 @@ gst_rtsp_session_pool_create (GstRTSPSessionPool * pool)
g_object_ref (result);
g_hash_table_insert (pool->sessions, result->sessionid, result);
}
g_mutex_unlock (pool->lock);
g_mutex_unlock (&pool->lock);
g_free (id);
} while (result == NULL);
@ -325,14 +325,14 @@ no_session:
collision:
{
GST_WARNING ("can't find unique sessionid for GstRTSPSessionPool %p", pool);
g_mutex_unlock (pool->lock);
g_mutex_unlock (&pool->lock);
g_free (id);
return NULL;
}
too_many_sessions:
{
GST_WARNING ("session pool reached max sessions of %d", pool->max_sessions);
g_mutex_unlock (pool->lock);
g_mutex_unlock (&pool->lock);
g_free (id);
return NULL;
}
@ -355,9 +355,9 @@ gst_rtsp_session_pool_remove (GstRTSPSessionPool * pool, GstRTSPSession * sess)
g_return_val_if_fail (GST_IS_RTSP_SESSION_POOL (pool), FALSE);
g_return_val_if_fail (GST_IS_RTSP_SESSION (sess), FALSE);
g_mutex_lock (pool->lock);
g_mutex_lock (&pool->lock);
found = g_hash_table_remove (pool->sessions, sess->sessionid);
g_mutex_unlock (pool->lock);
g_mutex_unlock (&pool->lock);
return found;
}
@ -387,11 +387,11 @@ gst_rtsp_session_pool_cleanup (GstRTSPSessionPool * pool)
g_get_current_time (&now);
g_mutex_lock (pool->lock);
g_mutex_lock (&pool->lock);
result =
g_hash_table_foreach_remove (pool->sessions, (GHRFunc) cleanup_func,
&now);
g_mutex_unlock (pool->lock);
g_mutex_unlock (&pool->lock);
return result;
}
@ -457,9 +457,9 @@ gst_rtsp_session_pool_filter (GstRTSPSessionPool * pool,
data.user_data = user_data;
data.list = NULL;
g_mutex_lock (pool->lock);
g_mutex_lock (&pool->lock);
g_hash_table_foreach_remove (pool->sessions, (GHRFunc) filter_func, &data);
g_mutex_unlock (pool->lock);
g_mutex_unlock (&pool->lock);
return data.list;
}
@ -497,9 +497,9 @@ gst_pool_source_prepare (GSource * source, gint * timeout)
psrc = (GstPoolSource *) source;
psrc->timeout = -1;
g_mutex_lock (psrc->pool->lock);
g_mutex_lock (&psrc->pool->lock);
g_hash_table_foreach (psrc->pool->sessions, (GHFunc) collect_timeout, psrc);
g_mutex_unlock (psrc->pool->lock);
g_mutex_unlock (&psrc->pool->lock);
if (timeout)
*timeout = psrc->timeout;

View file

@ -53,7 +53,7 @@ struct _GstRTSPSessionPool {
guint max_sessions;
GMutex *lock;
GMutex lock;
GHashTable *sessions;
};