[svn-commits] wdoekes: trunk r423893 - in /trunk: ./ configs/samples/ res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Sep 25 15:49:11 CDT 2014


Author: wdoekes
Date: Thu Sep 25 15:49:04 2014
New Revision: 423893

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=423893
Log:
musiconhold: Add preferchannelclass=no option to prefer app class.

The new option 'preferchannelclass' is added to musiconhold.conf. If yes
(the default) the CHANNEL(musicclass) is preferred when choosing the
hold music. If it is no, the class suggested by the application that
calls the MoH (e.g. the Queue() app) gets preferred (new behaviour).

This way you set a different hold-music from the Queue-music by setting
both the CHANNEL(musicclass) and the queue-context musicclass.

ASTERISK-24276 #close
Reported by: Kristian Høgh
Patches:
  app_override_channel_moh.patch uploaded by Kristian Høgh (License #6639)

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

Modified:
    trunk/CHANGES
    trunk/configs/samples/musiconhold.conf.sample
    trunk/res/res_musiconhold.c

Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=423893&r1=423892&r2=423893
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Thu Sep 25 15:49:04 2014
@@ -18,7 +18,7 @@
 chan_sip
 ------------------
  * New 'rtpbindaddr' global setting. This allows a user to define which
-   ipaddress to bind the rtpengine too.  For example, chan_sip might bind
+   ipaddress to bind the rtpengine to. For example, chan_sip might bind
    to eth0 (10.0.0.2) but rtpengine to eth1 (192.168.1.10).
 
 
@@ -38,6 +38,9 @@
 ------------------
  * Added sort=randstart to the sort options. It sorts the files by name and
    then chooses the first file to play at random.
+ * Added preferchannelclass=no option to prefer the application-passed class
+   over the channel-set musicclass. This allows separate hold-music from
+   application (e.g. Queue or Dial) specified music.
 
 
 ------------------------------------------------------------------------------

Modified: trunk/configs/samples/musiconhold.conf.sample
URL: http://svnview.digium.com/svn/asterisk/trunk/configs/samples/musiconhold.conf.sample?view=diff&rev=423893&r1=423892&r2=423893
==============================================================================
--- trunk/configs/samples/musiconhold.conf.sample (original)
+++ trunk/configs/samples/musiconhold.conf.sample Thu Sep 25 15:49:04 2014
@@ -2,10 +2,13 @@
 ; Music on Hold -- Sample Configuration
 ;
 [general]
-;cachertclasses=yes ; use 1 instance of moh class for all users who are using it,
-                    ; decrease consumable cpu cycles and memory
-                    ; disabled by default
+;cachertclasses=yes     ; use 1 instance of moh class for all users who are using it,
+                        ; decrease consumable cpu cycles and memory
+                        ; disabled by default
 
+;preferchannelclass=yes ; Prefer the musicclass as defined by CHANNEL(musicclass),
+                        ; over a class set by an application (e.g. a musicclass set on a queue).
+                        ; Defaults to yes.
 
 ; valid mode options:
 ; files		-- read files from a directory in any Asterisk supported

Modified: trunk/res/res_musiconhold.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_musiconhold.c?view=diff&rev=423893&r1=423892&r2=423893
==============================================================================
--- trunk/res/res_musiconhold.c (original)
+++ trunk/res/res_musiconhold.c Thu Sep 25 15:49:04 2014
@@ -151,8 +151,9 @@
 #define MOH_RANDSTART		(MOH_RANDOMIZE | MOH_SORTALPHA) /*!< Sorted but start at random position */
 #define MOH_SORTMODE		(3 << 3)
 
-#define MOH_CACHERTCLASSES      (1 << 5)        /*!< Should we use a separate instance of MOH for each user or not */
-#define MOH_ANNOUNCEMENT	(1 << 6)			/*!< Do we play announcement files between songs on this channel? */
+#define MOH_CACHERTCLASSES	(1 << 5)	/*!< Should we use a separate instance of MOH for each user or not */
+#define MOH_ANNOUNCEMENT	(1 << 6)	/*!< Do we play announcement files between songs on this channel? */
+#define MOH_PREFERCHANNELCLASS	(1 << 7)	/*!< Should queue moh override channel moh */
 
 /* Custom astobj2 flag */
 #define MOH_NOTDELETED          (1 << 30)       /*!< Find only records that aren't deleted? */
@@ -1396,42 +1397,42 @@
 	struct moh_files_state *state = ast_channel_music_state(chan);
 	struct ast_variable *var = NULL;
 	int res = 0;
+	int i;
 	int realtime_possible = ast_check_realtime("musiconhold");
+	const char *classes[] = {NULL, NULL, interpclass, "default"};
+
+	if (ast_test_flag(global_flags, MOH_PREFERCHANNELCLASS)) {
+		classes[0] = ast_channel_musicclass(chan);
+		classes[1] = mclass;
+	} else {
+		classes[0] = mclass;
+		classes[1] = ast_channel_musicclass(chan);
+	}
 
 	/* The following is the order of preference for which class to use:
 	 * 1) The channels explicitly set musicclass, which should *only* be
 	 *    set by a call to Set(CHANNEL(musicclass)=whatever) in the dialplan.
+	 *    Unless preferchannelclass in musiconhold.conf is false
 	 * 2) The mclass argument. If a channel is calling ast_moh_start() as the
 	 *    result of receiving a HOLD control frame, this should be the
 	 *    payload that came with the frame.
-	 * 3) The interpclass argument. This would be from the mohinterpret
+	 * 3) The channels explicitly set musicclass, which should *only* be
+	 *    set by a call to Set(CHANNEL(musicclass)=whatever) in the dialplan.
+	 * 4) The interpclass argument. This would be from the mohinterpret
 	 *    option from channel drivers. This is the same as the old musicclass
 	 *    option.
-	 * 4) The default class.
+	 * 5) The default class.
 	 */
-	if (!ast_strlen_zero(ast_channel_musicclass(chan))) {
-		mohclass = get_mohbyname(ast_channel_musicclass(chan), 1, 0);
-		if (!mohclass && realtime_possible) {
-			var = ast_load_realtime("musiconhold", "name", ast_channel_musicclass(chan), SENTINEL);
-		}
-	}
-	if (!mohclass && !var && !ast_strlen_zero(mclass)) {
-		mohclass = get_mohbyname(mclass, 1, 0);
-		if (!mohclass && realtime_possible) {
-			var = ast_load_realtime("musiconhold", "name", mclass, SENTINEL);
-		}
-	}
-	if (!mohclass && !var && !ast_strlen_zero(interpclass)) {
-		mohclass = get_mohbyname(interpclass, 1, 0);
-		if (!mohclass && realtime_possible) {
-			var = ast_load_realtime("musiconhold", "name", interpclass, SENTINEL);
-		}
-	}
-
-	if (!mohclass && !var) {
-		mohclass = get_mohbyname("default", 1, 0);
-		if (!mohclass && realtime_possible) {
-			var = ast_load_realtime("musiconhold", "name", "default", SENTINEL);
+
+	for (i = 0; i < ARRAY_LEN(classes); ++i) {
+		if (!ast_strlen_zero(classes[i])) {
+			mohclass = get_mohbyname(classes[i], 1, 0);
+			if (!mohclass && realtime_possible) {
+				var = ast_load_realtime("musiconhold", "name", classes[i], SENTINEL);
+			}
+			if (mohclass || var) {
+				break;
+			}
 		}
 	}
 
@@ -1732,6 +1733,7 @@
 	}
 
 	ast_clear_flag(global_flags, AST_FLAGS_ALL);
+	ast_set2_flag(global_flags, 1, MOH_PREFERCHANNELCLASS);
 
 	cat = ast_category_browse(cfg, NULL);
 	for (; cat; cat = ast_category_browse(cfg, cat)) {
@@ -1740,6 +1742,8 @@
 			for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
 				if (!strcasecmp(var->name, "cachertclasses")) {
 					ast_set2_flag(global_flags, ast_true(var->value), MOH_CACHERTCLASSES);
+				} else if (!strcasecmp(var->name, "preferchannelclass")) {
+					ast_set2_flag(global_flags, ast_true(var->value), MOH_PREFERCHANNELCLASS);
 				} else {
 					ast_log(LOG_WARNING, "Unknown option '%s' in [general] section of musiconhold.conf\n", var->name);
 				}




More information about the svn-commits mailing list