#include "rtsp-sdp.h"
#include "rtsp-params.h"
-static GMutex *tunnels_lock;
+static GMutex tunnels_lock;
static GHashTable *tunnels;
enum
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");
}
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);
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;
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;
}
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;
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;
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);
}
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;
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);
}
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);
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);
}
/**
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);
}
}
}
- g_mutex_unlock (factory->medias_lock);
+ g_mutex_unlock (&factory->medias_lock);
if (key)
g_free (key);
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)))
* 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;
guint buffer_size;
gchar *multicast_group;
- GMutex *medias_lock;
+ GMutex medias_lock;
GHashTable *medias;
};
gst_rtsp_media_class_init (GstRTSPMediaClass * klass)
{
GObjectClass *gobject_class;
- GError *error = NULL;
gobject_class = G_OBJECT_CLASS (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;
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;
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);
}
{
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);
}
/**
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;
}
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;
}
/* 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;
}
struct _GstRTSPMedia {
GObject parent;
- GMutex *lock;
- GCond *cond;
+ GMutex lock;
+ GCond cond;
gboolean shared;
gboolean reusable;
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;
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);
}
#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)))
struct _GstRTSPServer {
GObject parent;
- GMutex *lock;
+ GMutex lock;
/* server information */
gchar *address;
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;
{
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);
{
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);
}
/**
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;
}
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;
}
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;
}
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)
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);
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;
}
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;
}
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;
}
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;
}
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;
guint max_sessions;
- GMutex *lock;
+ GMutex lock;
GHashTable *sessions;
};