[Asterisk-code-review] res pjsip: Add DTMF INFO Failback mode (asterisk[13])
Torrey Searle
asteriskteam at digium.com
Thu Jun 15 03:16:34 CDT 2017
Torrey Searle has uploaded this change for review. ( https://gerrit.asterisk.org/5842
Change subject: res_pjsip: Add DTMF INFO Failback mode
......................................................................
res_pjsip: Add DTMF INFO Failback mode
The existing auto dtmf mode reverts to inband if 4733 fails to be
negotiated. This patch adds a new mode auto_info which will
switch to INFO instead of inband if 4733 is not available.
Change-Id: Id185b11e84afd9191a2f269e8443019047765e91
---
M channels/chan_pjsip.c
M include/asterisk/res_pjsip.h
M res/res_pjsip.c
M res/res_pjsip/pjsip_configuration.c
M res/res_pjsip_sdp_rtp.c
5 files changed, 63 insertions(+), 18 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/42/5842/1
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 486a237..0c37020 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -1708,14 +1708,20 @@
}
ast_rtp_instance_dtmf_begin(media->rtp, digit);
- break;
+ break;
case AST_SIP_DTMF_AUTO:
- if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_INBAND)) {
- return -1;
- }
+ if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_INBAND)) {
+ return -1;
+ }
- ast_rtp_instance_dtmf_begin(media->rtp, digit);
- break;
+ ast_rtp_instance_dtmf_begin(media->rtp, digit);
+ break;
+ case AST_SIP_DTMF_AUTO_INFO:
+ if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_NONE)) {
+ return -1;
+ }
+ ast_rtp_instance_dtmf_begin(media->rtp, digit);
+ break;
case AST_SIP_DTMF_NONE:
break;
case AST_SIP_DTMF_INBAND:
@@ -1816,6 +1822,20 @@
int res = 0;
switch (channel->session->endpoint->dtmf) {
+ case AST_SIP_DTMF_AUTO_INFO:
+ {
+ if (!media || !media->rtp) {
+ return -1;
+ }
+ if (ast_rtp_instance_dtmf_mode_get(media->rtp) != AST_RTP_DTMF_MODE_NONE) {
+ ast_log(LOG_DTMF, "digit_end for AST_SIP_DTMF_AUTO_INFO --> sending DTMF via RFC_4733 \n");
+ ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration);
+ break;
+ }
+ // else continue for DTMF_INFO
+ ast_log(LOG_DTMF, "digit_end for AST_SIP_DTMF_AUTO_INFO --> sending DTMF via INFO.\n") ;
+ }
+
case AST_SIP_DTMF_INFO:
{
struct info_dtmf_data *dtmf_data = info_dtmf_data_alloc(channel->session, digit, duration);
@@ -1848,14 +1868,15 @@
}
ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration);
- break;
- case AST_SIP_DTMF_AUTO:
- if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_INBAND)) {
- return -1;
- }
+ break;
+ case AST_SIP_DTMF_AUTO:
+ if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_INBAND)) {
+ return -1;
+ }
- ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration);
- break;
+ ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration);
+ break;
+
case AST_SIP_DTMF_NONE:
break;
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index d4bd52c..66dff93 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -363,6 +363,7 @@
AST_SIP_DTMF_INFO,
/*! Use SIP 4733 if supported by the other side or INBAND if not */
AST_SIP_DTMF_AUTO,
+ AST_SIP_DTMF_AUTO_INFO,
};
/*!
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 6f1c19e..9e85a3d 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -229,6 +229,9 @@
<enum name="auto">
<para>DTMF is sent as RFC 4733 if the other side supports it or as INBAND if not.</para>
</enum>
+ <enum name="auto_info">
+ <para>DTMF is sent as RFC 4733 if the other side supports it or as SIP INFO if not.</para>
+ </enum>
</enumlist>
</description>
</configOption>
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index 77e31ab..62cd795 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -373,6 +373,8 @@
endpoint->dtmf = AST_SIP_DTMF_RFC_4733;
} else if (!strcasecmp(var->value, "inband")) {
endpoint->dtmf = AST_SIP_DTMF_INBAND;
+ } else if (!strcasecmp(var->value, "auto_info")) {
+ endpoint->dtmf = AST_SIP_DTMF_AUTO_INFO;
} else if (!strcasecmp(var->value, "info")) {
endpoint->dtmf = AST_SIP_DTMF_INFO;
} else if (!strcasecmp(var->value, "auto")) {
@@ -397,8 +399,11 @@
*buf = "inband"; break;
case AST_SIP_DTMF_INFO :
*buf = "info"; break;
- case AST_SIP_DTMF_AUTO :
+ case AST_SIP_DTMF_AUTO :
*buf = "auto"; break;
+ case AST_SIP_DTMF_AUTO_INFO :
+ *buf = "auto_info";
+ break;
default:
*buf = "none";
}
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index d39842f..579dfd0 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -246,7 +246,7 @@
ice->stop(session_media->rtp);
}
- if (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733 || session->endpoint->dtmf == AST_SIP_DTMF_AUTO) {
+ if (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733 || session->endpoint->dtmf == AST_SIP_DTMF_AUTO || session->endpoint->dtmf == AST_SIP_DTMF_AUTO_INFO) {
ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_RFC2833);
ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_DTMF, 1);
} else if (session->endpoint->dtmf == AST_SIP_DTMF_INBAND) {
@@ -269,7 +269,7 @@
}
static void get_codecs(struct ast_sip_session *session, const struct pjmedia_sdp_media *stream, struct ast_rtp_codecs *codecs,
- struct ast_sip_session_media *session_media)
+ struct ast_sip_session_media *session_media)
{
pjmedia_sdp_attr *attr;
pjmedia_sdp_rtpmap *rtpmap;
@@ -335,6 +335,20 @@
if (!tel_event && (session->endpoint->dtmf == AST_SIP_DTMF_AUTO)) {
ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_INBAND);
}
+
+ if (session->endpoint->dtmf == AST_SIP_DTMF_AUTO_INFO) {
+ if (tel_event) {
+ ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_RFC2833);
+ ast_log(LOG_DTMF, "Setting dtmf mode to RFC2833\n");
+ }
+ else {
+ ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_NONE);
+ ast_log(LOG_DTMF, "Setting dtmf mode to info\n");
+
+ }
+ }
+
+
/* Get the packetization, if it exists */
if ((attr = pjmedia_sdp_media_find_attr2(stream, "ptime", NULL))) {
unsigned long framing = pj_strtoul(pj_strltrim(&attr->value));
@@ -429,7 +443,8 @@
ast_set_read_format(session->channel, ast_channel_readformat(session->channel));
ast_set_write_format(session->channel, ast_channel_writeformat(session->channel));
}
- if ((session->endpoint->dtmf == AST_SIP_DTMF_AUTO)
+
+ if ( ((session->endpoint->dtmf == AST_SIP_DTMF_AUTO) || (session->endpoint->dtmf == AST_SIP_DTMF_AUTO_INFO) )
&& (ast_rtp_instance_dtmf_mode_get(session_media->rtp) == AST_RTP_DTMF_MODE_RFC2833)
&& (session->dsp)) {
dsp_features = ast_dsp_get_features(session->dsp);
@@ -1149,7 +1164,7 @@
pj_str_t stmp;
pjmedia_sdp_attr *attr;
int index = 0;
- int noncodec = (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733 || session->endpoint->dtmf == AST_SIP_DTMF_AUTO) ? AST_RTP_DTMF : 0;
+ int noncodec = (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733 || session->endpoint->dtmf == AST_SIP_DTMF_AUTO || session->endpoint->dtmf == AST_SIP_DTMF_AUTO_INFO) ? AST_RTP_DTMF : 0;
int min_packet_size = 0, max_packet_size = 0;
int rtp_code;
RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
--
To view, visit https://gerrit.asterisk.org/5842
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id185b11e84afd9191a2f269e8443019047765e91
Gerrit-Change-Number: 5842
Gerrit-PatchSet: 1
Gerrit-Owner: Torrey Searle <tsearle at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20170615/a7f219f3/attachment.html>
More information about the asterisk-code-review
mailing list