[asterisk-commits] rmudgett: trunk r410494 - in /trunk: ./ main/channel.c res/res_musiconhold.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 12 14:06:57 CDT 2014


Author: rmudgett
Date: Wed Mar 12 14:06:52 2014
New Revision: 410494

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=410494
Log:
res_musiconhold.c: Generate MOH start/stop events whenever the MOH stream is started/stopped.

* Made res_musiconhold.c always post the MusicOnHoldStart/MusicOnHoldStop
events when it actually starts/stops the music streams.  This allows the
events to always happen when MOH starts/stops.  The event posting code was
moved to the MOH alloc/release routines.

* Made channel_do_masquerade() stop any MOH on the original channel before
masquerading so the original channel will get a stop event with correct
information.

* Cleaned up a couple odd codings in moh_files_alloc() and moh_alloc()
dealing with the music state variable.

(issue ASTERISK-23311)
Reported by: Benjamin Keith Ford

Review: https://reviewboard.asterisk.org/r/3306/
........

Merged revisions 410493 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/main/channel.c
    trunk/res/res_musiconhold.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Modified: trunk/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/channel.c?view=diff&rev=410494&r1=410493&r2=410494
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Wed Mar 12 14:06:52 2014
@@ -6404,6 +6404,10 @@
 	ao2_unlink(channels, clonechan);
 
 	moh_is_playing = ast_test_flag(ast_channel_flags(original), AST_FLAG_MOH);
+	if (moh_is_playing) {
+		/* Stop MOH on the old original channel. */
+		ast_moh_stop(original);
+	}
 
 	/*
 	 * Stop any visible indication on the original channel so we can
@@ -6704,9 +6708,12 @@
 		}
 	}
 
-	/* if moh is playing on the original channel then it needs to be
-	   maintained on the channel that is replacing it. */
+	/*
+	 * If MOH was playing on the original channel then it needs to be
+	 * maintained on the channel that is replacing it.
+	 */
 	if (moh_is_playing) {
+		/* Start MOH on the new original channel. */
 		ast_moh_start(original, NULL, NULL);
 	}
 

Modified: trunk/res/res_musiconhold.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_musiconhold.c?view=diff&rev=410494&r1=410493&r2=410494
==============================================================================
--- trunk/res/res_musiconhold.c (original)
+++ trunk/res/res_musiconhold.c Wed Mar 12 14:06:52 2014
@@ -264,6 +264,42 @@
 }
 #endif
 
+static void moh_post_start(struct ast_channel *chan, const char *moh_class_name)
+{
+	struct stasis_message *message;
+	struct ast_json *json_object;
+
+	ast_verb(3, "Started music on hold, class '%s', on channel '%s'\n",
+		moh_class_name, ast_channel_name(chan));
+
+	json_object = ast_json_pack("{s: s}", "class", moh_class_name);
+	if (!json_object) {
+		return;
+	}
+
+	message = ast_channel_blob_create_from_cache(ast_channel_uniqueid(chan),
+		ast_channel_moh_start_type(), json_object);
+	if (message) {
+		stasis_publish(ast_channel_topic(chan), message);
+	}
+	ao2_cleanup(message);
+	ast_json_unref(json_object);
+}
+
+static void moh_post_stop(struct ast_channel *chan)
+{
+	struct stasis_message *message;
+
+	ast_verb(3, "Stopped music on hold on %s\n", ast_channel_name(chan));
+
+	message = ast_channel_blob_create_from_cache(ast_channel_uniqueid(chan),
+		ast_channel_moh_stop_type(), NULL);
+	if (message) {
+		stasis_publish(ast_channel_topic(chan), message);
+	}
+	ao2_cleanup(message);
+}
+
 static void moh_files_release(struct ast_channel *chan, void *data)
 {
 	struct moh_files_state *state;
@@ -278,8 +314,8 @@
 		ast_closestream(ast_channel_stream(chan));
 		ast_channel_stream_set(chan, NULL);
 	}
-	
-	ast_verb(3, "Stopped music on hold on %s\n", ast_channel_name(chan));
+
+	moh_post_stop(chan);
 
 	ast_format_clear(&state->mohwfmt); /* make sure to clear this format before restoring the original format. */
 	if (state->origwfmt.id && ast_set_write_format(chan, &state->origwfmt)) {
@@ -451,11 +487,11 @@
 	struct moh_files_state *state;
 	struct mohclass *class = params;
 
-	if (!ast_channel_music_state(chan) && (state = ast_calloc(1, sizeof(*state)))) {
+	state = ast_channel_music_state(chan);
+	if (!state && (state = ast_calloc(1, sizeof(*state)))) {
 		ast_channel_music_state_set(chan, state);
 		ast_module_ref(ast_module_info->self);
 	} else {
-		state = ast_channel_music_state(chan);
 		if (!state) {
 			return NULL;
 		}
@@ -485,9 +521,9 @@
 	ast_copy_string(state->name, class->name, sizeof(state->name));
 	state->save_total = class->total_files;
 
-	ast_verb(3, "Started music on hold, class '%s', on %s\n", class->name, ast_channel_name(chan));
-	
-	return ast_channel_music_state(chan);
+	moh_post_start(chan, class->name);
+
+	return state;
 }
 
 static int moh_digit_match(void *obj, void *arg, int flags)
@@ -518,8 +554,7 @@
 	}
 }
 
-static struct ast_generator moh_file_stream = 
-{
+static struct ast_generator moh_file_stream = {
 	.alloc    = moh_files_alloc,
 	.release  = moh_files_release,
 	.generate = moh_files_generator,
@@ -982,7 +1017,7 @@
 					ast_channel_name(chan), ast_getformatname(&oldwfmt));
 		}
 
-		ast_verb(3, "Stopped music on hold on %s\n", ast_channel_name(chan));
+		moh_post_stop(chan);
 	}
 }
 
@@ -993,11 +1028,11 @@
 	struct moh_files_state *state;
 
 	/* Initiating music_state for current channel. Channel should know name of moh class */
-	if (!ast_channel_music_state(chan) && (state = ast_calloc(1, sizeof(*state)))) {
+	state = ast_channel_music_state(chan);
+	if (!state && (state = ast_calloc(1, sizeof(*state)))) {
 		ast_channel_music_state_set(chan, state);
 		ast_module_ref(ast_module_info->self);
 	} else {
-		state = ast_channel_music_state(chan);
 		if (!state) {
 			return NULL;
 		}
@@ -1016,8 +1051,8 @@
 			res = NULL;
 		} else {
 			state->class = mohclass_ref(class, "Placing reference into state container");
-		}
-		ast_verb(3, "Started music on hold, class '%s', on channel '%s'\n", class->name, ast_channel_name(chan));
+			moh_post_start(chan, class->name);
+		}
 	}
 	return res;
 }
@@ -1385,8 +1420,6 @@
 	struct mohclass *mohclass = NULL;
 	struct moh_files_state *state = ast_channel_music_state(chan);
 	struct ast_variable *var = NULL;
-	struct stasis_message *message;
-	struct ast_json *json_object;
 	int res;
 	int realtime_possible = ast_check_realtime("musiconhold");
 
@@ -1575,30 +1608,15 @@
 		}
 	}
 
-	ast_channel_latest_musicclass_set(chan, mohclass->name);
-	ast_set_flag(ast_channel_flags(chan), AST_FLAG_MOH);
-
 	if (mohclass->total_files) {
 		res = ast_activate_generator(chan, &moh_file_stream, mohclass);
 	} else {
 		res = ast_activate_generator(chan, &mohgen, mohclass);
 	}
-
-	json_object = ast_json_pack("{s: s}",
-			"class", mohclass->name);
-	if (!json_object) {
-		mohclass = mohclass_unref(mohclass, "unreffing local reference to mohclass in local_ast_moh_start");
-		return -1;
-	}
-
-	message = ast_channel_blob_create_from_cache(ast_channel_uniqueid(chan),
-			ast_channel_moh_start_type(),
-			json_object);
-	if (message) {
-		stasis_publish(ast_channel_topic(chan), message);
-	}
-	ao2_cleanup(message);
-	ast_json_unref(json_object);
+	if (!res) {
+		ast_channel_latest_musicclass_set(chan, mohclass->name);
+		ast_set_flag(ast_channel_flags(chan), AST_FLAG_MOH);
+	}
 
 	mohclass = mohclass_unref(mohclass, "unreffing local reference to mohclass in local_ast_moh_start");
 
@@ -1607,8 +1625,6 @@
 
 static void local_ast_moh_stop(struct ast_channel *chan)
 {
-	struct stasis_message *message;
-
 	ast_clear_flag(ast_channel_flags(chan), AST_FLAG_MOH);
 	ast_deactivate_generator(chan);
 
@@ -1619,13 +1635,7 @@
 			ast_channel_stream_set(chan, NULL);
 		}
 	}
-
-	message = ast_channel_blob_create_from_cache(ast_channel_uniqueid(chan), ast_channel_moh_stop_type(), NULL);
-	if (message) {
-		stasis_publish(ast_channel_topic(chan), message);
-	}
 	ast_channel_unlock(chan);
-	ao2_cleanup(message);
 }
 
 static void moh_class_destructor(void *obj)




More information about the asterisk-commits mailing list