From 34a0ca50960a152c3ca9cee5099f6aa9109f7735 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 22 Dec 2010 20:38:57 -0600 Subject: [PATCH] drop rtp frame that was already replaced with a cng frame --- src/include/switch_types.h | 1 + src/mod/applications/mod_dptools/mod_dptools.c | 7 +++++++ src/switch_core_io.c | 3 ++- src/switch_rtp.c | 14 ++++++++++++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 76af5a40ed..830ea409e8 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1097,6 +1097,7 @@ typedef enum { CF_JITTERBUFFER, CF_DIALPLAN, CF_BLOCK_BROADCAST_UNTIL_MEDIA, + CF_CNG_PLC, /* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */ CF_FLAG_MAX } switch_channel_flag_t; diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index e508486380..d5d0cb7576 100755 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -3112,6 +3112,11 @@ SWITCH_STANDARD_APP(verbose_events_function) switch_channel_set_flag(switch_core_session_get_channel(session), CF_VERBOSE_EVENTS); } +SWITCH_STANDARD_APP(cng_plc_function) +{ + switch_channel_set_flag(switch_core_session_get_channel(session), CF_CNG_PLC); +} + SWITCH_STANDARD_APP(early_hangup_function) { switch_channel_set_flag(switch_core_session_get_channel(session), CF_EARLY_HANGUP); @@ -3497,6 +3502,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load) " []", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC); SWITCH_ADD_APP(app_interface, "verbose_events", "Make ALL Events verbose.", "Make ALL Events verbose.", verbose_events_function, "", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC); + SWITCH_ADD_APP(app_interface, "cng_plc", "Do PLC on CNG frames", "", cng_plc_function, "", + SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC); SWITCH_ADD_APP(app_interface, "early_hangup", "Enable early hangup", "", early_hangup_function, "", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC); SWITCH_ADD_APP(app_interface, "sleep", "Pause a channel", SLEEP_LONG_DESC, sleep_function, "", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_APP(app_interface, "delay_echo", "echo audio at a specified delay", "Delay n ms", delay_function, "", SAF_NONE); diff --git a/src/switch_core_io.c b/src/switch_core_io.c index c3113e9680..49956b3172 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -341,7 +341,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi } if (status == SWITCH_STATUS_SUCCESS) { - if (switch_channel_test_flag(session->channel, CF_JITTERBUFFER) && !session->plc) { + if ((switch_channel_test_flag(session->channel, CF_JITTERBUFFER) || switch_channel_test_flag(session->channel, CF_CNG_PLC)) + && !session->plc) { session->plc = plc_init(NULL); } diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 1600e2858f..60c0bae973 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -175,6 +175,7 @@ struct switch_rtp { uint32_t ts; uint32_t last_write_ts; uint32_t last_read_ts; + uint32_t last_cng_ts; uint32_t last_write_samplecount; uint32_t next_write_samplecount; switch_time_t last_write_timestamp; @@ -2164,11 +2165,19 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t { switch_status_t status = SWITCH_STATUS_FALSE; stfu_frame_t *jb_frame; + uint32_t ts; switch_assert(bytes); *bytes = sizeof(rtp_msg_t); status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock_input, 0, (void *) &rtp_session->recv_msg, bytes); + ts = ntohl(rtp_session->recv_msg.header.ts); + + if (ts && !rtp_session->jb && ts <= rtp_session->last_cng_ts) { + /* we already sent this frame..... */ + *bytes = 0; + return SWITCH_STATUS_SUCCESS; + } if (*bytes) { rtp_session->stats.inbound.raw_bytes += *bytes; @@ -2192,7 +2201,7 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t } - rtp_session->last_read_ts = ntohl(rtp_session->recv_msg.header.ts); + rtp_session->last_read_ts = ts; 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 && @@ -2920,7 +2929,8 @@ 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; - + rtp_session->last_cng_ts = rtp_session->last_read_ts + rtp_session->samples_per_interval; + 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;