- audio_gatherings[0].base = ice_add_local_candidate(audio_check_list, "host", local_addr, call->audio_port, 1, NULL);
- audio_gatherings[1].base = ice_add_local_candidate(audio_check_list, "host", local_addr, call->audio_port + 1, 2, NULL);
- if (call->params.has_video && (video_check_list != NULL)) {
- video_gatherings[0].base = ice_add_local_candidate(video_check_list, "host", local_addr, call->video_port, 1, NULL);
- video_gatherings[1].base = ice_add_local_candidate(video_check_list, "host", local_addr, call->video_port + 1, 2, NULL);
- }
-
- gettimeofday(&init, NULL);
- audio_gatherings[0].transmission_time = cur = init;
- diff.tv_sec = 0, diff.tv_usec = 20000;
- timeradd(&audio_gatherings[0].transmission_time, &diff, &audio_gatherings[1].transmission_time);
- timeradd(&audio_gatherings[1].transmission_time, &diff, &video_gatherings[0].transmission_time);
- timeradd(&video_gatherings[0].transmission_time, &diff, &video_gatherings[1].transmission_time);
- diff.tv_sec = 0, diff.tv_usec = 100000;
- do {
- if ((audio_gatherings[0].response == FALSE) && timercmp(&cur, &audio_gatherings[0].transmission_time, >=)) {
- timeradd(&audio_gatherings[0].transmission_time, &diff, &audio_gatherings[0].transmission_time);
- sendStunRequest(audio_gatherings[0].sock, (struct sockaddr*)&ss, ss_len, 1, FALSE);
- }
- if ((audio_gatherings[1].response == FALSE) && timercmp(&cur, &audio_gatherings[1].transmission_time, >=)) {
- timeradd(&audio_gatherings[1].transmission_time, &diff, &audio_gatherings[1].transmission_time);
- sendStunRequest(audio_gatherings[1].sock, (struct sockaddr*)&ss, ss_len, 1, FALSE);
- }
- if (call->params.has_video) {
- if ((video_gatherings[0].response == FALSE) && timercmp(&cur, &video_gatherings[0].transmission_time, >=)) {
- timeradd(&video_gatherings[0].transmission_time, &diff, &video_gatherings[0].transmission_time);
- sendStunRequest(video_gatherings[0].sock, (struct sockaddr*)&ss, ss_len, 2, FALSE);
- }
- if ((video_gatherings[1].response == FALSE) && timercmp(&cur, &video_gatherings[1].transmission_time, >=)) {
- timeradd(&video_gatherings[1].transmission_time, &diff, &video_gatherings[1].transmission_time);
- sendStunRequest(video_gatherings[1].sock, (struct sockaddr*)&ss, ss_len, 2, FALSE);
- }
- }
-#ifdef WIN32
- Sleep(10);
-#else
- usleep(10000);
-#endif
-
- if (recvStunResponse(audio_gatherings[0].sock, addr, &port, &id) > 0) {
- ice_add_local_candidate(audio_check_list, "srflx", addr, port, 1, audio_gatherings[0].base);
- audio_gatherings[0].response = TRUE;
- }
- if (recvStunResponse(audio_gatherings[1].sock, addr, &port, &id) > 0) {
- ice_add_local_candidate(audio_check_list, "srflx", addr, port, 2, audio_gatherings[1].base);
- audio_gatherings[1].response = TRUE;
- }
- if (call->params.has_video && (video_check_list != NULL)) {
- if (recvStunResponse(video_gatherings[0].sock, addr, &port, &id) > 0) {
- ice_add_local_candidate(video_check_list, "srflx", addr, port, 1, video_gatherings[0].base);
- video_gatherings[0].response = TRUE;
- }
- if (recvStunResponse(video_gatherings[1].sock, addr, &port, &id) > 0) {
- ice_add_local_candidate(video_check_list, "srflx", addr, port, 2, video_gatherings[1].base);
- video_gatherings[1].response = TRUE;
- }
- }
-
- gettimeofday(&cur, NULL);
- elapsed = ((cur.tv_sec - init.tv_sec) * 1000.0) + ((cur.tv_usec - init.tv_usec) / 1000.0);
- if (elapsed > 2000) {
- ms_message("Stun responses timeout, going ahead.");
- break;
- }
- loops++;
- } while (!((audio_gatherings[0].response == TRUE) && (audio_gatherings[1].response == TRUE)
- && (!call->params.has_video || ((video_gatherings[0].response == TRUE) && (video_gatherings[1].response == TRUE)))));
-
- if ((audio_gatherings[0].response == FALSE) || (audio_gatherings[1].response == FALSE)
- || (call->params.has_video && ((video_gatherings[0].response == FALSE) || (video_gatherings[1].response == FALSE)))) {
- /* Failed some STUN checks, deactivate ICE. */
- ice_session_destroy(ice_session);
- ice_session = NULL;
- sal_op_set_ice_session(call->op, ice_session);
- } else {
- ice_session_compute_candidates_foundations(ice_session);
- ice_session_eliminate_redundant_candidates(ice_session);
- ice_session_choose_default_candidates(ice_session);
- }
-
- close_socket(audio_gatherings[0].sock);
- close_socket(audio_gatherings[1].sock);
- if (ice_session != NULL) ice_dump_candidates(audio_check_list);