[asterisk-commits] beagles: branch 11 r376217 - in /branches/11: ./ main/channel.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Nov 13 12:48:46 CST 2012


Author: beagles
Date: Tue Nov 13 12:48:43 2012
New Revision: 376217

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=376217
Log:
Patch to prevent stopping the active generator when it is not the silence
generator.

This patch introduces an internal helper function to safely check whether the
current generator is the one that is expected before deactivating it. The
current externally accessible ast_channel_stop_generator() function has been
modified to be implemented in terms of the new function.

(closes issue ASTERISK-19918)
Reported by: Eduardo Abad
........

Merged revisions 376199 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 376208 from http://svn.asterisk.org/svn/asterisk/branches/10

Modified:
    branches/11/   (props changed)
    branches/11/main/channel.c

Propchange: branches/11/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.

Modified: branches/11/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/channel.c?view=diff&rev=376217&r1=376216&r2=376217
==============================================================================
--- branches/11/main/channel.c (original)
+++ branches/11/main/channel.c Tue Nov 13 12:48:43 2012
@@ -3096,7 +3096,11 @@
 
 	res = generate(chan, tmp, 0, ast_format_rate(ast_channel_writeformat(chan)) / 50);
 
-	ast_channel_generatordata_set(chan, tmp);
+	ast_channel_lock(chan);
+	if (ast_channel_generator(chan) && generate == ast_channel_generator(chan)->generate) {
+		ast_channel_generatordata_set(chan, tmp);
+	}
+	ast_channel_unlock(chan);
 
 	if (res) {
 		ast_debug(1, "Auto-deactivating generator\n");
@@ -8722,18 +8726,45 @@
 	return state;
 }
 
+static int internal_deactivate_generator(struct ast_channel *chan, void* generator)
+{
+	ast_channel_lock(chan);
+
+	if (!ast_channel_generatordata(chan)) {
+		ast_debug(1, "Trying to stop silence generator when there is no "
+		    "generator on '%s'\n", ast_channel_name(chan));
+		ast_channel_unlock(chan);
+		return 0;
+	}
+	if (ast_channel_generator(chan) != generator) {
+		ast_debug(1, "Trying to stop silence generator when it is not the current "
+		    "generator on '%s'\n", ast_channel_name(chan));
+		ast_channel_unlock(chan);
+		return 0;
+	}
+	if (ast_channel_generator(chan) && ast_channel_generator(chan)->release) {
+		ast_channel_generator(chan)->release(chan, ast_channel_generatordata(chan));
+	}
+	ast_channel_generatordata_set(chan, NULL);
+	ast_channel_generator_set(chan, NULL);
+	ast_channel_set_fd(chan, AST_GENERATOR_FD, -1);
+	ast_clear_flag(ast_channel_flags(chan), AST_FLAG_WRITE_INT);
+	ast_settimeout(chan, 0, NULL, NULL);
+	ast_channel_unlock(chan);
+
+	return 1;
+}
+
 void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state)
 {
 	if (!state)
 		return;
 
-	ast_deactivate_generator(chan);
-
-	ast_debug(1, "Stopped silence generator on '%s'\n", ast_channel_name(chan));
-
-	if (ast_set_write_format(chan, &state->old_write_format) < 0)
-		ast_log(LOG_ERROR, "Could not return write format to its original state\n");
-
+	if (internal_deactivate_generator(chan, &silence_generator)) {
+		ast_debug(1, "Stopped silence generator on '%s'\n", ast_channel_name(chan));
+		if (ast_set_write_format(chan, &state->old_write_format) < 0)
+			ast_log(LOG_ERROR, "Could not return write format to its original state\n");
+	}
 	ast_free(state);
 }
 




More information about the asterisk-commits mailing list