[Nice] [nice/master] Add function to component to force the selection of a remote candidate
Olivier Crête
olivier.crete at collabora.co.uk
Wed Nov 5 14:01:44 PST 2008
---
agent/component.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
agent/component.h | 4 +++
2 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/agent/component.c b/agent/component.c
index 0d9dc6a..15167b9 100644
--- a/agent/component.c
+++ b/agent/component.c
@@ -243,3 +243,66 @@ component_find_remote_candidate (const Component *component, const NiceAddress *
return NULL;
}
+
+/*
+ * Sets the desired remote candidate as the selected pair
+ *
+ * It will start sending on the highest priority pair available with
+ * this candidate.
+ */
+
+NiceCandidate *
+component_set_selected_remote_candidate (NiceAgent *agent, Component *component,
+ NiceCandidate *candidate)
+{
+ NiceCandidate *local = NULL;
+ NiceCandidate *remote = NULL;
+ guint32 priority = 0;
+ GSList *item = NULL;
+
+ for (item = component->local_candidates; item; item = g_slist_next (item)) {
+ NiceCandidate *tmp = item->data;
+ guint32 tmp_prio = 0;
+
+ if (tmp->transport != candidate->transport ||
+ tmp->addr.s.addr.sa_family != candidate->addr.s.addr.sa_family ||
+ tmp->type != NICE_CANDIDATE_TYPE_HOST)
+ continue;
+
+ tmp_prio = agent_candidate_pair_priority (agent, tmp, candidate);
+
+ if (tmp_prio > priority) {
+ priority = tmp_prio;
+ local = tmp;
+ }
+ }
+
+ if (local == NULL)
+ return NULL;
+
+ remote = component_find_remote_candidate (component, &candidate->addr,
+ candidate->transport);
+
+ if (!remote) {
+ GSList *modified_list = NULL;
+
+ remote = nice_candidate_copy (candidate);
+
+ modified_list = g_slist_append (component->remote_candidates,
+ remote);
+ if (modified_list) {
+ component->remote_candidates = modified_list;
+ agent_signal_new_remote_candidate (agent, remote);
+ }
+ else { /* error: memory alloc / list */
+ nice_candidate_free (remote), remote = NULL;
+ return NULL;
+ }
+ }
+
+ component->selected_pair.local = local;
+ component->selected_pair.remote = remote;
+ component->selected_pair.priority = priority;
+
+ return local;
+}
diff --git a/agent/component.h b/agent/component.h
index d05c8c4..a7e1319 100644
--- a/agent/component.h
+++ b/agent/component.h
@@ -116,6 +116,10 @@ component_update_selected_pair (Component *component, const CandidatePair *pair)
NiceCandidate *
component_find_remote_candidate (const Component *component, const NiceAddress *addr, NiceCandidateTransport transport);
+NiceCandidate *
+component_set_selected_remote_candidate (NiceAgent *agent, Component *component,
+ NiceCandidate *candidate);
+
G_END_DECLS
#endif /* _NICE_COMPONENT_H */
--
1.5.6.5
More information about the Nice
mailing list