[asterisk-commits] qwell: branch group/pimp_my_sip r386304 - in /team/group/pimp_my_sip: channel...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 22 12:50:49 CDT 2013


Author: qwell
Date: Mon Apr 22 12:50:44 2013
New Revision: 386304

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386304
Log:
Add support for DTMF via SIP INFO.

For sending, set dtmfmode=info in res_sip.conf.
For receiving, load res_sip_dtmf_info.so.

(closes issue ASTERISK-21261)

Review: https://reviewboard.asterisk.org/r/2455/

Added:
    team/group/pimp_my_sip/res/res_sip_dtmf_info.c
      - copied unchanged from r386303, team/qwell/pimp_my_dtmf/res/res_sip_dtmf_info.c
Modified:
    team/group/pimp_my_sip/channels/chan_gulp.c

Modified: team/group/pimp_my_sip/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/channels/chan_gulp.c?view=diff&rev=386304&r1=386303&r2=386304
==============================================================================
--- team/group/pimp_my_sip/channels/chan_gulp.c (original)
+++ team/group/pimp_my_sip/channels/chan_gulp.c Mon Apr 22 12:50:44 2013
@@ -824,6 +824,67 @@
 	return res;
 }
 
+struct info_dtmf_data {
+	struct ast_sip_session *session;
+	char digit;
+	unsigned int duration;
+};
+
+static void info_dtmf_data_destroy(void *obj)
+{
+	struct info_dtmf_data *dtmf_data = obj;
+	ao2_ref(dtmf_data->session, -1);
+}
+
+static struct info_dtmf_data *info_dtmf_data_alloc(struct ast_sip_session *session, char digit, unsigned int duration)
+{
+	struct info_dtmf_data *dtmf_data = ao2_alloc(sizeof(*dtmf_data), info_dtmf_data_destroy);
+	if (!dtmf_data) {
+		return NULL;
+	}
+	ao2_ref(session, +1);
+	dtmf_data->session = session;
+	dtmf_data->digit = digit;
+	dtmf_data->duration = duration;
+	return dtmf_data;
+}
+
+static int transmit_info_dtmf(void *data)
+{
+	RAII_VAR(struct info_dtmf_data *, dtmf_data, data, ao2_cleanup);
+
+	struct ast_sip_session *session = dtmf_data->session;
+	struct pjsip_tx_data *tdata;
+
+	RAII_VAR(struct ast_str *, body_text, NULL, ast_free_ptr);
+
+	struct ast_sip_body body = {
+		.type = "application",
+		.subtype = "dtmf-relay",
+	};
+
+	if (!(body_text = ast_str_create(32))) {
+		ast_log(LOG_ERROR, "Could not allocate buffer for INFO DTMF.\n");
+		return -1;
+	}
+	ast_str_set(&body_text, 0, "Signal=%c\r\nDuration=%u\r\n", dtmf_data->digit, dtmf_data->duration);
+
+	body.body_text = ast_str_buffer(body_text);
+
+	if (ast_sip_create_request("INFO", session->inv_session->dlg, session->endpoint, NULL, &tdata)) {
+		ast_log(LOG_ERROR, "Could not create DTMF INFO request\n");
+		return -1;
+	}
+	if (ast_sip_add_body(tdata, &body)) {
+		ast_log(LOG_ERROR, "Could not add body to DTMF INFO request\n");
+		pjsip_tx_data_dec_ref(tdata);
+		return -1;
+	}
+	ast_sip_session_send_request(session, tdata);
+
+	return 0;
+}
+
 /*! \brief Function called by core to stop a DTMF digit */
 static int gulp_digit_end(struct ast_channel *ast, char digit, unsigned int duration)
 {
@@ -834,8 +895,20 @@
 
 	switch (session->endpoint->dtmf) {
 	case AST_SIP_DTMF_INFO:
-		/* TODO: Send INFO dtmf here */
-		break;
+	{
+		struct info_dtmf_data *dtmf_data = info_dtmf_data_alloc(session, digit, duration);
+
+		if (!dtmf_data) {
+			return -1;
+		}
+
+		if (ast_sip_push_task(session->serializer, transmit_info_dtmf, dtmf_data)) {
+			ast_log(LOG_WARNING, "Error sending DTMF via INFO.\n");
+			ao2_cleanup(dtmf_data);
+			return -1;
+		}
+		break;
+	}
 	case AST_SIP_DTMF_RFC_4733:
 		if (!media || !media->rtp) {
 			return -1;




More information about the asterisk-commits mailing list