diff --git a/src/switch_rtp.c b/src/switch_rtp.c index a91f937708..3a29d8d52a 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -474,14 +474,23 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session return SWITCH_STATUS_FALSE; } } - switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_USE_TIMER); + if (timer_name) { - if (switch_core_timer_init(&rtp_session->timer, timer_name, ms_per_packet / 1000, packet_size, rtp_session->pool) != SWITCH_STATUS_SUCCESS) { - return SWITCH_STATUS_FALSE; - } switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_USE_TIMER); } + if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER) && !timer_name) { + timer_name = "soft"; + } + + if (switch_core_timer_init(&rtp_session->timer, timer_name, ms_per_packet / 1000, packet_size, rtp_session->pool) == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Starting timer [%s] %d bytes per %dms\n", timer_name, packet_size, ms_per_packet); + } else { + memset(&rtp_session->timer, 0, sizeof(rtp_session->timer)); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error starting timer [%s], async RTP disabled\n", timer_name); + switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_USE_TIMER); + } + rtp_session->ready++; *new_rtp_session = rtp_session; @@ -727,13 +736,17 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ { switch_size_t bytes; switch_status_t status; - switch_time_t now = 0; - + uint8_t check = 1; + + if (!rtp_session->timer.interval) { + rtp_session->last_time = switch_time_now(); + } + for(;;) { bytes = sizeof(rtp_msg_t); status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *)&rtp_session->recv_msg, &bytes); - if (!SWITCH_STATUS_IS_BREAK(status) && rtp_session->timer.timer_interface) { + if (!SWITCH_STATUS_IS_BREAK(status) && rtp_session->timer.interval) { switch_core_timer_step(&rtp_session->timer); } @@ -795,11 +808,13 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ } } } - - if ((!rtp_session->timer.timer_interface && (now=switch_time_now()) - rtp_session->last_time > 10000) || - switch_core_timer_check(&rtp_session->timer) == SWITCH_STATUS_SUCCESS) { + + if (rtp_session->timer.interval) { + check = (switch_core_timer_check(&rtp_session->timer) == SWITCH_STATUS_SUCCESS); + } + + if (check) { do_2833(rtp_session); - rtp_session->last_time = now; if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) { /* We're late! We're Late!*/