mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-19 14:56:36 +00:00
rtsp-server: port to new thread API
This commit is contained in:
parent
a798e8dcfd
commit
6cc2fb9bfc
9 changed files with 72 additions and 76 deletions
|
@ -36,7 +36,7 @@
|
||||||
#include "rtsp-sdp.h"
|
#include "rtsp-sdp.h"
|
||||||
#include "rtsp-params.h"
|
#include "rtsp-params.h"
|
||||||
|
|
||||||
static GMutex *tunnels_lock;
|
static GMutex tunnels_lock;
|
||||||
static GHashTable *tunnels;
|
static GHashTable *tunnels;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -101,7 +101,7 @@ gst_rtsp_client_class_init (GstRTSPClientClass * klass)
|
||||||
|
|
||||||
tunnels =
|
tunnels =
|
||||||
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
|
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_CATEGORY_INIT (rtsp_client_debug, "rtspclient", 0, "GstRTSPClient");
|
||||||
}
|
}
|
||||||
|
@ -495,10 +495,10 @@ close_connection (GstRTSPClient * client)
|
||||||
GST_DEBUG ("client %p: closing connection", client);
|
GST_DEBUG ("client %p: closing connection", client);
|
||||||
|
|
||||||
if ((tunnelid = gst_rtsp_connection_get_tunnelid (client->connection))) {
|
if ((tunnelid = gst_rtsp_connection_get_tunnelid (client->connection))) {
|
||||||
g_mutex_lock (tunnels_lock);
|
g_mutex_lock (&tunnels_lock);
|
||||||
/* remove from tunnelids */
|
/* remove from tunnelids */
|
||||||
g_hash_table_remove (tunnels, tunnelid);
|
g_hash_table_remove (tunnels, tunnelid);
|
||||||
g_mutex_unlock (tunnels_lock);
|
g_mutex_unlock (&tunnels_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_rtsp_connection_close (client->connection);
|
gst_rtsp_connection_close (client->connection);
|
||||||
|
@ -1687,10 +1687,10 @@ closed (GstRTSPWatch * watch, gpointer user_data)
|
||||||
GST_INFO ("client %p: connection closed", client);
|
GST_INFO ("client %p: connection closed", client);
|
||||||
|
|
||||||
if ((tunnelid = gst_rtsp_connection_get_tunnelid (client->connection))) {
|
if ((tunnelid = gst_rtsp_connection_get_tunnelid (client->connection))) {
|
||||||
g_mutex_lock (tunnels_lock);
|
g_mutex_lock (&tunnels_lock);
|
||||||
/* remove from tunnelids */
|
/* remove from tunnelids */
|
||||||
g_hash_table_remove (tunnels, tunnelid);
|
g_hash_table_remove (tunnels, tunnelid);
|
||||||
g_mutex_unlock (tunnels_lock);
|
g_mutex_unlock (&tunnels_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
return GST_RTSP_OK;
|
return GST_RTSP_OK;
|
||||||
|
@ -1738,12 +1738,12 @@ remember_tunnel (GstRTSPClient * client)
|
||||||
GST_INFO ("client %p: inserting tunnel session %s", client, tunnelid);
|
GST_INFO ("client %p: inserting tunnel session %s", client, tunnelid);
|
||||||
|
|
||||||
/* we can't have two clients connecting with the same 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))
|
if (g_hash_table_lookup (tunnels, tunnelid))
|
||||||
goto tunnel_existed;
|
goto tunnel_existed;
|
||||||
|
|
||||||
g_hash_table_insert (tunnels, g_strdup (tunnelid), g_object_ref (client));
|
g_hash_table_insert (tunnels, g_strdup (tunnelid), g_object_ref (client));
|
||||||
g_mutex_unlock (tunnels_lock);
|
g_mutex_unlock (&tunnels_lock);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
@ -1755,7 +1755,7 @@ no_tunnelid:
|
||||||
}
|
}
|
||||||
tunnel_existed:
|
tunnel_existed:
|
||||||
{
|
{
|
||||||
g_mutex_unlock (tunnels_lock);
|
g_mutex_unlock (&tunnels_lock);
|
||||||
GST_ERROR ("client %p: tunnel session %s already existed", client,
|
GST_ERROR ("client %p: tunnel session %s already existed", client,
|
||||||
tunnelid);
|
tunnelid);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -1815,7 +1815,7 @@ tunnel_complete (GstRTSPWatch * watch, gpointer user_data)
|
||||||
if (tunnelid == NULL)
|
if (tunnelid == NULL)
|
||||||
goto no_tunnelid;
|
goto no_tunnelid;
|
||||||
|
|
||||||
g_mutex_lock (tunnels_lock);
|
g_mutex_lock (&tunnels_lock);
|
||||||
if (!(oclient = g_hash_table_lookup (tunnels, tunnelid)))
|
if (!(oclient = g_hash_table_lookup (tunnels, tunnelid)))
|
||||||
goto no_tunnel;
|
goto no_tunnel;
|
||||||
|
|
||||||
|
@ -1826,7 +1826,7 @@ tunnel_complete (GstRTSPWatch * watch, gpointer user_data)
|
||||||
|
|
||||||
if (oclient->watch == NULL)
|
if (oclient->watch == NULL)
|
||||||
goto tunnel_closed;
|
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,
|
GST_INFO ("client %p: found tunnel %p (old %p, new %p)", client, oclient,
|
||||||
oclient->connection, client->connection);
|
oclient->connection, client->connection);
|
||||||
|
@ -1851,13 +1851,13 @@ no_tunnelid:
|
||||||
}
|
}
|
||||||
no_tunnel:
|
no_tunnel:
|
||||||
{
|
{
|
||||||
g_mutex_unlock (tunnels_lock);
|
g_mutex_unlock (&tunnels_lock);
|
||||||
GST_INFO ("client %p: tunnel session %s not found", client, tunnelid);
|
GST_INFO ("client %p: tunnel session %s not found", client, tunnelid);
|
||||||
return GST_RTSP_ERROR;
|
return GST_RTSP_ERROR;
|
||||||
}
|
}
|
||||||
tunnel_closed:
|
tunnel_closed:
|
||||||
{
|
{
|
||||||
g_mutex_unlock (tunnels_lock);
|
g_mutex_unlock (&tunnels_lock);
|
||||||
GST_INFO ("client %p: tunnel session %s was closed", client, tunnelid);
|
GST_INFO ("client %p: tunnel session %s was closed", client, tunnelid);
|
||||||
g_object_unref (oclient);
|
g_object_unref (oclient);
|
||||||
return GST_RTSP_ERROR;
|
return GST_RTSP_ERROR;
|
||||||
|
|
|
@ -158,8 +158,8 @@ gst_rtsp_media_factory_init (GstRTSPMediaFactory * factory)
|
||||||
factory->buffer_size = DEFAULT_BUFFER_SIZE;
|
factory->buffer_size = DEFAULT_BUFFER_SIZE;
|
||||||
factory->multicast_group = g_strdup (DEFAULT_MULTICAST_GROUP);
|
factory->multicast_group = g_strdup (DEFAULT_MULTICAST_GROUP);
|
||||||
|
|
||||||
factory->lock = g_mutex_new ();
|
g_mutex_init (&factory->lock);
|
||||||
factory->medias_lock = g_mutex_new ();
|
g_mutex_init (&factory->medias_lock);
|
||||||
factory->medias = g_hash_table_new_full (g_str_hash, g_str_equal,
|
factory->medias = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
g_free, g_object_unref);
|
g_free, g_object_unref);
|
||||||
}
|
}
|
||||||
|
@ -170,10 +170,10 @@ gst_rtsp_media_factory_finalize (GObject * obj)
|
||||||
GstRTSPMediaFactory *factory = GST_RTSP_MEDIA_FACTORY (obj);
|
GstRTSPMediaFactory *factory = GST_RTSP_MEDIA_FACTORY (obj);
|
||||||
|
|
||||||
g_hash_table_unref (factory->medias);
|
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->launch);
|
||||||
g_free (factory->multicast_group);
|
g_free (factory->multicast_group);
|
||||||
g_mutex_free (factory->lock);
|
g_mutex_clear (&factory->lock);
|
||||||
if (factory->auth)
|
if (factory->auth)
|
||||||
g_object_unref (factory->auth);
|
g_object_unref (factory->auth);
|
||||||
|
|
||||||
|
@ -568,9 +568,9 @@ compare_media (gpointer key, GstRTSPMedia * media1, GstRTSPMedia * media2)
|
||||||
static void
|
static void
|
||||||
media_unprepared (GstRTSPMedia * media, GstRTSPMediaFactory * factory)
|
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_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
|
else
|
||||||
key = NULL;
|
key = NULL;
|
||||||
|
|
||||||
g_mutex_lock (factory->medias_lock);
|
g_mutex_lock (&factory->medias_lock);
|
||||||
if (key) {
|
if (key) {
|
||||||
/* we have a key, see if we find a cached media */
|
/* we have a key, see if we find a cached media */
|
||||||
media = g_hash_table_lookup (factory->medias, key);
|
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)
|
if (key)
|
||||||
g_free (key);
|
g_free (key);
|
||||||
|
|
|
@ -41,7 +41,7 @@ G_BEGIN_DECLS
|
||||||
typedef struct _GstRTSPMediaFactory GstRTSPMediaFactory;
|
typedef struct _GstRTSPMediaFactory GstRTSPMediaFactory;
|
||||||
typedef struct _GstRTSPMediaFactoryClass GstRTSPMediaFactoryClass;
|
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_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)))
|
#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.
|
* can contain multiple streams like audio and video.
|
||||||
*/
|
*/
|
||||||
struct _GstRTSPMediaFactory {
|
struct _GstRTSPMediaFactory {
|
||||||
GObject parent;
|
GObject parent;
|
||||||
|
|
||||||
GMutex *lock;
|
GMutex lock;
|
||||||
gchar *launch;
|
gchar *launch;
|
||||||
gboolean shared;
|
gboolean shared;
|
||||||
gboolean eos_shutdown;
|
gboolean eos_shutdown;
|
||||||
|
@ -73,7 +73,7 @@ struct _GstRTSPMediaFactory {
|
||||||
guint buffer_size;
|
guint buffer_size;
|
||||||
gchar *multicast_group;
|
gchar *multicast_group;
|
||||||
|
|
||||||
GMutex *medias_lock;
|
GMutex medias_lock;
|
||||||
GHashTable *medias;
|
GHashTable *medias;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,6 @@ static void
|
||||||
gst_rtsp_media_class_init (GstRTSPMediaClass * klass)
|
gst_rtsp_media_class_init (GstRTSPMediaClass * klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class;
|
GObjectClass *gobject_class;
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
gobject_class = G_OBJECT_CLASS (klass);
|
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");
|
GST_DEBUG_CATEGORY_INIT (rtsp_media_debug, "rtspmedia", 0, "GstRTSPMedia");
|
||||||
|
|
||||||
klass->thread = g_thread_create ((GThreadFunc) do_loop, klass, TRUE, &error);
|
klass->thread = g_thread_new ("Bus Thread", (GThreadFunc) do_loop, klass);
|
||||||
if (error != NULL) {
|
|
||||||
g_critical ("could not start bus thread: %s", error->message);
|
|
||||||
}
|
|
||||||
klass->handle_message = default_handle_message;
|
klass->handle_message = default_handle_message;
|
||||||
klass->unprepare = default_unprepare;
|
klass->unprepare = default_unprepare;
|
||||||
|
|
||||||
|
@ -153,8 +150,8 @@ static void
|
||||||
gst_rtsp_media_init (GstRTSPMedia * media)
|
gst_rtsp_media_init (GstRTSPMedia * media)
|
||||||
{
|
{
|
||||||
media->streams = g_array_new (FALSE, TRUE, sizeof (GstRTSPMediaStream *));
|
media->streams = g_array_new (FALSE, TRUE, sizeof (GstRTSPMediaStream *));
|
||||||
media->lock = g_mutex_new ();
|
g_mutex_init (&media->lock);
|
||||||
media->cond = g_cond_new ();
|
g_cond_init (&media->cond);
|
||||||
|
|
||||||
media->shared = DEFAULT_SHARED;
|
media->shared = DEFAULT_SHARED;
|
||||||
media->reusable = DEFAULT_REUSABLE;
|
media->reusable = DEFAULT_REUSABLE;
|
||||||
|
@ -235,8 +232,8 @@ gst_rtsp_media_finalize (GObject * obj)
|
||||||
g_source_unref (media->source);
|
g_source_unref (media->source);
|
||||||
}
|
}
|
||||||
g_free (media->multicast_group);
|
g_free (media->multicast_group);
|
||||||
g_mutex_free (media->lock);
|
g_mutex_clear (&media->lock);
|
||||||
g_cond_free (media->cond);
|
g_cond_clear (&media->cond);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gst_rtsp_media_parent_class)->finalize (obj);
|
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_return_if_fail (GST_IS_RTSP_MEDIA (media));
|
||||||
|
|
||||||
g_mutex_lock (media->lock);
|
g_mutex_lock (&media->lock);
|
||||||
g_free (media->multicast_group);
|
g_free (media->multicast_group);
|
||||||
media->multicast_group = g_strdup (mc);
|
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_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);
|
result = g_strdup (media->multicast_group);
|
||||||
g_mutex_unlock (media->lock);
|
g_mutex_unlock (&media->lock);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1445,28 +1442,27 @@ unlock_streams (GstRTSPMedia * media)
|
||||||
static void
|
static void
|
||||||
gst_rtsp_media_set_status (GstRTSPMedia * media, GstRTSPMediaStatus status)
|
gst_rtsp_media_set_status (GstRTSPMedia * media, GstRTSPMediaStatus status)
|
||||||
{
|
{
|
||||||
g_mutex_lock (media->lock);
|
g_mutex_lock (&media->lock);
|
||||||
/* never overwrite the error status */
|
/* never overwrite the error status */
|
||||||
if (media->status != GST_RTSP_MEDIA_STATUS_ERROR)
|
if (media->status != GST_RTSP_MEDIA_STATUS_ERROR)
|
||||||
media->status = status;
|
media->status = status;
|
||||||
GST_DEBUG ("setting new status to %d", status);
|
GST_DEBUG ("setting new status to %d", status);
|
||||||
g_cond_broadcast (media->cond);
|
g_cond_broadcast (&media->cond);
|
||||||
g_mutex_unlock (media->lock);
|
g_mutex_unlock (&media->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstRTSPMediaStatus
|
static GstRTSPMediaStatus
|
||||||
gst_rtsp_media_get_status (GstRTSPMedia * media)
|
gst_rtsp_media_get_status (GstRTSPMedia * media)
|
||||||
{
|
{
|
||||||
GstRTSPMediaStatus result;
|
GstRTSPMediaStatus result;
|
||||||
GTimeVal timeout;
|
gint64 end_time;
|
||||||
|
|
||||||
g_mutex_lock (media->lock);
|
g_mutex_lock (&media->lock);
|
||||||
g_get_current_time (&timeout);
|
end_time = g_get_monotonic_time () + 20 * G_TIME_SPAN_SECOND;
|
||||||
g_time_val_add (&timeout, 20 * G_USEC_PER_SEC);
|
|
||||||
/* while we are preparing, wait */
|
/* while we are preparing, wait */
|
||||||
while (media->status == GST_RTSP_MEDIA_STATUS_PREPARING) {
|
while (media->status == GST_RTSP_MEDIA_STATUS_PREPARING) {
|
||||||
GST_DEBUG ("waiting for status change");
|
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");
|
GST_DEBUG ("timeout, assuming error status");
|
||||||
media->status = GST_RTSP_MEDIA_STATUS_ERROR;
|
media->status = GST_RTSP_MEDIA_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -1474,7 +1470,7 @@ gst_rtsp_media_get_status (GstRTSPMedia * media)
|
||||||
/* could be success or error */
|
/* could be success or error */
|
||||||
result = media->status;
|
result = media->status;
|
||||||
GST_DEBUG ("got status %d", result);
|
GST_DEBUG ("got status %d", result);
|
||||||
g_mutex_unlock (media->lock);
|
g_mutex_unlock (&media->lock);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,8 +191,8 @@ typedef enum {
|
||||||
struct _GstRTSPMedia {
|
struct _GstRTSPMedia {
|
||||||
GObject parent;
|
GObject parent;
|
||||||
|
|
||||||
GMutex *lock;
|
GMutex lock;
|
||||||
GCond *cond;
|
GCond cond;
|
||||||
|
|
||||||
gboolean shared;
|
gboolean shared;
|
||||||
gboolean reusable;
|
gboolean reusable;
|
||||||
|
|
|
@ -164,7 +164,7 @@ gst_rtsp_server_class_init (GstRTSPServerClass * klass)
|
||||||
static void
|
static void
|
||||||
gst_rtsp_server_init (GstRTSPServer * server)
|
gst_rtsp_server_init (GstRTSPServer * server)
|
||||||
{
|
{
|
||||||
server->lock = g_mutex_new ();
|
g_mutex_init (&server->lock);
|
||||||
server->address = g_strdup (DEFAULT_ADDRESS);
|
server->address = g_strdup (DEFAULT_ADDRESS);
|
||||||
server->service = g_strdup (DEFAULT_SERVICE);
|
server->service = g_strdup (DEFAULT_SERVICE);
|
||||||
server->backlog = DEFAULT_BACKLOG;
|
server->backlog = DEFAULT_BACKLOG;
|
||||||
|
@ -188,7 +188,7 @@ gst_rtsp_server_finalize (GObject * object)
|
||||||
if (server->auth)
|
if (server->auth)
|
||||||
g_object_unref (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);
|
G_OBJECT_CLASS (gst_rtsp_server_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ typedef struct _GstRTSPServerClass GstRTSPServerClass;
|
||||||
#define GST_RTSP_SERVER_CAST(obj) ((GstRTSPServer*)(obj))
|
#define GST_RTSP_SERVER_CAST(obj) ((GstRTSPServer*)(obj))
|
||||||
#define GST_RTSP_SERVER_CLASS_CAST(klass) ((GstRTSPServerClass*)(klass))
|
#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_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)))
|
#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 {
|
struct _GstRTSPServer {
|
||||||
GObject parent;
|
GObject parent;
|
||||||
|
|
||||||
GMutex *lock;
|
GMutex lock;
|
||||||
|
|
||||||
/* server information */
|
/* server information */
|
||||||
gchar *address;
|
gchar *address;
|
||||||
|
|
|
@ -77,7 +77,7 @@ gst_rtsp_session_pool_class_init (GstRTSPSessionPoolClass * klass)
|
||||||
static void
|
static void
|
||||||
gst_rtsp_session_pool_init (GstRTSPSessionPool * pool)
|
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,
|
pool->sessions = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
NULL, g_object_unref);
|
NULL, g_object_unref);
|
||||||
pool->max_sessions = DEFAULT_MAX_SESSIONS;
|
pool->max_sessions = DEFAULT_MAX_SESSIONS;
|
||||||
|
@ -88,7 +88,7 @@ gst_rtsp_session_pool_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
GstRTSPSessionPool *pool = GST_RTSP_SESSION_POOL (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_hash_table_unref (pool->sessions);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gst_rtsp_session_pool_parent_class)->finalize (object);
|
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_return_if_fail (GST_IS_RTSP_SESSION_POOL (pool));
|
||||||
|
|
||||||
g_mutex_lock (pool->lock);
|
g_mutex_lock (&pool->lock);
|
||||||
pool->max_sessions = max;
|
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_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;
|
result = pool->max_sessions;
|
||||||
g_mutex_unlock (pool->lock);
|
g_mutex_unlock (&pool->lock);
|
||||||
|
|
||||||
return result;
|
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_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);
|
result = g_hash_table_size (pool->sessions);
|
||||||
g_mutex_unlock (pool->lock);
|
g_mutex_unlock (&pool->lock);
|
||||||
|
|
||||||
return result;
|
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 (GST_IS_RTSP_SESSION_POOL (pool), NULL);
|
||||||
g_return_val_if_fail (sessionid != NULL, 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);
|
result = g_hash_table_lookup (pool->sessions, sessionid);
|
||||||
if (result) {
|
if (result) {
|
||||||
g_object_ref (result);
|
g_object_ref (result);
|
||||||
gst_rtsp_session_touch (result);
|
gst_rtsp_session_touch (result);
|
||||||
}
|
}
|
||||||
g_mutex_unlock (pool->lock);
|
g_mutex_unlock (&pool->lock);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ gst_rtsp_session_pool_create (GstRTSPSessionPool * pool)
|
||||||
if (id == NULL)
|
if (id == NULL)
|
||||||
goto no_session;
|
goto no_session;
|
||||||
|
|
||||||
g_mutex_lock (pool->lock);
|
g_mutex_lock (&pool->lock);
|
||||||
/* check session limit */
|
/* check session limit */
|
||||||
if (pool->max_sessions > 0) {
|
if (pool->max_sessions > 0) {
|
||||||
if (g_hash_table_size (pool->sessions) >= pool->max_sessions)
|
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_object_ref (result);
|
||||||
g_hash_table_insert (pool->sessions, result->sessionid, result);
|
g_hash_table_insert (pool->sessions, result->sessionid, result);
|
||||||
}
|
}
|
||||||
g_mutex_unlock (pool->lock);
|
g_mutex_unlock (&pool->lock);
|
||||||
|
|
||||||
g_free (id);
|
g_free (id);
|
||||||
} while (result == NULL);
|
} while (result == NULL);
|
||||||
|
@ -325,14 +325,14 @@ no_session:
|
||||||
collision:
|
collision:
|
||||||
{
|
{
|
||||||
GST_WARNING ("can't find unique sessionid for GstRTSPSessionPool %p", pool);
|
GST_WARNING ("can't find unique sessionid for GstRTSPSessionPool %p", pool);
|
||||||
g_mutex_unlock (pool->lock);
|
g_mutex_unlock (&pool->lock);
|
||||||
g_free (id);
|
g_free (id);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
too_many_sessions:
|
too_many_sessions:
|
||||||
{
|
{
|
||||||
GST_WARNING ("session pool reached max sessions of %d", pool->max_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);
|
g_free (id);
|
||||||
return NULL;
|
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_POOL (pool), FALSE);
|
||||||
g_return_val_if_fail (GST_IS_RTSP_SESSION (sess), 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);
|
found = g_hash_table_remove (pool->sessions, sess->sessionid);
|
||||||
g_mutex_unlock (pool->lock);
|
g_mutex_unlock (&pool->lock);
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
@ -387,11 +387,11 @@ gst_rtsp_session_pool_cleanup (GstRTSPSessionPool * pool)
|
||||||
|
|
||||||
g_get_current_time (&now);
|
g_get_current_time (&now);
|
||||||
|
|
||||||
g_mutex_lock (pool->lock);
|
g_mutex_lock (&pool->lock);
|
||||||
result =
|
result =
|
||||||
g_hash_table_foreach_remove (pool->sessions, (GHRFunc) cleanup_func,
|
g_hash_table_foreach_remove (pool->sessions, (GHRFunc) cleanup_func,
|
||||||
&now);
|
&now);
|
||||||
g_mutex_unlock (pool->lock);
|
g_mutex_unlock (&pool->lock);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -457,9 +457,9 @@ gst_rtsp_session_pool_filter (GstRTSPSessionPool * pool,
|
||||||
data.user_data = user_data;
|
data.user_data = user_data;
|
||||||
data.list = NULL;
|
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_hash_table_foreach_remove (pool->sessions, (GHRFunc) filter_func, &data);
|
||||||
g_mutex_unlock (pool->lock);
|
g_mutex_unlock (&pool->lock);
|
||||||
|
|
||||||
return data.list;
|
return data.list;
|
||||||
}
|
}
|
||||||
|
@ -497,9 +497,9 @@ gst_pool_source_prepare (GSource * source, gint * timeout)
|
||||||
psrc = (GstPoolSource *) source;
|
psrc = (GstPoolSource *) source;
|
||||||
psrc->timeout = -1;
|
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_hash_table_foreach (psrc->pool->sessions, (GHFunc) collect_timeout, psrc);
|
||||||
g_mutex_unlock (psrc->pool->lock);
|
g_mutex_unlock (&psrc->pool->lock);
|
||||||
|
|
||||||
if (timeout)
|
if (timeout)
|
||||||
*timeout = psrc->timeout;
|
*timeout = psrc->timeout;
|
||||||
|
|
|
@ -53,7 +53,7 @@ struct _GstRTSPSessionPool {
|
||||||
|
|
||||||
guint max_sessions;
|
guint max_sessions;
|
||||||
|
|
||||||
GMutex *lock;
|
GMutex lock;
|
||||||
GHashTable *sessions;
|
GHashTable *sessions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue