[asterisk-commits] beagles: trunk r376291 - in /trunk: ./ main/channel.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Nov 15 08:35:05 CST 2012
Author: beagles
Date: Thu Nov 15 08:35:01 2012
New Revision: 376291
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=376291
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 376217 from http://svn.asterisk.org/svn/asterisk/branches/11
Modified:
trunk/ (props changed)
trunk/main/channel.c
Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-11-merged' - no diff available.
Modified: trunk/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/channel.c?view=diff&rev=376291&r1=376290&r2=376291
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Thu Nov 15 08:35:01 2012
@@ -3144,7 +3144,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");
@@ -8774,18 +8778,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