diff --git a/conf/freeswitch.xml b/conf/freeswitch.xml
index 8a63a3dee7..f5278ecce8 100644
--- a/conf/freeswitch.xml
+++ b/conf/freeswitch.xml
@@ -106,6 +106,8 @@
+
+
diff --git a/src/include/switch_rtp.h b/src/include/switch_rtp.h
index 2ea19fb535..53767cda89 100644
--- a/src/include/switch_rtp.h
+++ b/src/include/switch_rtp.h
@@ -348,6 +348,13 @@ SWITCH_DECLARE(uint32_t) switch_rtp_get_ssrc(switch_rtp_t *rtp_session);
*/
SWITCH_DECLARE(void) switch_rtp_set_private(switch_rtp_t *rtp_session, void *private_data);
+/*!
+ \brief Set the payload type to consider RFC2833 DTMF
+ \param rtp_session the RTP session to modify
+ \param te the payload type
+*/
+SWITCH_DECLARE(void) switch_rtp_set_telephony_event(switch_rtp_t *rtp_session, switch_payload_t te);
+
/*!
\brief Retrieve the private data from a given RTP session
\param rtp_session the RTP session to retrieve the data from
diff --git a/src/mod/endpoints/mod_exosip/mod_exosip.c b/src/mod/endpoints/mod_exosip/mod_exosip.c
index c188071cdc..7f8d6d2fba 100644
--- a/src/mod/endpoints/mod_exosip/mod_exosip.c
+++ b/src/mod/endpoints/mod_exosip/mod_exosip.c
@@ -109,6 +109,7 @@ static struct {
unsigned int flags;
switch_mutex_t *reg_mutex;
switch_core_db_t *db;
+ switch_payload_t te;
} globals;
struct private_object {
@@ -138,6 +139,7 @@ struct private_object {
char *realm;
switch_codec_interface_t *codecs[SWITCH_MAX_CODECS];
int num_codecs;
+ switch_payload_t te;
};
@@ -275,6 +277,7 @@ static switch_status_t exosip_on_init(switch_core_session_t *session)
char *dest_uri;
char *ip, *err;
switch_port_t sdp_port;
+ char dbuf[256];
/* do SIP Goodies... */
@@ -338,9 +341,11 @@ static switch_status_t exosip_on_init(switch_core_session_t *session)
tech_set_codecs(tech_pvt);
- sdp_message_m_payload_add(tech_pvt->local_sdp, 0, osip_strdup("101"));
- sdp_add_codec(tech_pvt->sdp_config, SWITCH_CODEC_TYPE_AUDIO, 101, "telephone-event", 8000, 0);
- sdp_message_a_attribute_add(tech_pvt->local_sdp, 0, "rtpmap", osip_strdup("101 telephone-event/8000"));
+ sprintf(dbuf, "%u", tech_pvt->te);
+ sdp_message_m_payload_add(tech_pvt->local_sdp, 0, osip_strdup(dbuf));
+ sdp_add_codec(tech_pvt->sdp_config, SWITCH_CODEC_TYPE_AUDIO, tech_pvt->te, "telephone-event", 8000, 0);
+ sprintf(dbuf, "%u telephone-event/8000", tech_pvt->te);
+ sdp_message_a_attribute_add(tech_pvt->local_sdp, 0, "rtpmap", osip_strdup(dbuf));
if (tech_pvt->num_codecs > 0) {
@@ -552,7 +557,11 @@ static switch_status_t activate_rtp(struct private_object *tech_pvt)
tech_pvt->ssrc = switch_rtp_get_ssrc(tech_pvt->rtp_session);
switch_set_flag(tech_pvt, TFLAG_RTP);
-
+
+ if (tech_pvt->te > 96) {
+ switch_rtp_set_telephony_event(tech_pvt->rtp_session, tech_pvt->te);
+ }
+
if ((vad_in && inb) || (vad_out && !inb)) {
switch_rtp_enable_vad(tech_pvt->rtp_session, tech_pvt->session, &tech_pvt->read_codec, SWITCH_VAD_FLAG_TALKING);
switch_set_flag(tech_pvt, TFLAG_VAD);
@@ -1017,6 +1026,7 @@ static switch_status_t exosip_outgoing_channel(switch_core_session_t *session, s
channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt);
tech_pvt->session = *new_session;
+ tech_pvt->te = globals.te;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
switch_core_session_destroy(new_session);
@@ -1131,6 +1141,7 @@ static switch_status_t exosip_create_call(eXosip_event_t * event)
char name[128];
char *dpayload, *dname = NULL, *drate = NULL;
char *remote_sdp_str = NULL;
+ char dbuf[256];
if ((session = switch_core_session_request(&exosip_endpoint_interface, NULL)) != 0) {
struct private_object *tech_pvt;
@@ -1149,6 +1160,7 @@ static switch_status_t exosip_create_call(eXosip_event_t * event)
channel = switch_core_session_get_channel(session);
switch_core_session_set_private(session, tech_pvt);
tech_pvt->session = session;
+ tech_pvt->te = globals.te;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
switch_core_session_destroy(&session);
@@ -1258,11 +1270,13 @@ static switch_status_t exosip_create_call(eXosip_event_t * event)
tech_set_codecs(tech_pvt);
sdp_message_init(&tech_pvt->local_sdp);
- sdp_message_m_payload_add(tech_pvt->local_sdp, 0, osip_strdup("101"));
- sdp_message_a_attribute_add(tech_pvt->local_sdp, 0, "rtpmap", osip_strdup("101 telephone-event/8000"));
- sdp_add_codec(tech_pvt->sdp_config, SWITCH_CODEC_TYPE_AUDIO, 101, "telephone-event", 8000, 0);
-
+ sprintf(dbuf, "%u", tech_pvt->te);
+ sdp_message_m_payload_add(tech_pvt->local_sdp, 0, osip_strdup(dbuf));
+ sdp_add_codec(tech_pvt->sdp_config, SWITCH_CODEC_TYPE_AUDIO, tech_pvt->te, "telephone-event", 8000, 0);
+ sprintf(dbuf, "%u telephone-event/8000", tech_pvt->te);
+ sdp_message_a_attribute_add(tech_pvt->local_sdp, 0, "rtpmap", osip_strdup(dbuf));
+
if (tech_pvt->num_codecs > 0) {
int i;
static const switch_codec_implementation_t *imp;
@@ -1466,18 +1480,25 @@ static switch_status_t parse_sdp_media(struct private_object *tech_pvt, sdp_medi
if ((rate = strchr(name, '/'))) {
*rate++ = '\0';
}
- pt = atoi(payload);
+ pt = (switch_payload_t)atoi(payload);
r = atoi(rate);
+
+ if (!strcasecmp(name, "telephone-event")) {
+ tech_pvt->te = pt;
+ attr = NULL;
+ pos++;
+ continue;
+ }
for(i = 0; !match && i < tech_pvt->num_codecs; i++) {
const switch_codec_implementation_t *imp;
-
+
if (pt < 97) {
match = (pt == tech_pvt->codecs[i]->ianacode) ? 1 : 0;
} else {
match = strcasecmp(name, tech_pvt->codecs[i]->iananame) ? 0 : 1;
}
-
+
if (match) {
match = 0;
@@ -1901,6 +1922,7 @@ static int config_exosip(int reload)
}
globals.dtmf_duration = 100;
+ globals.te = 101;
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
@@ -1913,6 +1935,8 @@ static int config_exosip(int reload)
switch_set_flag(&globals, TFLAG_TIMER);
} else if (!strcmp(var, "port")) {
globals.port = atoi(val);
+ } else if (!strcmp(var, "rfc2833-pt")) {
+ globals.te = (switch_payload_t) atoi(val);
} else if (!strcmp(var, "vad")) {
if (!strcasecmp(val, "in")) {
switch_set_flag(&globals, TFLAG_VAD_IN);
diff --git a/src/switch_rtp.c b/src/switch_rtp.c
index 0669c29297..5a46d68865 100644
--- a/src/switch_rtp.c
+++ b/src/switch_rtp.c
@@ -169,6 +169,7 @@ struct switch_rtp {
struct switch_rtp_vad_data vad_data;
struct switch_rtp_rfc2833_data dtmf_data;
uint8_t mini;
+ switch_payload_t te;
};
static int global_init = 0;
@@ -379,6 +380,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session
rtp_session->pool = pool;
rtp_session->flags = flags;
+ rtp_session->te = 101;
switch_mutex_init(&rtp_session->dtmf_data.dtmf_mutex, SWITCH_MUTEX_NESTED, rtp_session->pool);
switch_buffer_create(rtp_session->pool, &rtp_session->dtmf_data.dtmf_buffer, 128);
/* for from address on recvfrom calls */
@@ -506,6 +508,12 @@ SWITCH_DECLARE(switch_rtp_t *)switch_rtp_new(char *rx_host,
return rtp_session;
}
+SWITCH_DECLARE(void) switch_rtp_set_telephony_event(switch_rtp_t *rtp_session, switch_payload_t te)
+{
+ if (te > 96) {
+ rtp_session->te = te;
+ }
+}
SWITCH_DECLARE(switch_status_t) switch_rtp_activate_ice(switch_rtp_t *rtp_session, char *login, char *rlogin)
{
@@ -627,7 +635,7 @@ static void do_2833(switch_rtp_t *rtp_session)
for (x = 0; x < loops; x++) {
switch_rtp_write_manual(rtp_session,
- rtp_session->dtmf_data.out_digit_packet, 4, 0, 101, rtp_session->dtmf_data.timestamp_dtmf,
+ rtp_session->dtmf_data.out_digit_packet, 4, 0, rtp_session->te, rtp_session->dtmf_data.timestamp_dtmf,
rtp_session->dtmf_data.out_digit_seq++, &flags);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send %s packet for [%c] ts=%d sofar=%u dur=%d\n",
loops == 1 ? "middle" : "end",
@@ -661,7 +669,7 @@ static void do_2833(switch_rtp_t *rtp_session)
rtp_session->dtmf_data.out_digit_packet,
4,
1,
- 101,
+ rtp_session->te,
rtp_session->dtmf_data.timestamp_dtmf,
rtp_session->dtmf_data.out_digit_seq++,
&flags);
@@ -684,6 +692,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
switch_size_t bytes;
switch_status_t status;
+
for(;;) {
bytes = sizeof(rtp_msg_t);
status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *)&rtp_session->recv_msg, &bytes);
@@ -813,7 +822,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
}
/* RFC2833 ... TBD try harder to honor the duration etc.*/
- if (rtp_session->recv_msg.header.pt == 101) {
+ if (rtp_session->recv_msg.header.pt == rtp_session->te) {
unsigned char *packet = (unsigned char *) rtp_session->recv_msg.body;
int end = packet[1]&0x80;
int duration = (packet[2]<<8) + packet[3];