[farsight2/master] Move remote candidate setting to component class
Olivier Crête
olivier.crete at collabora.co.uk
Tue Dec 23 15:22:03 PST 2008
---
transmitters/rawudp/fs-rawudp-component.c | 52 ++++++++++++++++++++
transmitters/rawudp/fs-rawudp-component.h | 5 ++
transmitters/rawudp/fs-rawudp-stream-transmitter.c | 24 +++------
3 files changed, 65 insertions(+), 16 deletions(-)
diff --git a/transmitters/rawudp/fs-rawudp-component.c b/transmitters/rawudp/fs-rawudp-component.c
index d1b1bee..4484521 100644
--- a/transmitters/rawudp/fs-rawudp-component.c
+++ b/transmitters/rawudp/fs-rawudp-component.c
@@ -72,6 +72,8 @@ struct _FsRawUdpComponentPrivate
/* Above this line, its all set at construction time */
/* This is protected by the mutex */
+ FsCandidate *remote_candidate;
+
gboolean sending;
};
@@ -238,6 +240,13 @@ fs_rawudp_component_dispose (GObject *object)
/* If dispose did already run, return. */
return;
+ if (self->priv->remote_candidate &&
+ self->priv->udpport &&
+ self->priv->sending)
+ fs_rawudp_transmitter_udpport_remove_dest (self->priv->udpport,
+ self->priv->remote_candidate->ip,
+ self->priv->remote_candidate->port);
+
FS_RAWUDP_COMPONENT_LOCK (self);
self->priv->udpport = NULL;
@@ -259,6 +268,9 @@ fs_rawudp_component_finalize (GObject *object)
{
FsRawUdpComponent *self = FS_RAWUDP_COMPONENT (object);
+ if (self->priv->remote_candidate)
+ fs_candidate_destroy (self->priv->remote_candidate);
+
g_free (self->priv->stun_ip);
g_mutex_free (self->priv->mutex);
@@ -359,3 +371,43 @@ fs_rawudp_component_new (
return self;
}
+
+
+gboolean
+fs_rawudp_component_add_remote_candidate (FsRawUdpComponent *self,
+ FsCandidate *candidate,
+ GError **error)
+{
+ FsCandidate *old_candidate = NULL;
+ gboolean sending;
+
+ if (candidate->component_id != self->priv->component)
+ {
+ g_set_error (error, FS_ERROR, FS_ERROR_INTERNAL,
+ "Remote candidate routed to wrong component (%d->%d)",
+ candidate->component_id,
+ self->priv->component);
+ return FALSE;
+ }
+
+ FS_RAWUDP_COMPONENT_LOCK (self);
+ old_candidate = self->priv->remote_candidate;
+ self->priv->remote_candidate = fs_candidate_copy (candidate);
+ sending = self->priv->sending;
+ FS_RAWUDP_COMPONENT_UNLOCK (self);
+
+
+ if (sending)
+ fs_rawudp_transmitter_udpport_add_dest (self->priv->udpport,
+ candidate->ip, candidate->port);
+
+ if (old_candidate)
+ {
+ fs_rawudp_transmitter_udpport_remove_dest (self->priv->udpport,
+ old_candidate->ip,
+ old_candidate->port);
+ fs_candidate_destroy (old_candidate);
+ }
+
+ return TRUE;
+}
diff --git a/transmitters/rawudp/fs-rawudp-component.h b/transmitters/rawudp/fs-rawudp-component.h
index 53fdcaf..0ea8ba2 100644
--- a/transmitters/rawudp/fs-rawudp-component.h
+++ b/transmitters/rawudp/fs-rawudp-component.h
@@ -99,6 +99,11 @@ fs_rawudp_component_new (
UdpPort *udpport,
GError **error);
+gboolean
+fs_rawudp_component_add_remote_candidate (FsRawUdpComponent *self,
+ FsCandidate *candidate,
+ GError **error);
+
G_END_DECLS
diff --git a/transmitters/rawudp/fs-rawudp-stream-transmitter.c b/transmitters/rawudp/fs-rawudp-stream-transmitter.c
index e12f75b..e7558b2 100644
--- a/transmitters/rawudp/fs-rawudp-stream-transmitter.c
+++ b/transmitters/rawudp/fs-rawudp-stream-transmitter.c
@@ -375,10 +375,7 @@ fs_rawudp_stream_transmitter_finalize (GObject *object)
{
if (self->priv->udpports && self->priv->udpports[c] &&
self->priv->sending)
- fs_rawudp_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]);
+ fs_candidate_destroy (self->priv->remote_candidate[c]);
}
}
@@ -748,21 +745,16 @@ fs_rawudp_stream_transmitter_add_remote_candidate (
* IMPROVE ME: We should probably check that the candidate's IP
* 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 (
- self->priv->udpports[candidate->component_id],
- candidate->ip, candidate->port);
- }
+
+
+ if (!fs_rawudp_component_add_remote_candidate (
+ self->priv->component[candidate->component_id],
+ candidate, error))
+ return FALSE;
+
if (self->priv->remote_candidate[candidate->component_id])
- {
- fs_rawudp_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);
fs_candidate_destroy (
self->priv->remote_candidate[candidate->component_id]);
- }
self->priv->remote_candidate[candidate->component_id] =
fs_candidate_copy (candidate);
--
1.5.6.5
More information about the farsight-commits
mailing list