Index: res/res_rtp_asterisk.c =================================================================== --- res/res_rtp_asterisk.c (revision 408284) +++ res/res_rtp_asterisk.c (working copy) @@ -508,6 +508,7 @@ struct ao2_iterator i; struct ast_rtp_engine_ice_candidate *candidate; int cand_cnt = 0; + int res; if (!rtp->ice || !rtp->remote_candidates || rtp->ice_started) { return; @@ -549,22 +554,31 @@ ao2_iterator_destroy(&i); - if (pj_ice_sess_create_check_list(rtp->ice, &ufrag, &passwd, ao2_container_count(rtp->remote_candidates), &candidates[0]) == PJ_SUCCESS) { + /* pj_ice_sess_create_check_list will assert if we try to send more candidates than it can + * handle. Wipe the existing candidates out if that's the case. */ + if (ao2_container_count(rtp->remote_candidates) + rtp->ice->rcand_cnt > PJ_ICE_MAX_CAND) { + ao2_ref(rtp->remote_candidates, -1); + rtp->remote_candidates = NULL; + rtp->ice->rcand_cnt = rtp->ice->clist.count = 0; + return; + } + + res = pj_ice_sess_create_check_list(rtp->ice, &ufrag, &passwd, ao2_container_count(rtp->remote_candidates), &candidates[0]); + if (res == PJ_SUCCESS) { + ast_debug(1, "ICE session check list success.\n"); pj_ice_sess_start_check(rtp->ice); pj_timer_heap_poll(timerheap, NULL); rtp->ice_started = 1; rtp->strict_rtp_state = STRICT_RTP_OPEN; - return; + } else if (res == PJ_ETOOMANY) { + /* pj_ice_sess_create_check_list has more ice candidates than it can handle. */ + ast_debug(1, "ICE session check list has more ice candidates than it can handle.\n"); + ao2_ref(rtp->remote_candidates, -1); + rtp->remote_candidates = NULL; + rtp->ice->rcand_cnt = rtp->ice->clist.count = 0; + } else { + ast_debug(1, "ICE session check list failure. (%d)\n",res); } - - /* even though create check list failed don't stop ice as - it might still work */ - ast_debug(1, "Failed to create ICE session check list\n"); - /* however we do need to reset remote candidates since - this function may be re-entered */ - ao2_ref(rtp->remote_candidates, -1); - rtp->remote_candidates = NULL; - rtp->ice->rcand_cnt = rtp->ice->clist.count = 0; } static void ast_rtp_ice_stop(struct ast_rtp_instance *instance) @@ -1062,6 +1068,7 @@ } rtp->strict_rtp_state = STRICT_RTP_LEARN; + ast_debug(1, "Learning mode set by on_ice_complete.\n"); rtp_learning_seq_init(&rtp->rtp_source_learn, (uint16_t)rtp->seqno); }