Commit 1f084193 authored by Philip Withnall's avatar Philip Withnall

agent: Turn Stream into a GObject

This makes it reference-counted. This will be useful for allowing
GDatagramBased and GIOStream objects to hold references to the stream
and component they are interested in, allowing removal of the global
NiceAgent lock previously needed to look up the component for every I/O
operation.

It also means that nice_stream_close() could eventually become
asynchronous, which would fix a few race conditions.
Reviewed-by: default avatarOlivier Crête <olivier.crete@collabora.com>
Differential Revision: https://phabricator.freedesktop.org/D306
parent da707161
......@@ -48,6 +48,11 @@
static volatile unsigned int n_streams_created = 0;
static volatile unsigned int n_streams_destroyed = 0;
G_DEFINE_TYPE (NiceStream, nice_stream, G_TYPE_OBJECT);
static void
nice_stream_finalize (GObject *obj);
/*
* @file stream.c
* @brief ICE stream functionality
......@@ -55,22 +60,20 @@ static volatile unsigned int n_streams_destroyed = 0;
Stream *
stream_new (guint n_components, NiceAgent *agent)
{
Stream *stream;
NiceStream *stream = NULL;
guint n;
Component *component;
g_atomic_int_inc (&n_streams_created);
nice_debug ("Created NiceStream (%u created, %u destroyed)",
n_streams_created, n_streams_destroyed);
stream = g_object_new (NICE_TYPE_STREAM, NULL);
stream = g_slice_new0 (Stream);
/* Create the components. */
for (n = 0; n < n_components; n++) {
Component *component = NULL;
component = component_new (n + 1, agent, stream);
stream->components = g_slist_append (stream->components, component);
}
stream->n_components = n_components;
stream->initial_binding_request_received = FALSE;
return stream;
}
......@@ -89,13 +92,7 @@ stream_close (Stream *stream)
void
stream_free (Stream *stream)
{
g_free (stream->name);
g_slist_free_full (stream->components, (GDestroyNotify) component_free);
g_slice_free (Stream, stream);
g_atomic_int_inc (&n_streams_destroyed);
nice_debug ("Destroyed NiceStream (%u created, %u destroyed)",
n_streams_created, n_streams_destroyed);
g_object_unref (stream);
}
Component *
......@@ -167,3 +164,40 @@ stream_restart (NiceAgent *agent, Stream *stream)
}
}
static void
nice_stream_class_init (NiceStreamClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = nice_stream_finalize;
}
static void
nice_stream_init (NiceStream *stream)
{
g_atomic_int_inc (&n_streams_created);
nice_debug ("Created NiceStream (%u created, %u destroyed)",
n_streams_created, n_streams_destroyed);
stream->n_components = 0;
stream->initial_binding_request_received = FALSE;
}
/* Must be called with the agent lock released as it could dispose of
* NiceIOStreams. */
static void
nice_stream_finalize (GObject *obj)
{
NiceStream *stream;
stream = NICE_STREAM (obj);
g_free (stream->name);
g_slist_free_full (stream->components, (GDestroyNotify) component_free);
g_atomic_int_inc (&n_streams_destroyed);
nice_debug ("Destroyed NiceStream (%u created, %u destroyed)",
n_streams_created, n_streams_destroyed);
G_OBJECT_CLASS (nice_stream_parent_class)->finalize (obj);
}
......@@ -42,7 +42,8 @@
#include <glib.h>
typedef struct _Stream Stream;
typedef struct _Stream Stream G_GNUC_DEPRECATED_FOR(NiceStream);
typedef Stream NiceStream;
#include "component.h"
#include "random.h"
......@@ -59,8 +60,23 @@ G_BEGIN_DECLS
#define NICE_STREAM_DEF_UFRAG 4 + 1 /* ufrag + NULL */
#define NICE_STREAM_DEF_PWD 22 + 1 /* pwd + NULL */
#define NICE_TYPE_STREAM nice_stream_get_type()
#define NICE_STREAM(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), NICE_TYPE_STREAM, NiceStream))
#define NICE_STREAM_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), NICE_TYPE_STREAM, NiceStreamClass))
#define NICE_IS_STREAM(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), NICE_TYPE_STREAM))
#define NICE_IS_STREAM_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), NICE_TYPE_STREAM))
#define NICE_STREAM_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), NICE_TYPE_STREAM, NiceStreamClass))
struct _Stream
{
/*< private >*/
GObject parent;
gchar *name;
guint id;
guint n_components;
......@@ -76,25 +92,37 @@ struct _Stream
gint tos;
};
typedef struct {
GObjectClass parent_class;
} NiceStreamClass;
GType nice_stream_get_type (void);
G_DEPRECATED
Stream *
stream_new (guint n_components, NiceAgent *agent);
G_DEPRECATED
void
stream_close (Stream *stream);
G_DEPRECATED_FOR(g_object_unref)
void
stream_free (Stream *stream);
G_DEPRECATED
gboolean
stream_all_components_ready (const Stream *stream);
G_DEPRECATED
Component *
stream_find_component_by_id (const Stream *stream, guint id);
G_DEPRECATED
void
stream_initialize_credentials (Stream *stream, NiceRNG *rng);
G_DEPRECATED
void
stream_restart (NiceAgent *agent, Stream *stream);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment