[asterisk-commits] oej: branch oej/silence-detection-games-1.8 r407395 - /team/oej/silence-detec...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 5 06:59:27 CST 2014


Author: oej
Date: Wed Feb  5 06:59:23 2014
New Revision: 407395

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=407395
Log:
And here comes the soft dsp

Modified:
    team/oej/silence-detection-games-1.8/channels/chan_sip.c

Modified: team/oej/silence-detection-games-1.8/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/silence-detection-games-1.8/channels/chan_sip.c?view=diff&rev=407395&r1=407394&r2=407395
==============================================================================
--- team/oej/silence-detection-games-1.8/channels/chan_sip.c (original)
+++ team/oej/silence-detection-games-1.8/channels/chan_sip.c Wed Feb  5 06:59:23 2014
@@ -6129,6 +6129,11 @@
 		ast_free(p->stimer);
 		p->stimer = NULL;
 	}
+	/* Destroy the silence detector */
+	if (p->sildet) {
+		ast_dsp_free(p->sildet);
+		p->sildet = NULL;
+	}
 
 	if (sip_debug_test_pvt(p))
 		ast_verbose("Really destroying SIP dialog '%s' Method: %s\n", p->callid, sip_methods[p->method].text);
@@ -7453,6 +7458,43 @@
 	return res;
 }
 
+
+/*! \brief Activates a DSP to detect silence, something we can use to suppress silent RTP packets
+	and send CNG (comfort noise generation) requests instead */
+static int activate_silence_detection(struct sip_pvt *dialog)
+{
+	int res = 0;
+	ast_debug(3, "Checking if we need silence detection on %s\n", dialog->callid);
+
+	/* Check if we really want silence suppression */
+	if (!dialog || !dialog->rtp || !dialog->chan || !ast_test_flag(&dialog->flags[2], SIP_PAGE3_SILENCE_DETECTION)) {
+		return FALSE;
+	}
+	/* Allocate a new DSP */
+	if (!(dialog->sildet = ast_dsp_new())) {
+		ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
+		return FALSE;
+	}
+	ast_dsp_set_threshold(sildet, ast_dsp_get_threshold_from_settings(dialog->silencelevel));
+
+	/* Create the silence detector */
+	/* Put channel in the right codec mode: SLINEAR
+		This is for this first version. Later on we'll introduce a framehook that listens
+		to a converted frame stream. After that we want the codecs themselves (when involved)
+		to be able to tell us if something is silent without having to transcode first.
+	 */
+	if ((res = ast_set_read_format(dialog->chan, AST_FORMAT_SLINEAR)) < 0) {
+		ast_log(LOG_WARNING, "Unable to set channel to linear mode, giving up\n");
+		ast_dsp_free(dialog->sildet);
+		dialog->sildet = NULL;
+		return FALSE;
+	}
+
+	/* We now have a call where we have a DSP. The rest of the magic is happening somewhere else in chan_sip. */
+	ast_debug(3, "Activated silence detection on call %s\n", dialog->callid);
+	return TRUE;
+}
+
 /*!
  * \brief Initiate a call in the SIP channel
  *
@@ -7671,6 +7713,8 @@
 		manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate",
 			"Channel: %s\r\nUniqueid: %s\r\nChanneltype: %s\r\nSIPcallid: %s\r\nSIPfullcontact: %s\r\n",
 			tmp->name, tmp->uniqueid, "SIP", i->callid, i->fullcontact);
+
+	activate_silence_detection(i);
 
 	return tmp;
 }




More information about the asterisk-commits mailing list