[farsight2/master] Remove references to STUN from the multicast transmitter
Olivier Crête
olivier.crete at collabora.co.uk
Tue Dec 23 15:20:59 PST 2008
---
.../multicast/fs-multicast-stream-transmitter.c | 591 +++-----------------
1 files changed, 81 insertions(+), 510 deletions(-)
diff --git a/transmitters/multicast/fs-multicast-stream-transmitter.c b/transmitters/multicast/fs-multicast-stream-transmitter.c
index 7cedb48..98a6a05 100644
--- a/transmitters/multicast/fs-multicast-stream-transmitter.c
+++ b/transmitters/multicast/fs-multicast-stream-transmitter.c
@@ -5,7 +5,7 @@
* @author: Olivier Crete <olivier.crete at collabora.co.uk>
* Copyright 2007 Nokia Corp.
*
- * fs-rawudp-transmitter.c - A Farsight Multiast UDP stream transmitter
+ * fs-multicast-transmitter.c - A Farsight Multiast UDP stream transmitter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -34,9 +34,6 @@
#include "config.h"
#endif
-#include "fs-rawudp-stream-transmitter.h"
-
-#include "stun.h"
#include "fs-interfaces.h"
#include <gst/farsight/fs-candidate.h>
@@ -52,8 +49,8 @@
#include <netdb.h>
#include <unistd.h>
-GST_DEBUG_CATEGORY_EXTERN (fs_rawudp_transmitter_debug);
-#define GST_CAT_DEFAULT fs_rawudp_transmitter_debug
+GST_DEBUG_CATEGORY_EXTERN (fs_multicast_transmitter_debug);
+#define GST_CAT_DEFAULT fs_multicast_transmitter_debug
/* Signals */
enum
@@ -66,13 +63,10 @@ enum
{
PROP_0,
PROP_SENDING,
- PROP_PREFERED_LOCAL_CANDIDATES,
- PROP_STUN_IP,
- PROP_STUN_PORT,
- PROP_STUN_TIMEOUT
+ PROP_PREFERED_LOCAL_CANDIDATES
};
-struct _FsRawUdpStreamTransmitterPrivate
+struct _FsMulticastStreamTransmitterPrivate
{
gboolean disposed;
@@ -80,7 +74,7 @@ struct _FsRawUdpStreamTransmitterPrivate
* But since our parent FsStream can not exist without its parent
* FsSession, we should be safe
*/
- FsRawUdpTransmitter *transmitter;
+ FsMulticastTransmitter *transmitter;
gboolean sending;
@@ -90,23 +84,10 @@ struct _FsRawUdpStreamTransmitterPrivate
FsCandidate **remote_candidate;
FsCandidate **local_forced_candidate;
- FsCandidate **local_stun_candidate;
FsCandidate **local_active_candidate;
UdpPort **udpports;
- gchar *stun_ip;
- guint stun_port;
- guint stun_timeout;
-
- /* These are protected by the sources_mutex too
- * And there is one per component (+1)
- */
- gulong *stun_recv_id;
- guint *stun_timeout_id;
-
- gchar stun_cookie[16];
-
GList *prefered_local_candidates;
guint next_candidate_id;
@@ -115,43 +96,36 @@ struct _FsRawUdpStreamTransmitterPrivate
GList *sources;
};
-#define FS_RAWUDP_STREAM_TRANSMITTER_GET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), FS_TYPE_RAWUDP_STREAM_TRANSMITTER, \
- FsRawUdpStreamTransmitterPrivate))
+#define FS_MULTICAST_STREAM_TRANSMITTER_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), FS_TYPE_MULTICAST_STREAM_TRANSMITTER, \
+ FsMulticastStreamTransmitterPrivate))
-static void fs_rawudp_stream_transmitter_class_init (FsRawUdpStreamTransmitterClass *klass);
-static void fs_rawudp_stream_transmitter_init (FsRawUdpStreamTransmitter *self);
-static void fs_rawudp_stream_transmitter_dispose (GObject *object);
-static void fs_rawudp_stream_transmitter_finalize (GObject *object);
+static void fs_multicast_stream_transmitter_class_init (FsMulticastStreamTransmitterClass *klass);
+static void fs_multicast_stream_transmitter_init (FsMulticastStreamTransmitter *self);
+static void fs_multicast_stream_transmitter_dispose (GObject *object);
+static void fs_multicast_stream_transmitter_finalize (GObject *object);
-static void fs_rawudp_stream_transmitter_get_property (GObject *object,
+static void fs_multicast_stream_transmitter_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
-static void fs_rawudp_stream_transmitter_set_property (GObject *object,
+static void fs_multicast_stream_transmitter_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
-static gboolean fs_rawudp_stream_transmitter_add_remote_candidate (
+static gboolean fs_multicast_stream_transmitter_add_remote_candidate (
FsStreamTransmitter *streamtransmitter, FsCandidate *candidate,
GError **error);
-static gboolean fs_rawudp_stream_transmitter_start_stun (
- FsRawUdpStreamTransmitter *self, guint component_id, GError **error);
-static void fs_rawudp_stream_transmitter_stop_stun (
- FsRawUdpStreamTransmitter *self, guint component_id);
-
-static FsCandidate * fs_rawudp_stream_transmitter_build_forced_candidate (
- FsRawUdpStreamTransmitter *self, const char *ip, gint port,
+static FsCandidate * fs_multicast_stream_transmitter_build_forced_candidate (
+ FsMulticastStreamTransmitter *self, const char *ip, gint port,
guint component_id);
-static gboolean fs_rawudp_stream_transmitter_no_stun (
- gpointer user_data);
-static void fs_rawudp_stream_transmitter_maybe_new_active_candidate_pair (
- FsRawUdpStreamTransmitter *self, guint component_id);
+static void fs_multicast_stream_transmitter_maybe_new_active_candidate_pair (
+ FsMulticastStreamTransmitter *self, guint component_id);
static gboolean
-fs_rawudp_stream_transmitter_emit_local_candidates (
- FsRawUdpStreamTransmitter *self, guint component_id);
+fs_multicast_stream_transmitter_emit_local_candidates (
+ FsMulticastStreamTransmitter *self, guint component_id);
static GObjectClass *parent_class = NULL;
@@ -160,34 +134,34 @@ static GObjectClass *parent_class = NULL;
static GType type = 0;
GType
-fs_rawudp_stream_transmitter_get_type (void)
+fs_multicast_stream_transmitter_get_type (void)
{
return type;
}
GType
-fs_rawudp_stream_transmitter_register_type (FsPlugin *module)
+fs_multicast_stream_transmitter_register_type (FsPlugin *module)
{
static const GTypeInfo info = {
- sizeof (FsRawUdpStreamTransmitterClass),
+ sizeof (FsMulticastStreamTransmitterClass),
NULL,
NULL,
- (GClassInitFunc) fs_rawudp_stream_transmitter_class_init,
+ (GClassInitFunc) fs_multicast_stream_transmitter_class_init,
NULL,
NULL,
- sizeof (FsRawUdpStreamTransmitter),
+ sizeof (FsMulticastStreamTransmitter),
0,
- (GInstanceInitFunc) fs_rawudp_stream_transmitter_init
+ (GInstanceInitFunc) fs_multicast_stream_transmitter_init
};
type = g_type_module_register_type (G_TYPE_MODULE (module),
- FS_TYPE_STREAM_TRANSMITTER, "FsRawUdpStreamTransmitter", &info, 0);
+ FS_TYPE_STREAM_TRANSMITTER, "FsMulticastStreamTransmitter", &info, 0);
return type;
}
static void
-fs_rawudp_stream_transmitter_class_init (FsRawUdpStreamTransmitterClass *klass)
+fs_multicast_stream_transmitter_class_init (FsMulticastStreamTransmitterClass *klass)
{
GObjectClass *gobject_class = (GObjectClass *) klass;
FsStreamTransmitterClass *streamtransmitterclass =
@@ -195,68 +169,38 @@ fs_rawudp_stream_transmitter_class_init (FsRawUdpStreamTransmitterClass *klass)
parent_class = g_type_class_peek_parent (klass);
- gobject_class->set_property = fs_rawudp_stream_transmitter_set_property;
- gobject_class->get_property = fs_rawudp_stream_transmitter_get_property;
+ gobject_class->set_property = fs_multicast_stream_transmitter_set_property;
+ gobject_class->get_property = fs_multicast_stream_transmitter_get_property;
streamtransmitterclass->add_remote_candidate =
- fs_rawudp_stream_transmitter_add_remote_candidate;
+ fs_multicast_stream_transmitter_add_remote_candidate;
g_object_class_override_property (gobject_class, PROP_SENDING, "sending");
g_object_class_override_property (gobject_class,
PROP_PREFERED_LOCAL_CANDIDATES, "prefered-local-candidates");
- g_object_class_install_property (gobject_class,
- PROP_STUN_IP,
- g_param_spec_string ("stun-ip",
- "The IP address of the STUN server",
- "The IPv4 address of the STUN server as a x.x.x.x string",
- NULL,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class,
- PROP_STUN_PORT,
- g_param_spec_uint ("stun-port",
- "The port of the STUN server",
- "The IPv4 UDP port of the STUN server as a ",
- 1, 65535, 3478,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class,
- PROP_STUN_TIMEOUT,
- g_param_spec_uint ("stun-timeout",
- "The timeout for the STUN reply",
- "How long to wait for for the STUN reply (in seconds) before giving up",
- 1, G_MAXUINT, 30,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
-
- gobject_class->dispose = fs_rawudp_stream_transmitter_dispose;
- gobject_class->finalize = fs_rawudp_stream_transmitter_finalize;
-
- g_type_class_add_private (klass, sizeof (FsRawUdpStreamTransmitterPrivate));
+ gobject_class->dispose = fs_multicast_stream_transmitter_dispose;
+ gobject_class->finalize = fs_multicast_stream_transmitter_finalize;
+
+ g_type_class_add_private (klass, sizeof (FsMulticastStreamTransmitterPrivate));
}
static void
-fs_rawudp_stream_transmitter_init (FsRawUdpStreamTransmitter *self)
+fs_multicast_stream_transmitter_init (FsMulticastStreamTransmitter *self)
{
/* member init */
- self->priv = FS_RAWUDP_STREAM_TRANSMITTER_GET_PRIVATE (self);
+ self->priv = FS_MULTICAST_STREAM_TRANSMITTER_GET_PRIVATE (self);
self->priv->disposed = FALSE;
self->priv->sending = TRUE;
- /* Use a pseudo-random number for the STUN cookie */
- ((guint32*)self->priv->stun_cookie)[0] = g_random_int ();
- ((guint32*)self->priv->stun_cookie)[1] = g_random_int ();
- ((guint32*)self->priv->stun_cookie)[2] = g_random_int ();
- ((guint32*)self->priv->stun_cookie)[3] = g_random_int ();
-
self->priv->sources_mutex = g_mutex_new ();
}
static void
-fs_rawudp_stream_transmitter_dispose (GObject *object)
+fs_multicast_stream_transmitter_dispose (GObject *object)
{
- FsRawUdpStreamTransmitter *self = FS_RAWUDP_STREAM_TRANSMITTER (object);
+ FsMulticastStreamTransmitter *self = FS_MULTICAST_STREAM_TRANSMITTER (object);
gint c;
if (self->priv->disposed) {
@@ -266,14 +210,6 @@ fs_rawudp_stream_transmitter_dispose (GObject *object)
g_mutex_lock (self->priv->sources_mutex);
- if (self->priv->stun_recv_id) {
- for (c = 1; c <= self->priv->transmitter->components; c++) {
- if (self->priv->stun_recv_id[c]) {
- fs_rawudp_stream_transmitter_stop_stun (self, c);
- }
- }
- }
-
if (self->priv->sources) {
g_list_foreach (self->priv->sources, (GFunc) g_source_remove, NULL);
g_list_free (self->priv->sources);
@@ -289,16 +225,11 @@ fs_rawudp_stream_transmitter_dispose (GObject *object)
}
static void
-fs_rawudp_stream_transmitter_finalize (GObject *object)
+fs_multicast_stream_transmitter_finalize (GObject *object)
{
- FsRawUdpStreamTransmitter *self = FS_RAWUDP_STREAM_TRANSMITTER (object);
+ FsMulticastStreamTransmitter *self = FS_MULTICAST_STREAM_TRANSMITTER (object);
gint c; /* component_id */
- if (self->priv->stun_ip) {
- g_free (self->priv->stun_ip);
- self->priv->stun_ip = NULL;
- }
-
if (self->priv->prefered_local_candidates) {
fs_candidate_list_destroy (self->priv->prefered_local_candidates);
self->priv->prefered_local_candidates = NULL;
@@ -309,7 +240,7 @@ fs_rawudp_stream_transmitter_finalize (GObject *object)
if (self->priv->remote_candidate[c]) {
if (self->priv->udpports && self->priv->udpports[c] &&
self->priv->sending)
- fs_rawudp_transmitter_udpport_remove_dest (self->priv->udpports[c],
+ fs_multicast_transmitter_udpport_remove_dest (self->priv->udpports[c],
self->priv->remote_candidate[c]->ip,
self->priv->remote_candidate[c]->port);
fs_candidate_destroy (self->priv->remote_candidate[c]);
@@ -323,7 +254,7 @@ fs_rawudp_stream_transmitter_finalize (GObject *object)
if (self->priv->udpports) {
for (c = 1; c <= self->priv->transmitter->components; c++) {
if (self->priv->udpports[c]) {
- fs_rawudp_transmitter_put_udpport (self->priv->transmitter,
+ fs_multicast_transmitter_put_udpport (self->priv->transmitter,
self->priv->udpports[c]);
self->priv->udpports[c] = NULL;
}
@@ -344,17 +275,6 @@ fs_rawudp_stream_transmitter_finalize (GObject *object)
self->priv->local_forced_candidate = NULL;
}
- if (self->priv->local_stun_candidate) {
- for (c = 1; c <= self->priv->transmitter->components; c++) {
- if (self->priv->local_stun_candidate[c]) {
- fs_candidate_destroy (self->priv->local_stun_candidate[c]);
- self->priv->local_stun_candidate[c] = NULL;
- }
- }
- g_free (self->priv->local_stun_candidate);
- self->priv->local_stun_candidate = NULL;
- }
-
if (self->priv->local_active_candidate) {
for (c = 1; c <= self->priv->transmitter->components; c++) {
if (self->priv->local_active_candidate[c]) {
@@ -371,26 +291,16 @@ fs_rawudp_stream_transmitter_finalize (GObject *object)
self->priv->sources_mutex = NULL;
}
- if (self->priv->stun_recv_id) {
- g_free (self->priv->stun_recv_id);
- self->priv->stun_recv_id = NULL;
- }
-
- if (self->priv->stun_timeout_id) {
- g_free (self->priv->stun_timeout_id);
- self->priv->stun_timeout_id = NULL;
- }
-
parent_class->finalize (object);
}
static void
-fs_rawudp_stream_transmitter_get_property (GObject *object,
+fs_multicast_stream_transmitter_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
- FsRawUdpStreamTransmitter *self = FS_RAWUDP_STREAM_TRANSMITTER (object);
+ FsMulticastStreamTransmitter *self = FS_MULTICAST_STREAM_TRANSMITTER (object);
switch (prop_id) {
case PROP_SENDING:
@@ -399,15 +309,6 @@ fs_rawudp_stream_transmitter_get_property (GObject *object,
case PROP_PREFERED_LOCAL_CANDIDATES:
g_value_set_boxed (value, self->priv->prefered_local_candidates);
break;
- case PROP_STUN_IP:
- g_value_set_string (value, self->priv->stun_ip);
- break;
- case PROP_STUN_PORT:
- g_value_set_uint (value, self->priv->stun_port);
- break;
- case PROP_STUN_TIMEOUT:
- g_value_set_uint (value, self->priv->stun_timeout);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -415,12 +316,12 @@ fs_rawudp_stream_transmitter_get_property (GObject *object,
}
static void
-fs_rawudp_stream_transmitter_set_property (GObject *object,
+fs_multicast_stream_transmitter_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
- FsRawUdpStreamTransmitter *self = FS_RAWUDP_STREAM_TRANSMITTER (object);
+ FsMulticastStreamTransmitter *self = FS_MULTICAST_STREAM_TRANSMITTER (object);
switch (prop_id) {
case PROP_SENDING:
@@ -435,7 +336,7 @@ fs_rawudp_stream_transmitter_set_property (GObject *object,
for (c = 1; c <= self->priv->transmitter->components; c++)
if (self->priv->remote_candidate[c])
- fs_rawudp_transmitter_udpport_add_dest (
+ fs_multicast_transmitter_udpport_add_dest (
self->priv->udpports[c],
self->priv->remote_candidate[c]->ip,
self->priv->remote_candidate[c]->port);
@@ -443,7 +344,7 @@ fs_rawudp_stream_transmitter_set_property (GObject *object,
for (c = 1; c <= self->priv->transmitter->components; c++)
if (self->priv->remote_candidate[c])
- fs_rawudp_transmitter_udpport_remove_dest (
+ fs_multicast_transmitter_udpport_remove_dest (
self->priv->udpports[c],
self->priv->remote_candidate[c]->ip,
self->priv->remote_candidate[c]->port);
@@ -454,16 +355,6 @@ fs_rawudp_stream_transmitter_set_property (GObject *object,
case PROP_PREFERED_LOCAL_CANDIDATES:
self->priv->prefered_local_candidates = g_value_dup_boxed (value);
break;
- case PROP_STUN_IP:
- g_free (self->priv->stun_ip);
- self->priv->stun_ip = g_value_dup_string (value);
- break;
- case PROP_STUN_PORT:
- self->priv->stun_port = g_value_get_uint (value);
- break;
- case PROP_STUN_TIMEOUT:
- self->priv->stun_timeout = g_value_get_uint (value);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -471,7 +362,7 @@ fs_rawudp_stream_transmitter_set_property (GObject *object,
}
static gboolean
-fs_rawudp_stream_transmitter_build (FsRawUdpStreamTransmitter *self,
+fs_multicast_stream_transmitter_build (FsMulticastStreamTransmitter *self,
GError **error)
{
const gchar **ips = g_new0 (const gchar *,
@@ -488,14 +379,8 @@ fs_rawudp_stream_transmitter_build (FsRawUdpStreamTransmitter *self,
self->priv->transmitter->components + 1);
self->priv->local_forced_candidate = g_new0 (FsCandidate *,
self->priv->transmitter->components + 1);
- self->priv->local_stun_candidate = g_new0 (FsCandidate *,
- self->priv->transmitter->components + 1);
self->priv->local_active_candidate = g_new0 (FsCandidate *,
self->priv->transmitter->components + 1);
- self->priv->stun_recv_id = g_new0 (gulong,
- self->priv->transmitter->components + 1);
- self->priv->stun_timeout_id = g_new0 (guint,
- self->priv->transmitter->components + 1);
for (item = g_list_first (self->priv->prefered_local_candidates);
item;
@@ -556,12 +441,12 @@ fs_rawudp_stream_transmitter_build (FsRawUdpStreamTransmitter *self,
requested_port = next_port;
self->priv->udpports[c] =
- fs_rawudp_transmitter_get_udpport (self->priv->transmitter, c, ips[c],
+ fs_multicast_transmitter_get_udpport (self->priv->transmitter, c, ips[c],
requested_port, error);
if (!self->priv->udpports[c])
goto error;
- used_port = fs_rawudp_transmitter_udpport_get_port (self->priv->udpports[c]);
+ used_port = fs_multicast_transmitter_udpport_get_port (self->priv->udpports[c]);
/* If we dont get the requested port and it wasnt a forced port,
* then we rewind up to the last forced port and jump to the next
@@ -570,7 +455,7 @@ fs_rawudp_stream_transmitter_build (FsRawUdpStreamTransmitter *self,
if (used_port != requested_port && !ports[c]) {
do {
- fs_rawudp_transmitter_put_udpport (self->priv->transmitter,
+ fs_multicast_transmitter_put_udpport (self->priv->transmitter,
self->priv->udpports[c]);
self->priv->udpports[c] = NULL;
@@ -588,26 +473,12 @@ fs_rawudp_stream_transmitter_build (FsRawUdpStreamTransmitter *self,
if (ips[c])
self->priv->local_forced_candidate[c] =
- fs_rawudp_stream_transmitter_build_forced_candidate (self, ips[c],
+ fs_multicast_stream_transmitter_build_forced_candidate (self, ips[c],
used_port, c);
next_port = used_port+1;
}
- if (self->priv->stun_ip && self->priv->stun_port) {
- for (c = 1; c <= self->priv->transmitter->components; c++)
- if (!fs_rawudp_stream_transmitter_start_stun (self, c, error))
- goto error;
- } else {
- guint id;
- id = g_idle_add (fs_rawudp_stream_transmitter_no_stun, self);
- g_assert (id);
- g_mutex_lock (self->priv->sources_mutex);
- self->priv->sources = g_list_prepend (self->priv->sources,
- GUINT_TO_POINTER(id));
- g_mutex_unlock (self->priv->sources_mutex);
- }
-
g_free (ips);
g_free (ports);
@@ -621,7 +492,7 @@ fs_rawudp_stream_transmitter_build (FsRawUdpStreamTransmitter *self,
}
/**
- * fs_rawudp_stream_transmitter_add_remote_candidate
+ * fs_multicast_stream_transmitter_add_remote_candidate
* @streamtransmitter: a #FsStreamTransmitter
* @candidate: a remote #FsCandidate to add
* @error: location of a #GError, or NULL if no error occured
@@ -633,12 +504,12 @@ fs_rawudp_stream_transmitter_build (FsRawUdpStreamTransmitter *self,
*/
static gboolean
-fs_rawudp_stream_transmitter_add_remote_candidate (
+fs_multicast_stream_transmitter_add_remote_candidate (
FsStreamTransmitter *streamtransmitter, FsCandidate *candidate,
GError **error)
{
- FsRawUdpStreamTransmitter *self =
- FS_RAWUDP_STREAM_TRANSMITTER (streamtransmitter);
+ FsMulticastStreamTransmitter *self =
+ FS_MULTICAST_STREAM_TRANSMITTER (streamtransmitter);
if (candidate->proto != FS_NETWORK_PROTOCOL_UDP) {
g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
@@ -666,12 +537,12 @@ fs_rawudp_stream_transmitter_add_remote_candidate (
* has the format x.x.x.x where x is [0,255] using GRegex, etc
*/
if (self->priv->sending) {
- fs_rawudp_transmitter_udpport_add_dest (
+ fs_multicast_transmitter_udpport_add_dest (
self->priv->udpports[candidate->component_id],
candidate->ip, candidate->port);
}
if (self->priv->remote_candidate[candidate->component_id]) {
- fs_rawudp_transmitter_udpport_remove_dest (
+ fs_multicast_transmitter_udpport_remove_dest (
self->priv->udpports[candidate->component_id],
self->priv->remote_candidate[candidate->component_id]->ip,
self->priv->remote_candidate[candidate->component_id]->port);
@@ -681,20 +552,20 @@ fs_rawudp_stream_transmitter_add_remote_candidate (
self->priv->remote_candidate[candidate->component_id] =
fs_candidate_copy (candidate);
- fs_rawudp_stream_transmitter_maybe_new_active_candidate_pair (self,
+ fs_multicast_stream_transmitter_maybe_new_active_candidate_pair (self,
candidate->component_id);
return TRUE;
}
-FsRawUdpStreamTransmitter *
-fs_rawudp_stream_transmitter_newv (FsRawUdpTransmitter *transmitter,
+FsMulticastStreamTransmitter *
+fs_multicast_stream_transmitter_newv (FsMulticastTransmitter *transmitter,
guint n_parameters, GParameter *parameters, GError **error)
{
- FsRawUdpStreamTransmitter *streamtransmitter = NULL;
+ FsMulticastStreamTransmitter *streamtransmitter = NULL;
- streamtransmitter = g_object_newv (FS_TYPE_RAWUDP_STREAM_TRANSMITTER,
+ streamtransmitter = g_object_newv (FS_TYPE_MULTICAST_STREAM_TRANSMITTER,
n_parameters, parameters);
if (!streamtransmitter) {
@@ -705,7 +576,7 @@ fs_rawudp_stream_transmitter_newv (FsRawUdpTransmitter *transmitter,
streamtransmitter->priv->transmitter = transmitter;
- if (!fs_rawudp_stream_transmitter_build (streamtransmitter, error)) {
+ if (!fs_multicast_stream_transmitter_build (streamtransmitter, error)) {
g_object_unref (streamtransmitter);
return NULL;
}
@@ -714,310 +585,14 @@ fs_rawudp_stream_transmitter_newv (FsRawUdpTransmitter *transmitter,
}
struct CandidateTransit {
- FsRawUdpStreamTransmitter *self;
+ FsMulticastStreamTransmitter *self;
FsCandidate *candidate;
guint component_id;
};
-static gboolean
-fs_rawudp_stream_transmitter_emit_stun_candidate (gpointer user_data)
-{
- struct CandidateTransit *data = user_data;
- gboolean all_active = TRUE;
- gint c;
- GSource *source;
-
- data->self->priv->local_stun_candidate[data->component_id] =
- data->candidate;
- data->self->priv->local_active_candidate[data->component_id] =
- fs_candidate_copy (data->candidate);
-
- g_signal_emit_by_name (data->self, "new-local-candidate", data->candidate);
-
- for (c = 1; c <= data->self->priv->transmitter->components; c++) {
- if (!data->self->priv->local_active_candidate[c]) {
- all_active = FALSE;
- break;
- }
- }
-
- if (all_active)
- g_signal_emit_by_name (data->self, "local-candidates-prepared");
-
-
- /* Lets remove this source from the list of sources to destroy */
- source = g_main_current_source ();
-
- if (source) {
- guint id = g_source_get_id (source);
-
- g_mutex_lock (data->self->priv->sources_mutex);
- data->self->priv->sources =
- g_list_remove (data->self->priv->sources, GUINT_TO_POINTER (id));
- g_mutex_unlock (data->self->priv->sources_mutex);
- }
-
- fs_rawudp_stream_transmitter_maybe_new_active_candidate_pair (data->self,
- data->component_id);
-
- g_free (data);
-
- /* We only pass one candidate at a time */
- return FALSE;
-}
-
-/*
- * We have to be extremely careful in this callback, it is executed
- * on the streaming thread, so all data must either be object-constant
- * (ie doesnt change for the life of the object) or locked by a mutex
- *
- */
-
-static gboolean
-fs_rawudp_stream_transmitter_stun_recv_cb (GstPad *pad, GstBuffer *buffer,
- gpointer user_data)
-{
- FsRawUdpStreamTransmitter *self = FS_RAWUDP_STREAM_TRANSMITTER (user_data);
- gint component_id = -1;
- FsCandidate *candidate = NULL;
- StunMessage *msg;
- StunAttribute **attr;
- gint c;
-
-
- if (GST_BUFFER_SIZE (buffer) < 4) {
- /* Packet is too small to be STUN */
- return TRUE;
- }
-
- if (GST_BUFFER_DATA (buffer)[0] >> 6) {
- /* Non stun packet */
- return TRUE;
- }
-
- for (c = 1; c <= self->priv->transmitter->components; c++) {
- if (fs_rawudp_transmitter_udpport_is_pad (self->priv->udpports[c], pad)) {
- component_id = c;
- break;
- }
- }
-
- if (component_id < 0) {
- g_error ("We've been called from a pad we shouldn't be listening to");
- return FALSE;
- }
-
- msg = stun_message_unpack (GST_BUFFER_SIZE (buffer),
- (const gchar *) GST_BUFFER_DATA (buffer));
- if (!msg) {
- /* invalid message */
- return TRUE;
- }
-
- if (memcmp (msg->transaction_id, self->priv->stun_cookie, 16) != 0) {
- /* not ours */
- stun_message_free (msg);
- return TRUE;
- }
-
- if (msg->type == STUN_MESSAGE_BINDING_ERROR_RESPONSE) {
- fs_stream_transmitter_emit_error (FS_STREAM_TRANSMITTER (self),
- FS_ERROR_NETWORK, "Got an error message from the STUN server",
- "The STUN process produced an error");
- stun_message_free (msg);
- // fs_rawudp_stream_transmitter_stop_stun (self, component_id);
- /* Lets not stop the STUN now and wait for the timeout
- * in case the server answers with the right reply
- */
- return FALSE;
- }
-
- if (msg->type != STUN_MESSAGE_BINDING_RESPONSE) {
- stun_message_free (msg);
- return TRUE;
- }
-
-
- for (attr = msg->attributes; *attr; attr++) {
- if ((*attr)->type == STUN_ATTRIBUTE_MAPPED_ADDRESS) {
-
- candidate = g_new0 (FsCandidate,1);
- candidate->candidate_id = g_strdup_printf ("L%u",
- self->priv->next_candidate_id);
- candidate->component_id = component_id;
- candidate->ip = g_strdup_printf ("%u.%u.%u.%u",
- ((*attr)->address.ip & 0xff000000) >> 24,
- ((*attr)->address.ip & 0x00ff0000) >> 16,
- ((*attr)->address.ip & 0x0000ff00) >> 8,
- ((*attr)->address.ip & 0x000000ff));
- candidate->port = (*attr)->address.port;
- candidate->proto = FS_NETWORK_PROTOCOL_UDP;
- candidate->type = FS_CANDIDATE_TYPE_SRFLX;
-
- GST_DEBUG ("Stun server says we are %u.%u.%u.%u %u\n",
- ((*attr)->address.ip & 0xff000000) >> 24,
- ((*attr)->address.ip & 0x00ff0000) >> 16,
- ((*attr)->address.ip & 0x0000ff00) >> 8,
- ((*attr)->address.ip & 0x000000ff),(*attr)->address.port);
- break;
- }
- }
-
- g_mutex_lock (self->priv->sources_mutex);
- fs_rawudp_stream_transmitter_stop_stun (self, component_id);
- g_mutex_unlock (self->priv->sources_mutex);
-
- if (candidate) {
- guint id;
- struct CandidateTransit *data = g_new0 (struct CandidateTransit, 1);
- data->self = self;
- data->candidate = candidate;
- data->component_id = component_id;
- id = g_idle_add (fs_rawudp_stream_transmitter_emit_stun_candidate, data);
- g_assert (id);
- g_mutex_lock (self->priv->sources_mutex);
- self->priv->sources = g_list_prepend (self->priv->sources,
- GUINT_TO_POINTER(id));
- g_mutex_unlock (self->priv->sources_mutex);
- }
-
- /* It was a stun packet, lets drop it */
- stun_message_free (msg);
- return FALSE;
-}
-
-static gboolean
-fs_rawudp_stream_transmitter_stun_timeout_cb (gpointer user_data)
-{
- struct CandidateTransit *data = user_data;
- gint c;
- gboolean all_active = TRUE;
-
- g_mutex_lock (data->self->priv->sources_mutex);
- fs_rawudp_stream_transmitter_stop_stun (data->self, data->component_id);
- g_mutex_unlock (data->self->priv->sources_mutex);
-
- if (!fs_rawudp_stream_transmitter_emit_local_candidates (data->self,
- data->component_id))
- return FALSE;
-
- for (c = 1; c <= data->self->priv->transmitter->components; c++) {
- if (!data->self->priv->local_active_candidate[c]) {
- all_active = FALSE;
- break;
- }
- }
-
- if (all_active)
- g_signal_emit_by_name (data->self, "local-candidates-prepared");
-
- return FALSE;
-}
-
-static gboolean
-fs_rawudp_stream_transmitter_start_stun (FsRawUdpStreamTransmitter *self,
- guint component_id, GError **error)
-{
- struct addrinfo hints;
- struct addrinfo *result = NULL;
- struct sockaddr_in address;
- gchar *packed;
- guint length;
- int retval;
- StunMessage *msg;
- gboolean ret = TRUE;
- struct CandidateTransit *data;
-
- memset (&hints, 0, sizeof (struct addrinfo));
- hints.ai_family = AF_INET;
- hints.ai_flags = AI_NUMERICHOST;
- retval = getaddrinfo (self->priv->stun_ip, NULL, &hints, &result);
- if (retval != 0) {
- g_set_error (error, FS_ERROR, FS_ERROR_NETWORK,
- "Invalid IP address %s passed for STUN: %s",
- self->priv->stun_ip, gai_strerror (retval));
- return FALSE;
- }
- memcpy (&address, result->ai_addr, sizeof(struct sockaddr_in));
- freeaddrinfo (result);
-
- address.sin_family = AF_INET;
- address.sin_port = htons (self->priv->stun_port);
-
- g_mutex_lock (self->priv->sources_mutex);
- self->priv->stun_recv_id[component_id] =
- fs_rawudp_transmitter_udpport_connect_recv (
- self->priv->udpports[component_id],
- G_CALLBACK (fs_rawudp_stream_transmitter_stun_recv_cb), self);
- g_mutex_unlock (self->priv->sources_mutex);
-
- msg = stun_message_new (STUN_MESSAGE_BINDING_REQUEST,
- self->priv->stun_cookie, 0);
- if (!msg) {
- g_set_error (error, FS_ERROR, FS_ERROR_NETWORK,
- "Could not create a new STUN binding request");
- return FALSE;
- }
-
- length = stun_message_pack (msg, &packed);
-
- if (!fs_rawudp_transmitter_udpport_sendto (self->priv->udpports[component_id],
- packed, length, (const struct sockaddr *)&address, sizeof(address),
- error)) {
- ret = FALSE;
- }
-
- g_free (packed);
- stun_message_free (msg);
-
- data = g_new0 (struct CandidateTransit, 1);
- data->self = self;
- data->component_id = component_id;
-
- g_mutex_lock (data->self->priv->sources_mutex);
-#if 1
- /* This is MAY broken in GLib 2.14 (gnome bug #448943) */
- /* If the test does not stop (and times out), this may be the cause
- * and in this case should be investigated further
- */
- self->priv->stun_timeout_id[component_id] = g_timeout_add_seconds_full (
- G_PRIORITY_DEFAULT, self->priv->stun_timeout,
- fs_rawudp_stream_transmitter_stun_timeout_cb, data, g_free);
-#else
- self->priv->stun_timeout_id[component_id] = g_timeout_add_full (
- G_PRIORITY_DEFAULT, self->priv->stun_timeout * 1000,
- fs_rawudp_stream_transmitter_stun_timeout_cb, data, g_free);
-#endif
- g_assert (self->priv->stun_timeout_id[component_id]);
- g_mutex_unlock (data->self->priv->sources_mutex);
-
- return ret;
-}
-
-/*
- * This function MUST be called with the sources_mutex held
- */
-
-static void
-fs_rawudp_stream_transmitter_stop_stun (FsRawUdpStreamTransmitter *self,
- guint component_id)
-{
- if (self->priv->stun_recv_id[component_id]) {
- fs_rawudp_transmitter_udpport_disconnect_recv (
- self->priv->udpports[component_id],
- self->priv->stun_recv_id[component_id]);
- self->priv->stun_recv_id[component_id] = 0;
- }
-
- if (self->priv->stun_timeout_id[component_id]) {
- g_source_remove (self->priv->stun_timeout_id[component_id]);
- self->priv->stun_timeout_id[component_id] = 0;
- }
-}
-
static FsCandidate *
-fs_rawudp_stream_transmitter_build_forced_candidate (
- FsRawUdpStreamTransmitter *self, const char *ip, gint port,
+fs_multicast_stream_transmitter_build_forced_candidate (
+ FsMulticastStreamTransmitter *self, const char *ip, gint port,
guint component_id)
{
FsCandidate *candidate = g_new0 (FsCandidate, 1);
@@ -1035,8 +610,8 @@ fs_rawudp_stream_transmitter_build_forced_candidate (
}
static gboolean
-fs_rawudp_stream_transmitter_emit_local_candidates (
- FsRawUdpStreamTransmitter *self, guint component_id)
+fs_multicast_stream_transmitter_emit_local_candidates (
+ FsMulticastStreamTransmitter *self, guint component_id)
{
GList *ips = NULL;
GList *current;
@@ -1056,12 +631,12 @@ fs_rawudp_stream_transmitter_emit_local_candidates (
self->priv->local_forced_candidate[component_id]);
g_signal_emit_by_name (self, "new-local-candidate",
self->priv->local_forced_candidate[component_id]);
- fs_rawudp_stream_transmitter_maybe_new_active_candidate_pair (self,
+ fs_multicast_stream_transmitter_maybe_new_active_candidate_pair (self,
component_id);
return TRUE;
}
- port = fs_rawudp_transmitter_udpport_get_port (
+ port = fs_multicast_transmitter_udpport_get_port (
self->priv->udpports[component_id]);
ips = farsight_get_local_ips (TRUE);
@@ -1101,20 +676,16 @@ fs_rawudp_stream_transmitter_emit_local_candidates (
return FALSE;
}
- fs_rawudp_stream_transmitter_maybe_new_active_candidate_pair (self,
+ fs_multicast_stream_transmitter_maybe_new_active_candidate_pair (self,
component_id);
return TRUE;
}
-/*
- * This is called when there is no stun
- */
-
static gboolean
-fs_rawudp_stream_transmitter_no_stun (gpointer user_data)
+fs_multicast_stream_transmitter_no_stun (gpointer user_data)
{
- FsRawUdpStreamTransmitter *self = user_data;
+ FsMulticastStreamTransmitter *self = user_data;
GSource *source;
gint c;
@@ -1123,7 +694,7 @@ fs_rawudp_stream_transmitter_no_stun (gpointer user_data)
for (c = 1; c <= self->priv->transmitter->components; c++) {
if (!self->priv->local_active_candidate[c]) {
- if (!fs_rawudp_stream_transmitter_emit_local_candidates (self, c))
+ if (!fs_multicast_stream_transmitter_emit_local_candidates (self, c))
return FALSE;
}
g_assert (self->priv->local_active_candidate[c]);
@@ -1148,8 +719,8 @@ fs_rawudp_stream_transmitter_no_stun (gpointer user_data)
}
static void
-fs_rawudp_stream_transmitter_maybe_new_active_candidate_pair (
- FsRawUdpStreamTransmitter *self, guint component_id)
+fs_multicast_stream_transmitter_maybe_new_active_candidate_pair (
+ FsMulticastStreamTransmitter *self, guint component_id)
{
if (self->priv->local_active_candidate[component_id] &&
self->priv->remote_candidate[component_id]) {
--
1.5.6.5
More information about the farsight-commits
mailing list