[asterisk-commits] oej: branch oej/silence-detection-games-1.8 r411914 - in /team/oej/silence-de...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 8 03:50:47 CDT 2014


Author: oej
Date: Tue Apr  8 03:50:32 2014
New Revision: 411914

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=411914
Log:
Implementing AST_FRAME_DROP for frames that should not get out on the wire.

Modified:
    team/oej/silence-detection-games-1.8/include/asterisk/frame.h
    team/oej/silence-detection-games-1.8/main/audiohook.c
    team/oej/silence-detection-games-1.8/main/silencedetection.c
    team/oej/silence-detection-games-1.8/res/res_rtp_asterisk.c

Modified: team/oej/silence-detection-games-1.8/include/asterisk/frame.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/silence-detection-games-1.8/include/asterisk/frame.h?view=diff&rev=411914&r1=411913&r2=411914
==============================================================================
--- team/oej/silence-detection-games-1.8/include/asterisk/frame.h (original)
+++ team/oej/silence-detection-games-1.8/include/asterisk/frame.h Tue Apr  8 03:50:32 2014
@@ -124,6 +124,8 @@
 	AST_FRAME_MODEM,	
 	/*! DTMF begin event, subclass is the digit */
 	AST_FRAME_DTMF_BEGIN,
+	/*! A frame that needs to be killed, dropped or just silently ignored */
+	AST_FRAME_DROP,
 };
 #define AST_FRAME_DTMF AST_FRAME_DTMF_END
 

Modified: team/oej/silence-detection-games-1.8/main/audiohook.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/silence-detection-games-1.8/main/audiohook.c?view=diff&rev=411914&r1=411913&r2=411914
==============================================================================
--- team/oej/silence-detection-games-1.8/main/audiohook.c (original)
+++ team/oej/silence-detection-games-1.8/main/audiohook.c Tue Apr  8 03:50:32 2014
@@ -21,7 +21,6 @@
  * \brief Audiohooks Architecture
  *
  * \author Joshua Colp <jcolp at digium.com>
- * \author Olle E. Johansson <oej at edvina.net> - the silence detection hook
  */
 
 /*** MODULEINFO

Modified: team/oej/silence-detection-games-1.8/main/silencedetection.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/silence-detection-games-1.8/main/silencedetection.c?view=diff&rev=411914&r1=411913&r2=411914
==============================================================================
--- team/oej/silence-detection-games-1.8/main/silencedetection.c (original)
+++ team/oej/silence-detection-games-1.8/main/silencedetection.c Tue Apr  8 03:50:32 2014
@@ -18,12 +18,16 @@
 
 /*! \file
  *
- * \brief Silence Detection audiohooks
+ * \brief Silence Detection and suppression audiohooks
  *
  * \author Olle E. Johansson <oej at edvina.net>
  *
  *
- * This is an internal API and have no functions, applications or other cool stuff to expose.
+ * This is an internal API and have no functions, applications or other cool stuff to expose to the admin.
+ * 
+ * If this audiohook is applied, we listen for silence and when silence has been detected for a certain 
+ * number of frames in a row, we replace the frame with a CNG frame and then (want to) drop frames until
+ * we have audio again. Right now the code just clears the frame.
  *
  * \note This code only handles audio streams 
  * 	For silence in video, check Ingmar Bergman movies on Wikipedia. We have
@@ -110,8 +114,6 @@
 	}
 
 	sildet = datastore->data;
-	ast_debug(9, "Audiohook grabbed a frame. Mmmmmm \n");
-
 
 	/* If this is audio then allow them to increase/decrease the gains */
 	if (frame->frametype == AST_FRAME_VOICE) {
@@ -132,13 +134,24 @@
 				sildet->detect = 0;		/* No more silence */
 			} else {
 				if (option_debug && sildet->silencecounter > 0) {
-					ast_debug(8, "          ++++ Silence continues %d ++++ on chan %s\n", sildet->silencecounter, chan->name);
+					ast_debug(9, "          ++++ Silence continues %d ++++ on chan %s\n", sildet->silencecounter, chan->name);
 				}
 				sildet->silencecounter++;
+				ast_frame_clear(frame);		/* Should really be dropped. */
+				frame->frametype = AST_FRAME_DROP;
+				ast_channel_unlock(chan);
+				return 1;	/* Return TRUE since we manipulated the frame */
 			}
 			if (sildet->detect == 0 && sildet->silencecounter > sildet->silenceframes) {
 				ast_debug(8, "          ++++ Silence suppression should start now ++++ on chan %s\n", chan->name);
 				sildet->detect = 1;
+				ast_frame_clear(frame);
+				frame->frametype = AST_FRAME_CNG;
+        			frame->subclass.integer = data[0] & 0x7f;
+        			frame->samples = 0;
+        			rframe->delivery.tv_usec = fram.delivery.tv_sec = 0;
+				ast_channel_unlock(chan);
+				return 1;	/* Return TRUE since we manipulated the frame */
 			}
 			/* Do not touch the frame yet */
 		}

Modified: team/oej/silence-detection-games-1.8/res/res_rtp_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/silence-detection-games-1.8/res/res_rtp_asterisk.c?view=diff&rev=411914&r1=411913&r2=411914
==============================================================================
--- team/oej/silence-detection-games-1.8/res/res_rtp_asterisk.c (original)
+++ team/oej/silence-detection-games-1.8/res/res_rtp_asterisk.c Tue Apr  8 03:50:32 2014
@@ -1344,6 +1344,11 @@
 		return 0;
 	}
 
+	if (frame->frametype != AST_FRAME_DROP) {
+		/* This is a victim of silence suppression. Just ignore it. */
+		return 0;
+	}
+
 	/* If there is no data length we can't very well send the packet */
 	if (!frame->datalen) {
 		ast_debug(1, "Received frame with no data for RTP instance '%p' so dropping frame\n", instance);
@@ -1753,9 +1758,11 @@
 	/* Convert comfort noise into audio with various codecs.  Unfortunately this doesn't
 	   totally help us out becuase we don't have an engine to keep it going and we are not
 	   guaranteed to have it every 20ms or anything */
-	if (rtpdebug)
+	if (rtpdebug) {
 		ast_debug(0, "- RTP 3389 Comfort noise event: Level %" PRId64 " (len = %d)\n", rtp->lastrxformat, len);
-
+	}
+
+#ifdef OLD
 	if (ast_test_flag(rtp, FLAG_3389_WARNING)) {
 		struct ast_sockaddr remote_address = { {0,} };
 
@@ -1765,10 +1772,12 @@
 			ast_sockaddr_stringify(&remote_address));
 		ast_set_flag(rtp, FLAG_3389_WARNING);
 	}
+#endif
 
 	/* Must have at least one byte */
-	if (!len)
+	if (!len) {
 		return NULL;
+	}
 	if (len < 24) {
 		rtp->f.data.ptr = rtp->rawdata + AST_FRIENDLY_OFFSET;
 		rtp->f.datalen = len - 1;




More information about the asterisk-commits mailing list