Commit d523aa98 authored by Ghislain MARY's avatar Ghislain MARY

Add ICE session.

parent 15bc4916
......@@ -25,6 +25,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "ortp/ortp.h"
typedef enum {
IR_Controlling,
IR_Controlled
} IceRole;
typedef enum {
ICT_HostCandidate,
ICT_ServerReflexiveCandidate,
......@@ -46,6 +51,13 @@ typedef enum {
ICL_Failed
} IceCheckListState;
typedef struct _IceSession {
MSList *streams; /**< List of IceChecklist structures */
IceRole role;
uint64_t tie_breaker;
uint8_t max_connectivity_checks;
} IceSession;
typedef struct _IceTransportAddress {
char ip[64];
int port;
......@@ -79,13 +91,13 @@ typedef struct _IcePairFoundation {
} IcePairFoundation;
typedef struct _IceCheckList {
IceSession *session;
MSList *local_candidates; /**< List of IceCandidate structures */
MSList *remote_candidates; /**< List of IceCandidate structures */
MSList *pairs; /**< List of IceCandidatePair structures */
MSList *foundations; /**< List of IcePairFoundation structures */
IceCheckListState state;
uint32_t foundation_generator;
uint8_t max_connectivity_checks;
} IceCheckList;
......@@ -93,13 +105,21 @@ typedef struct _IceCheckList {
extern "C"{
#endif
IceSession * ice_session_new(void);
void ice_session_destroy(IceSession *session);
IceCheckList * ice_check_list_new(void);
void ice_check_list_destroy(IceCheckList *cl);
IceCheckListState ice_check_list_state(IceCheckList *cl);
void ice_session_set_role(IceSession *session, IceRole role);
void ice_session_set_max_connectivity_checks(IceSession *session, uint8_t max_connectivity_checks);
void ice_check_list_set_max_connectivity_checks(IceCheckList *cl, uint8_t max_connectivity_checks);
void ice_session_add_check_list(IceSession *session, IceCheckList *cl);
IceCheckListState ice_check_list_state(IceCheckList *cl);
/**
* This function is not to be used directly. The ice_gather_candidates() function SHOULD be used instead.
......
......@@ -82,15 +82,45 @@ static const char * const candidate_pair_state_values[] = {
/******************************************************************************
* INITIALISATION AND DEINITIALISATION *
* SESSION INITIALISATION AND DEINITIALISATION *
*****************************************************************************/
static void ice_session_init(IceSession *session)
{
session->streams = NULL;
session->role = IR_Controlling;
session->tie_breaker = (random() << 32) | (random() & 0xffffffff);
session->max_connectivity_checks = ICE_MAX_NB_CANDIDATE_PAIRS;
}
IceSession * ice_session_new(void)
{
IceSession *session = ms_new(IceSession, 1);
if (session == NULL) {
ms_error("ice_session_new: Memory allocation failed");
return NULL;
}
ice_session_init(session);
return session;
}
void ice_session_destroy(IceSession *session)
{
ms_list_free(session->streams);
ms_free(session);
}
/******************************************************************************
* CHECK LIST INITIALISATION AND DEINITIALISATION *
*****************************************************************************/
static void ice_check_list_init(IceCheckList *cl)
{
cl->session = NULL;
cl->local_candidates = cl->remote_candidates = cl->pairs = cl->foundations = NULL;
cl->state = ICL_Running;
cl->foundation_generator = 1;
cl->max_connectivity_checks = ICE_MAX_NB_CANDIDATE_PAIRS;
}
IceCheckList * ice_check_list_new(void)
......@@ -142,9 +172,30 @@ IceCheckListState ice_check_list_state(IceCheckList *cl)
return cl->state;
}
void ice_check_list_set_max_connectivity_checks(IceCheckList *cl, uint8_t max_connectivity_checks)
/******************************************************************************
* SESSION ACCESSORS *
*****************************************************************************/
void ice_session_set_role(IceSession *session, IceRole role)
{
session->role = role;
}
void ice_session_set_max_connectivity_checks(IceSession *session, uint8_t max_connectivity_checks)
{
session->max_connectivity_checks = max_connectivity_checks;
}
/******************************************************************************
* SESSION HANDLING *
*****************************************************************************/
void ice_session_add_check_list(IceSession *session, IceCheckList *cl)
{
cl->max_connectivity_checks = max_connectivity_checks;
session->streams = ms_list_append(session->streams, cl);
cl->session = session;
}
......@@ -481,8 +532,8 @@ static void ice_prune_candidate_pairs(IceCheckList *cl)
}
/* Limit the number of connectivity checks. */
nb_pairs = ms_list_size(cl->pairs);
if (nb_pairs > cl->max_connectivity_checks) {
nb_pairs_to_remove = nb_pairs - cl->max_connectivity_checks;
if (nb_pairs > cl->session->max_connectivity_checks) {
nb_pairs_to_remove = nb_pairs - cl->session->max_connectivity_checks;
list = cl->pairs;
for (i = 0; i < (nb_pairs - 1); i++) list = ms_list_next(list);
for (i = 0; i < nb_pairs_to_remove; i++) {
......
......@@ -131,6 +131,7 @@ typedef struct _MediastreamDatas {
OrtpEvQueue *q;
RtpProfile *profile;
IceSession *ice_session;
MediastreamIceCandidate ice_local_candidates[MEDIASTREAM_MAX_ICE_CANDIDATES];
MediastreamIceCandidate ice_remote_candidates[MEDIASTREAM_MAX_ICE_CANDIDATES];
int ice_local_candidates_nb;
......@@ -305,6 +306,7 @@ MediastreamDatas* init_default_args() {
args->q = NULL;
args->profile = NULL;
args->ice_session = NULL;
memset(args->ice_local_candidates, 0, sizeof(args->ice_local_candidates));
memset(args->ice_remote_candidates, 0, sizeof(args->ice_remote_candidates));
args->ice_local_candidates_nb = args->ice_remote_candidates_nb = 0;
......@@ -548,6 +550,7 @@ void setup_media_streams(MediastreamDatas* args) {
ms_init();
ms_filter_enable_statistics(TRUE);
ms_filter_reset_statistics();
args->ice_session=ice_session_new();
signal(SIGINT,stop_handler);
args->pt=rtp_profile_get_payload(args->profile,args->payload);
......@@ -620,6 +623,7 @@ void setup_media_streams(MediastreamDatas* args) {
ice_add_remote_candidate(args->audio->ice_check_list,candidate->type,candidate->ip,candidate->port+1,2,0,foundation);
}
}
ice_session_add_check_list(args->ice_session, args->audio->ice_check_list);
ice_choose_default_candidates(args->audio->ice_check_list);
ice_pair_candidates(args->audio->ice_check_list, TRUE);
ice_dump_candidates(args->audio->ice_check_list);
......@@ -823,6 +827,7 @@ void clear_mediastreams(MediastreamDatas* args) {
ms_filter_log_statistics();
}
#endif
if (args->ice_session) ice_session_destroy(args->ice_session);
ortp_ev_queue_destroy(args->q);
rtp_profile_destroy(args->profile);
......
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