Commit 074d897e authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Add function to eliminate ICE redundant candidates.

parent 91bc2e61
......@@ -466,6 +466,16 @@ void ice_session_set_base_for_srflx_candidates(IceSession *session);
*/
MS2_PUBLIC void ice_session_compute_candidates_foundations(IceSession *session);
/**
* Eliminate the redundant candidates of an ICE session.
*
* @param session A pointer to a session
*
* This function is to be called at the end of the local candidates gathering process, before sending
* the SDP to the remote agent.
*/
MS2_PUBLIC void ice_session_eliminate_redundant_candidates(IceSession *session);
/**
* Choose the default candidates of an ICE session.
*
......
......@@ -1469,6 +1469,52 @@ void ice_session_compute_candidates_foundations(IceSession *session)
}
/******************************************************************************
* ELIMINATE REDUNDANT CANDIDATES *
*****************************************************************************/
static int ice_find_redundant_candidate(const IceCandidate *c1, const IceCandidate *c2)
{
if (c1 == c2) return 1;
return !(!ice_compare_transport_addresses(&c1->taddr, &c2->taddr) && (c1->base == c2->base));
}
static void ice_check_list_eliminate_redundant_candidates(IceCheckList *cl)
{
MSList *elem;
MSList *other_elem;
IceCandidate *candidate;
IceCandidate *other_candidate;
bool_t elem_removed;
do {
elem_removed = FALSE;
/* Do not use ms_list_for_each2() here, we may remove list elements. */
for (elem = cl->local_candidates; elem != NULL; elem = elem->next) {
candidate = (IceCandidate *)elem->data;
other_elem = ms_list_find_custom(cl->local_candidates, (MSCompareFunc)ice_find_redundant_candidate, candidate);
if (other_elem != NULL) {
other_candidate = (IceCandidate *)other_elem->data;
if (other_candidate->priority < candidate->priority) {
ice_free_candidate(other_candidate);
cl->local_candidates = ms_list_remove_link(cl->local_candidates, other_elem);
} else {
ice_free_candidate(candidate);
cl->local_candidates = ms_list_remove_link(cl->local_candidates, elem);
}
elem_removed = TRUE;
break;
}
}
} while (elem_removed);
}
void ice_session_eliminate_redundant_candidates(IceSession *session)
{
ms_list_for_each(session->streams, (void (*)(void*))ice_check_list_eliminate_redundant_candidates);
}
/******************************************************************************
* CHOOSE DEFAULT CANDIDATES *
*****************************************************************************/
......
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