Asterisk Pjsip Auto Dtmf Mode

Home » Asterisk Users » Asterisk Pjsip Auto Dtmf Mode
Asterisk Users 1 Comment

Hello Asterisk Users, I have been looking for similar auto dtmf mode implementation on pjsip, but didn’t see it coming, so I decided to give it a try. My basic plan was to do it as simple as possible with minimum changes because I am not familiar with all Asterisk code. My idea is to use rfc4733
settings, but when going over the codecs check if telephone-event appear and if not set the dtmf mode to inband on rtp instance. I would appreciate if someone would look at what I did and see if I didn’t do stupid things. If you think this is something you would like to add to one of the next releases I am willing to help – add the additional dtmf mode … I based my development on 13.1.0. The following are my changes:

In res/res_pjsip_sdp_rtp.c (I added session_media to get_codecs and used it in order to update dtmf settings on rtp instance when telephone-event is not included in the sdp):
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)
char fmt_param[256];
int tel_event = 0;
ast_copy_pj_str(name, &rtpmap->enc_name, sizeof(name));
if (strcmp(name,”telephone-event”) == 0) {
if (tel_event==0) {
ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_INBAND);
/* Get the packetization, if it exists */
get_codecs(session, stream, &codecs, session_media);

In res/res_pjsip_session.c (Just activated DSP also on RFC dtmf mode – I
didn’t find a way to test the rtp instance dtmf settiings because session_media pointer is not there. Any advice for doing so would be appreciated):
if (endpoint->dtmf == AST_SIP_DTMF_INBAND || endpoint->dtmf =AST_SIP_DTMF_RFC_4733) {

In channels/chan_pjsip.c (1 change similar to the above, and 2 more changes to send inband dtmf when rtp instance dtmf settings is inband)
if (session->endpoint->dtmf == AST_SIP_DTMF_INBAND ||
session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733) {
ast_dsp_set_features(session->dsp, DSP_FEATURE_DIGIT_DETECT);
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;

That’s it!!! It works fine for me. Any remarks / advice would be appreciated.


One thought on - Asterisk Pjsip Auto Dtmf Mode