mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 18:55:19 +00:00 
			
		
		
		
	Merged revisions 149062 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ................ r149062 | tilghman | 2008-10-14 15:16:48 -0500 (Tue, 14 Oct 2008) | 13 lines Merged revisions 149061 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r149061 | tilghman | 2008-10-14 15:09:06 -0500 (Tue, 14 Oct 2008) | 6 lines Check correct values in the return of ast_waitfor(); also, get rid of a possible memory leak. (closes issue #13658) Reported by: explidous Patch by: me ........ ................ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@149063 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
		| @@ -81,7 +81,7 @@ static char *descrip_noise = | |||||||
| "Wait for Noise: The same as Wait for Silance but waits for noise that is above the threshold specified\n"; | "Wait for Noise: The same as Wait for Silance but waits for noise that is above the threshold specified\n"; | ||||||
|  |  | ||||||
| static int do_waiting(struct ast_channel *chan, int timereqd, time_t waitstart, int timeout, int wait_for_silence) { | static int do_waiting(struct ast_channel *chan, int timereqd, time_t waitstart, int timeout, int wait_for_silence) { | ||||||
| 	struct ast_frame *f; | 	struct ast_frame *f = NULL; | ||||||
| 	int dsptime = 0; | 	int dsptime = 0; | ||||||
| 	int rfmt = 0; | 	int rfmt = 0; | ||||||
| 	int res = 0; | 	int res = 0; | ||||||
| @@ -93,57 +93,50 @@ static int do_waiting(struct ast_channel *chan, int timereqd, time_t waitstart, | |||||||
| 				wait_for_silence ? ast_dsp_silence : ast_dsp_noise; | 				wait_for_silence ? ast_dsp_silence : ast_dsp_noise; | ||||||
|  |  | ||||||
| 	rfmt = chan->readformat; /* Set to linear mode */ | 	rfmt = chan->readformat; /* Set to linear mode */ | ||||||
| 	res = ast_set_read_format(chan, AST_FORMAT_SLINEAR); | 	if ((res = ast_set_read_format(chan, AST_FORMAT_SLINEAR)) < 0) { | ||||||
| 	if (res < 0) { |  | ||||||
| 		ast_log(LOG_WARNING, "Unable to set channel to linear mode, giving up\n"); | 		ast_log(LOG_WARNING, "Unable to set channel to linear mode, giving up\n"); | ||||||
| 		return -1; | 		return -1; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	sildet = ast_dsp_new(); /* Create the silence detector */ | 	/* Create the silence detector */ | ||||||
| 	if (!sildet) { | 	if (!(sildet = ast_dsp_new())) { | ||||||
| 		ast_log(LOG_WARNING, "Unable to create silence detector :(\n"); | 		ast_log(LOG_WARNING, "Unable to create silence detector :(\n"); | ||||||
| 		return -1; | 		return -1; | ||||||
| 	} | 	} | ||||||
| 	ast_dsp_set_threshold(sildet, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE)); | 	ast_dsp_set_threshold(sildet, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE)); | ||||||
|  |  | ||||||
| 	/* Await silence... */ | 	/* Await silence... */ | ||||||
| 	f = NULL; | 	for (;;) { | ||||||
| 	for(;;) { |  | ||||||
| 		/* Start with no silence received */ | 		/* Start with no silence received */ | ||||||
| 		dsptime = 0; | 		dsptime = 0; | ||||||
|  |  | ||||||
| 		res = ast_waitfor(chan, timereqd); | 		res = ast_waitfor(chan, timereqd); | ||||||
|  |  | ||||||
| 		/* Must have gotten a hangup; let's exit */ | 		/* Must have gotten a hangup; let's exit */ | ||||||
| 		if (res <= 0) { | 		if (res < 0) { | ||||||
| 			f = NULL; | 			pbx_builtin_setvar_helper(chan, "WAITSTATUS", "HANGUP"); | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		/* We waited and got no frame; sounds like digital silence or a muted digital channel */ | 		/* We waited and got no frame; sounds like digital silence or a muted digital channel */ | ||||||
| 		if (!res) { | 		if (res == 0) { | ||||||
| 			dsptime = timereqd; | 			dsptime = timereqd; | ||||||
| 		} else { | 		} else { | ||||||
| 			/* Looks like we did get a frame, so let's check it out */ | 			/* Looks like we did get a frame, so let's check it out */ | ||||||
| 			f = ast_read(chan); | 			if (!(f = ast_read(chan))) { | ||||||
| 			if (!f) | 				pbx_builtin_setvar_helper(chan, "WAITSTATUS", "HANGUP"); | ||||||
| 				break; | 				break; | ||||||
| 			if (f && f->frametype == AST_FRAME_VOICE) { |  | ||||||
| 				ast_dsp_func(sildet, f, &dsptime); |  | ||||||
| 				ast_frfree(f); |  | ||||||
| 			} | 			} | ||||||
|  | 			if (f->frametype == AST_FRAME_VOICE) { | ||||||
|  | 				ast_dsp_func(sildet, f, &dsptime); | ||||||
|  | 			} | ||||||
|  | 			ast_frfree(f); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if (wait_for_silence) | 		ast_verb(6, "Got %dms %s < %dms required\n", dsptime, wait_for_silence ? "silence" : "noise", timereqd); | ||||||
| 			ast_verb(6, "Got %dms silence < %dms required\n", dsptime, timereqd); |  | ||||||
| 		else |  | ||||||
| 			ast_verb(6, "Got %dms noise < %dms required\n", dsptime, timereqd); |  | ||||||
|  |  | ||||||
| 		if (dsptime >= timereqd) { | 		if (dsptime >= timereqd) { | ||||||
| 			if (wait_for_silence) | 			ast_verb(3, "Exiting with %dms %s >= %dms required\n", dsptime, wait_for_silence ? "silence" : "noise", timereqd); | ||||||
| 				ast_verb(3, "Exiting with %dms silence >= %dms required\n", dsptime, timereqd); |  | ||||||
| 			else |  | ||||||
| 				ast_verb(3, "Exiting with %dms noise >= %dms required\n", dsptime, timereqd); |  | ||||||
| 			/* Ended happily with silence */ | 			/* Ended happily with silence */ | ||||||
| 			res = 1; | 			res = 1; | ||||||
| 			pbx_builtin_setvar_helper(chan, "WAITSTATUS", wait_for_silence ? "SILENCE" : "NOISE"); | 			pbx_builtin_setvar_helper(chan, "WAITSTATUS", wait_for_silence ? "SILENCE" : "NOISE"); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user