drop rtp frame that was already replaced with a cng frame

This commit is contained in:
Anthony Minessale 2010-12-22 20:38:57 -06:00
parent 751e0291ee
commit 34a0ca5096
4 changed files with 22 additions and 3 deletions

View File

@ -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;

View File

@ -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)
"<ip> <acl | cidr> [<hangup_cause>]", 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, "<pausemilliseconds>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_APP(app_interface, "delay_echo", "echo audio at a specified delay", "Delay n ms", delay_function, "<delay ms>", SAF_NONE);

View File

@ -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);
}

View File

@ -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;