[asterisk-commits] branch bweschke/bug_5374 - r7355 in /team/bweschke/bug_5374: ./ apps/ channel...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Dec 5 23:12:07 CST 2005


Author: bweschke
Date: Mon Dec  5 23:12:04 2005
New Revision: 7355

URL: http://svn.digium.com/view/asterisk?rev=7355&view=rev
Log:
 Initial commit with the necessary changes made to keep the original functionality from 5374 current with /trunk


Modified:
    team/bweschke/bug_5374/apps/app_milliwatt.c
    team/bweschke/bug_5374/apps/app_sms.c
    team/bweschke/bug_5374/asterisk.8
    team/bweschke/bug_5374/asterisk.c
    team/bweschke/bug_5374/channel.c
    team/bweschke/bug_5374/channels/chan_sip.c
    team/bweschke/bug_5374/doc/README.asterisk.conf
    team/bweschke/bug_5374/include/asterisk/channel.h
    team/bweschke/bug_5374/include/asterisk/options.h

Modified: team/bweschke/bug_5374/apps/app_milliwatt.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/apps/app_milliwatt.c?rev=7355&r1=7354&r2=7355&view=diff
==============================================================================
--- team/bweschke/bug_5374/apps/app_milliwatt.c (original)
+++ team/bweschke/bug_5374/apps/app_milliwatt.c Mon Dec  5 23:12:04 2005
@@ -75,13 +75,22 @@
 	struct ast_frame wf;
 	unsigned char waste[AST_FRIENDLY_OFFSET];
 	unsigned char buf[640];
-	int i,*indexp = (int *) data;
+	const int maxsamples = sizeof (buf) / sizeof (buf[0]);
+	int i, *indexp = (int *) data;
 
-	if (len > sizeof(buf))
+	/* Instead of len, use samples, because channel.c generator_force 
+	 * generate(chan, tmp, 0, 160) ignores len. In any case, len is  
+	 * a multiple of samples, given by number of samples times bytes per
+	 * sample. In the case of ulaw, len = samples. for signed linear 
+	 * len = 2 * samples                                                 */
+
+	if (samples > maxsamples)
 	{
-		ast_log(LOG_WARNING,"Only doing %d bytes (%d bytes requested)\n",(int)sizeof(buf),len);
-		len = sizeof(buf);
+		ast_log(LOG_WARNING, "Only doing %d samples (%d requested)\n", maxsamples, samples);
+		samples = maxsamples;
 	}
+	len = samples * sizeof (buf[0]);
+
 	waste[0] = 0; /* make compiler happy */
 	wf.frametype = AST_FRAME_VOICE;
 	wf.subclass = AST_FORMAT_ULAW;
@@ -89,7 +98,7 @@
 	wf.mallocd = 0;
 	wf.data = buf;
 	wf.datalen = len;
-	wf.samples = wf.datalen;
+	wf.samples = samples;
 	wf.src = "app_milliwatt";
 	wf.delivery.tv_sec = 0;
 	wf.delivery.tv_usec = 0;

Modified: team/bweschke/bug_5374/apps/app_sms.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/apps/app_sms.c?rev=7355&r1=7354&r2=7355&view=diff
==============================================================================
--- team/bweschke/bug_5374/apps/app_sms.c (original)
+++ team/bweschke/bug_5374/apps/app_sms.c Mon Dec  5 23:12:04 2005
@@ -1179,32 +1179,31 @@
 {
 	struct ast_frame f = { 0 };
 	unsigned char waste[AST_FRIENDLY_OFFSET];
+#define MAXSAMPLES (800)
 #ifdef OUTALAW
-	unsigned char buf[800];
+	unsigned char buf[MAXSAMPLES];
 #else
-	signed short buf[800];
+	signed short buf[MAXSAMPLES];
 #endif
+#define SAMPLE2LEN (sizeof (buf[0]))
 	sms_t *h = data;
 	int i;
 
-	if (len > sizeof (buf)) {
-		ast_log (LOG_WARNING, "Only doing %d bytes (%d bytes requested)\n", (int)(sizeof (buf) / sizeof (signed short)), len);
-		len = sizeof (buf);
-#ifdef OUTALAW
-		samples = len;
-#else
-		samples = len / 2;
-#endif
-	}
-	waste[0] = 0;					 /* make compiler happy */
+	if (samples > MAXSAMPLES) {
+		ast_log (LOG_WARNING, "Only doing %d samples (%d requested)\n",
+			 MAXSAMPLES, samples);
+		samples = MAXSAMPLES;
+	}
+	len = samples * SAMPLE2LEN;
+
+	waste[0] = 0;				 /* make compiler happy */
 	f.frametype = AST_FRAME_VOICE;
 #ifdef OUTALAW
 	f.subclass = AST_FORMAT_ALAW;
-	f.datalen = samples;
 #else
 	f.subclass = AST_FORMAT_SLINEAR;
-	f.datalen = samples * 2;
 #endif
+	f.datalen = len;
 	f.offset = AST_FRIENDLY_OFFSET;
 	f.mallocd = 0;
 	f.data = buf;
@@ -1256,6 +1255,8 @@
 		return -1;
 	}
 	return 0;
+#undef SAMPLE2LEN
+#undef MAXSAMPLES
 }
 
 static void sms_process (sms_t * h, int samples, signed short *data)

Modified: team/bweschke/bug_5374/asterisk.8
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/asterisk.8?rev=7355&r1=7354&r2=7355&view=diff
==============================================================================
--- team/bweschke/bug_5374/asterisk.8 (original)
+++ team/bweschke/bug_5374/asterisk.8 Mon Dec  5 23:12:04 2005
@@ -59,6 +59,9 @@
 .TP
 \fB-f\fR
 Do not fork or detach from controlling terminal.
+.TP
+\fB-s\fR
+Enable silence suppression if timing device is available.
 .TP
 \fB-g\fR
 Remove resource limit on core size, thus forcing Asterisk to dump

Modified: team/bweschke/bug_5374/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/asterisk.c?rev=7355&r1=7354&r2=7355&view=diff
==============================================================================
--- team/bweschke/bug_5374/asterisk.c (original)
+++ team/bweschke/bug_5374/asterisk.c Mon Dec  5 23:12:04 2005
@@ -1875,6 +1875,9 @@
 		/* Transmit SLINEAR silence while a channel is being recorded */
 		} else if (!strcasecmp(v->name, "transmit_silence_during_record")) {
 			ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_TRANSMIT_SILENCE);
+		/* Enable/Disable Silence Suppression */
+		} else if (!strcasecmp(v->name, "silence_suppression")) {
+			ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_SILENCE_SUPPRESSION);
 		} else if (!strcasecmp(v->name, "maxcalls")) {
 			if ((sscanf(v->value, "%d", &option_maxcalls) != 1) || (option_maxcalls < 0)) {
 				option_maxcalls = 0;
@@ -1951,7 +1954,7 @@
 	}
 	*/
 	/* Check for options */
-	while((c=getopt(argc, argv, "tThfdvVqprRgcinx:U:G:C:L:M:")) != -1) {
+	while((c=getopt(argc, argv, "tThfdvVqprRgcinsx:U:G:C:L:M:")) != -1) {
 		switch(c) {
 		case 'd':
 			option_debug++;
@@ -1989,6 +1992,9 @@
 			break;
 		case 'q':
 			ast_set_flag(&ast_options, AST_OPT_FLAG_QUIET);
+			break;
+		case 's':
+			ast_set_flag(&ast_options, AST_OPT_SILENCE_SUPPRESSION);
 			break;
 		case 't':
 			ast_set_flag(&ast_options, AST_OPT_FLAG_CACHE_RECORD_FILES);

Modified: team/bweschke/bug_5374/channel.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/channel.c?rev=7355&r1=7354&r2=7355&view=diff
==============================================================================
--- team/bweschke/bug_5374/channel.c (original)
+++ team/bweschke/bug_5374/channel.c Mon Dec  5 23:12:04 2005
@@ -1773,6 +1773,14 @@
 	return 0; /* Time is up */
 }
 
+int ast_silence_suppression_enabled(struct ast_channel *chan)
+{
+	int ret = ast_opt_silence_suppression && chan->timingfd > -1;
+	if (option_verbose > 2)
+		ast_verbose(VERBOSE_PREFIX_3 "Silence suppression is %s (ast_opt_silence_suppression=%d chan->timingfd=%d)\n", ret? "enabled": "disabled", ast_opt_silence_suppression, chan->timingfd);
+	return ret;
+}
+
 struct ast_frame *ast_read(struct ast_channel *chan)
 {
 	struct ast_frame *f = NULL;
@@ -1960,18 +1968,13 @@
 		ast_cdr_answer(chan->cdr);
 	} 
 
-	/* Run any generator sitting on the line */
-	if (f && (f->frametype == AST_FRAME_VOICE) && chan->generatordata) {
-		/* Mask generator data temporarily and apply.  If there is a timing function, it
-		   will be calling the generator instead */
+	/* Run generator sitting on the line if timing device not available     *
+	 * and synchronous generation of outgoing frames is necessary           */
+	if (f && (f->frametype == AST_FRAME_VOICE) && chan->generatordata && !ast_silence_suppression_enabled(chan)) {
 		void *tmp;
 		int res;
 		int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples);
 
-		if (chan->timingfunc) {
-			ast_log(LOG_DEBUG, "Generator got voice, switching to phase locked mode\n");
-			ast_settimeout(chan, 0, NULL, NULL);
-		}
 		tmp = chan->generatordata;
 		chan->generatordata = NULL;
 		generate = chan->generator->generate;
@@ -1980,11 +1983,6 @@
 		if (res) {
 			ast_log(LOG_DEBUG, "Auto-deactivating generator\n");
 			ast_deactivate_generator(chan);
-		}
-	} else if (f && (f->frametype == AST_FRAME_CNG)) {
-		if (chan->generator && !chan->timingfunc && (chan->timingfd > -1)) {
-			ast_log(LOG_DEBUG, "Generator got CNG, switching to zap timed mode\n");
-			ast_settimeout(chan, 160, generator_force, chan);
 		}
 	}
 	/* High bit prints debugging */

Modified: team/bweschke/bug_5374/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/channels/chan_sip.c?rev=7355&r1=7354&r2=7355&view=diff
==============================================================================
--- team/bweschke/bug_5374/channels/chan_sip.c (original)
+++ team/bweschke/bug_5374/channels/chan_sip.c Mon Dec  5 23:12:04 2005
@@ -4451,7 +4451,8 @@
 				    debug);
 	}
 
-	ast_build_string(&a_audio_next, &a_audio_left, "a=silenceSupp:off - - - -\r\n");
+	if (!ast_silence_suppression_enabled(p->owner))
+		ast_build_string(&a_audio_next, &a_audio_left, "a=silenceSupp:off - - - -\r\n");
 
 	if ((m_audio_left < 2) || (m_video_left < 2) || (a_audio_left == 0) || (a_video_left == 0))
 		ast_log(LOG_WARNING, "SIP SDP may be truncated due to undersized buffer!!\n");

Modified: team/bweschke/bug_5374/doc/README.asterisk.conf
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/doc/README.asterisk.conf?rev=7355&r1=7354&r2=7355&view=diff
==============================================================================
--- team/bweschke/bug_5374/doc/README.asterisk.conf (original)
+++ team/bweschke/bug_5374/doc/README.asterisk.conf Mon Dec  5 23:12:04 2005
@@ -52,6 +52,7 @@
 runuser = asterisk				; User to run asterisk as (-U) NOTE: will require changes to
 						; directory and device permisions
 rungroup = asterisk				; Group to run asterisk as (-G)
+silence_supression = yes | no			; Enable silence suppression support (-s)
 
 ;These options have no command line equivalent
 cache_record_files = yes | no			; Cache record() files in another directory until completion

Modified: team/bweschke/bug_5374/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/include/asterisk/channel.h?rev=7355&r1=7354&r2=7355&view=diff
==============================================================================
--- team/bweschke/bug_5374/include/asterisk/channel.h (original)
+++ team/bweschke/bug_5374/include/asterisk/channel.h Mon Dec  5 23:12:04 2005
@@ -1100,6 +1100,16 @@
  */
 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
 
+/*!
+  \brief Check if the channel can run in silence suppression mode.
+  \param chan The channel to check
+  \return boolean
+
+  This function will return 1 if silence suppression is enabled and the timing
+  device is available.
+ */
+int ast_silence_suppression_enabled(struct ast_channel *chan);
+
 /* Misc. functions below */
 
 /* Helper function for migrating select to poll */

Modified: team/bweschke/bug_5374/include/asterisk/options.h
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/include/asterisk/options.h?rev=7355&r1=7354&r2=7355&view=diff
==============================================================================
--- team/bweschke/bug_5374/include/asterisk/options.h (original)
+++ team/bweschke/bug_5374/include/asterisk/options.h Mon Dec  5 23:12:04 2005
@@ -68,7 +68,9 @@
 	/*! Transmit Silence during Record() */
 	AST_OPT_FLAG_TRANSMIT_SILENCE = (1 << 17),
 	/*! Suppress some warnings */
-	AST_OPT_FLAG_DONT_WARN = (1 << 18)
+	AST_OPT_FLAG_DONT_WARN = (1 << 18),
+	/*! Support Silence Suppression */
+	AST_OPT_SILENCE_SUPPRESSION = (1 << 19)
 };
 
 #define ast_opt_exec_includes		ast_test_flag(&ast_options, AST_OPT_FLAG_EXEC_INCLUDES)
@@ -90,6 +92,7 @@
 #define ast_opt_reconnect		ast_test_flag(&ast_options, AST_OPT_FLAG_RECONNECT)
 #define ast_opt_transmit_silence	ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSMIT_SILENCE)
 #define ast_opt_dont_warn		ast_test_flag(&ast_options, AST_OPT_FLAG_DONT_WARN)
+#define ast_opt_silence_suppression	ast_test_flag(&ast_options, AST_OPT_SILENCE_SUPPRESSION)
 
 extern struct ast_flags ast_options;
 



More information about the asterisk-commits mailing list