From a3b01c195be3c1454c60e634477d8c825c60ac77 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 21 Dec 2010 15:35:13 -0600 Subject: [PATCH] rtp adjustments when using jitterbuffer --- src/switch_ivr.c | 2 +- src/switch_rtp.c | 39 ++++++++++++--------------------------- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/switch_ivr.c b/src/switch_ivr.c index cd74c332b7..68d5a55b40 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -2285,7 +2285,7 @@ SWITCH_DECLARE(void) switch_ivr_delay_echo(switch_core_session_t *session, uint3 break; } - stfu_n_eat(jb, ts, read_frame->payload, read_frame->data, read_frame->datalen); + stfu_n_eat(jb, ts, read_frame->payload, read_frame->data, read_frame->datalen, 0); ts += interval; if ((jb_frame = stfu_n_read_a_frame(jb))) { diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 4e667fb49b..aa4ca7a5ca 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -2135,19 +2135,6 @@ static void do_flush(switch_rtp_t *rtp_session) flushed++; -#ifdef _MSC_VER -#pragma warning(push) /* remove this stuff when "if (0" is removed */ -#pragma warning(disable:4127) -#endif - if (0 && rtp_session->jb) { - stfu_n_eat(rtp_session->jb, ntohl(rtp_session->recv_msg.header.ts), - rtp_session->recv_msg.header.pt, - rtp_session->recv_msg.body, bytes - rtp_header_len); - } -#ifdef _MSC_VER -#pragma warning(pop) -#endif - rtp_session->stats.inbound.raw_bytes += bytes; rtp_session->stats.inbound.flush_packet_count++; rtp_session->stats.inbound.packet_count++; @@ -2196,12 +2183,13 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t rtp_session->stats.inbound.packet_count++; } - if ((rtp_session->recv_te && rtp_session->recv_msg.header.pt == rtp_session->recv_te) || - *bytes < rtp_header_len || - switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA) || switch_test_flag(rtp_session, SWITCH_RTP_FLAG_UDPTL)) { - return SWITCH_STATUS_SUCCESS; + if (*bytes != 0 && !rtp_session->jb) { + if ((rtp_session->recv_te && rtp_session->recv_msg.header.pt == rtp_session->recv_te) || + *bytes < rtp_header_len || + switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PROXY_MEDIA) || switch_test_flag(rtp_session, SWITCH_RTP_FLAG_UDPTL)) { + return SWITCH_STATUS_SUCCESS; + } } - if (rtp_session->jb && rtp_session->recv_msg.header.version == 2 && *bytes) { if (rtp_session->recv_msg.header.m && rtp_session->recv_msg.header.pt != rtp_session->recv_te && @@ -2211,14 +2199,15 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t stfu_n_eat(rtp_session->jb, ntohl(rtp_session->recv_msg.header.ts), rtp_session->recv_msg.header.pt, - rtp_session->recv_msg.body, *bytes - rtp_header_len); + rtp_session->recv_msg.body, *bytes - rtp_header_len, rtp_session->timer.samplecount); *bytes = 0; status = SWITCH_STATUS_FALSE; } - if (rtp_session->jb) { + if (rtp_session->jb && !rtp_session->checked_jb) { if ((jb_frame = stfu_n_read_a_frame(rtp_session->jb))) { memcpy(rtp_session->recv_msg.body, jb_frame->data, jb_frame->dlen); + if (jb_frame->plc) { (*flags) |= SFF_PLC; } else { @@ -2229,6 +2218,7 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t rtp_session->recv_msg.header.pt = jb_frame->pt; status = SWITCH_STATUS_SUCCESS; } + rtp_session->checked_jb++; } @@ -2385,7 +2375,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ rtp_session->read_pollfd) { if (switch_poll(rtp_session->read_pollfd, 1, &fdr, 0) == SWITCH_STATUS_SUCCESS) { rtp_session->hot_hits += rtp_session->samples_per_interval; - + if (rtp_session->hot_hits >= rtp_session->samples_per_second * 5) { switch_set_flag(rtp_session, SWITCH_RTP_FLAG_FLUSH); hot_socket = 1; @@ -2927,12 +2917,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ if (do_cng) { uint8_t *data = (uint8_t *) rtp_session->recv_msg.body; - int fdr; - - if ((poll_status = switch_poll(rtp_session->read_pollfd, 1, &fdr, 0)) == SWITCH_STATUS_SUCCESS) { - goto recvfrom; - } - + memset(data, 0, 2); data[0] = 65; rtp_session->recv_msg.header.pt = (uint32_t) rtp_session->cng_pt ? rtp_session->cng_pt : SWITCH_RTP_CNG_PAYLOAD;