[asterisk-commits] russell: branch russell/heap r176638 - in /team/russell/heap: ./ apps/ channe...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Feb 17 14:57:52 CST 2009


Author: russell
Date: Tue Feb 17 14:57:52 2009
New Revision: 176638

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=176638
Log:
sync with trunk

Added:
    team/russell/heap/apps/app_playtones.c
      - copied unchanged from r176635, trunk/apps/app_playtones.c
Removed:
    team/russell/heap/res/res_indications.c
Modified:
    team/russell/heap/   (props changed)
    team/russell/heap/UPGRADE.txt
    team/russell/heap/apps/app_disa.c
    team/russell/heap/apps/app_read.c
    team/russell/heap/apps/app_readexten.c
    team/russell/heap/channels/chan_misdn.c
    team/russell/heap/channels/chan_skinny.c
    team/russell/heap/channels/chan_unistim.c
    team/russell/heap/configs/indications.conf.sample
    team/russell/heap/funcs/func_channel.c
    team/russell/heap/include/asterisk/_private.h
    team/russell/heap/include/asterisk/channel.h
    team/russell/heap/include/asterisk/config.h
    team/russell/heap/include/asterisk/indications.h
    team/russell/heap/main/app.c
    team/russell/heap/main/asterisk.c
    team/russell/heap/main/channel.c
    team/russell/heap/main/indications.c
    team/russell/heap/main/loader.c
    team/russell/heap/main/pbx.c
    team/russell/heap/res/snmp/agent.c

Propchange: team/russell/heap/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Feb 17 14:57:52 2009
@@ -1,1 +1,1 @@
-/trunk:1-176613
+/trunk:1-176637

Modified: team/russell/heap/UPGRADE.txt
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/UPGRADE.txt?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/UPGRADE.txt (original)
+++ team/russell/heap/UPGRADE.txt Tue Feb 17 14:57:52 2009
@@ -17,6 +17,13 @@
 === UPGRADE-1.6.txt -- Upgrade info for 1.4 to 1.6
 ===
 ===========================================================
+
+From 1.6.1 to 1.6.2:
+
+* The res_indications module has been removed.  Its functionality was important
+  enough that most of it has been moved into the Asterisk core.
+  Two applications previously provided by res_indications, PlayTones and
+  StopPlayTones, have been moved into a new module, app_playtones.
 
 From 1.6.0.1 to 1.6.1:
 

Modified: team/russell/heap/apps/app_disa.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/apps/app_disa.c?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/apps/app_disa.c (original)
+++ team/russell/heap/apps/app_disa.c Tue Feb 17 14:57:52 2009
@@ -124,15 +124,20 @@
 
 static void play_dialtone(struct ast_channel *chan, char *mailbox)
 {
-	const struct tone_zone_sound *ts = NULL;
-	if(ast_app_has_voicemail(mailbox, NULL))
+	struct ast_tone_zone_sound *ts = NULL;
+
+	if (ast_app_has_voicemail(mailbox, NULL)) {
 		ts = ast_get_indication_tone(chan->zone, "dialrecall");
-	else
+	} else {
 		ts = ast_get_indication_tone(chan->zone, "dial");
-	if (ts)
+	}
+
+	if (ts) {
 		ast_playtones_start(chan, 0, ts->data, 0);
-	else
+		ts = ast_tone_zone_sound_unref(ts);
+	} else {
 		ast_tonepair_start(chan, 350, 440, 0, 0);
+	}
 }
 
 static int disa_exec(struct ast_channel *chan, void *data)

Modified: team/russell/heap/apps/app_read.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/apps/app_read.c?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/apps/app_read.c (original)
+++ team/russell/heap/apps/app_read.c Tue Feb 17 14:57:52 2009
@@ -132,7 +132,7 @@
 	int tries = 1, to = 0, x = 0;
 	double tosec;
 	char *argcopy = NULL;
-	struct tone_zone_sound *ts = NULL;
+	struct ast_tone_zone_sound *ts = NULL;
 	struct ast_flags flags = {0};
 	const char *status = "ERROR";
 
@@ -188,7 +188,7 @@
 		return 0;
 	}
 	if (ast_test_flag(&flags, OPT_INDICATION)) {
-		if (! ast_strlen_zero(arglist.filename)) {
+		if (!ast_strlen_zero(arglist.filename)) {
 			ts = ast_get_indication_tone(chan->zone, arglist.filename);
 		}
 	}
@@ -258,6 +258,10 @@
 		}
 	}
 
+	if (ts) {
+		ts = ast_tone_zone_sound_unref(ts);
+	}
+
 	if (ast_check_hangup(chan))
 		status = "HANGUP";
 	pbx_builtin_setvar_helper(chan, "READSTATUS", status);

Modified: team/russell/heap/apps/app_readexten.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/apps/app_readexten.c?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/apps/app_readexten.c (original)
+++ team/russell/heap/apps/app_readexten.c Tue Feb 17 14:57:52 2009
@@ -132,7 +132,7 @@
 	int maxdigits = sizeof(exten) - 1;
 	int timeout = 0, digit_timeout = 0, x = 0;
 	char *argcopy = NULL, *status = "";
-	struct tone_zone_sound *ts = NULL;
+	struct ast_tone_zone_sound *ts = NULL;
 	struct ast_flags flags = {0};
 
 	 AST_DECLARE_APP_ARGS(arglist,
@@ -179,8 +179,9 @@
 	if (digit_timeout <= 0)
 		digit_timeout = chan->pbx ? chan->pbx->dtimeoutms : 5000;
 
-	if (ast_test_flag(&flags, OPT_INDICATION) && !ast_strlen_zero(arglist.filename))
+	if (ast_test_flag(&flags, OPT_INDICATION) && !ast_strlen_zero(arglist.filename)) {
 		ts = ast_get_indication_tone(chan->zone, arglist.filename);
+	}
 
 	do {
 		if (chan->_state != AST_STATE_UP) {
@@ -250,6 +251,10 @@
 		}
 	} while (0);
 
+	if (ts) {
+		ts = ast_tone_zone_sound_unref(ts);
+	}
+
 	pbx_builtin_setvar_helper(chan, "READEXTENSTATUS", status);
 
 	return status[0] == 'H' ? -1 : 0;

Modified: team/russell/heap/channels/chan_misdn.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/channels/chan_misdn.c?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/channels/chan_misdn.c (original)
+++ team/russell/heap/channels/chan_misdn.c Tue Feb 17 14:57:52 2009
@@ -379,7 +379,7 @@
 	 * \brief Tone zone sound used for dialtone generation.
 	 * \note Used as a boolean.  Non-NULL to prod generation if enabled. 
 	 */
-	const struct tone_zone_sound *ts;
+	struct ast_tone_zone_sound *ts;
 	
 	/*!
 	 * \brief Enables overlap dialing for the set amount of seconds.  (0 = Disabled)
@@ -3357,7 +3357,6 @@
 
 static int dialtone_indicate(struct chan_list *cl)
 {
-	const struct tone_zone_sound *ts = NULL;
 	struct ast_channel *ast = cl->ast;
 	int nd = 0;
 
@@ -3374,14 +3373,14 @@
 	}
 	
 	chan_misdn_log(3, cl->bc->port, " --> Dial\n");
-	ts = ast_get_indication_tone(ast->zone, "dial");
-	cl->ts = ts;	
-	
-	if (ts) {
+
+	cl->ts = ast_get_indication_tone(ast->zone, "dial");
+	
+	if (cl->ts) {
 		cl->notxtone = 0;
 		cl->norxtone = 0;
 		/* This prods us in misdn_write */
-		ast_playtones_start(ast, 0, ts->data, 0);
+		ast_playtones_start(ast, 0, cl->ts->data, 0);
 	}
 
 	return 0;
@@ -3406,8 +3405,9 @@
 	misdn_lib_tone_generator_stop(cl->bc);
 	ast_playtones_stop(ast);
 
-	cl->ts = NULL;
-	/*ast_deactivate_generator(ast);*/
+	if (cl->ts) {
+		cl->ts = ast_tone_zone_sound_unref(cl->ts);
+	}
 
 	return 0;
 }

Modified: team/russell/heap/channels/chan_skinny.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/channels/chan_skinny.c?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/channels/chan_skinny.c (original)
+++ team/russell/heap/channels/chan_skinny.c Tue Feb 17 14:57:52 2009
@@ -3751,7 +3751,7 @@
 {
 	struct skinny_subchannel *xferor; /* the sub doing the transferring */
 	struct skinny_subchannel *xferee; /* the sub being transferred */
-	const struct tone_zone_sound *ts = NULL;
+	struct ast_tone_zone_sound *ts = NULL;
 		
 	if (ast_bridged_channel(sub->owner) || ast_bridged_channel(sub->related->owner)) {
 		if (sub->xferor) {
@@ -3774,8 +3774,10 @@
 			}
 			if (xferor->owner->_state == AST_STATE_RING) {
 				/* play ringing inband */
-				ts = ast_get_indication_tone(xferor->owner->zone, "ring");
-				ast_playtones_start(xferor->owner, 0, ts->data, 1);
+				if ((ts = ast_get_indication_tone(xferor->owner->zone, "ring"))) {
+					ast_playtones_start(xferor->owner, 0, ts->data, 1);
+					ts = ast_tone_zone_sound_unref(ts);
+				}
 			}
 			if (skinnydebug)
 				ast_debug(1, "Transfer Masquerading %s to %s\n",
@@ -3789,8 +3791,10 @@
 			ast_queue_control(xferee->owner, AST_CONTROL_UNHOLD);
 			if (xferor->owner->_state == AST_STATE_RING) {
 				/* play ringing inband */
-				ts = ast_get_indication_tone(xferor->owner->zone, "ring");
-				ast_playtones_start(xferor->owner, 0, ts->data, 1);
+				if ((ts = ast_get_indication_tone(xferor->owner->zone, "ring"))) {
+					ast_playtones_start(xferor->owner, 0, ts->data, 1);
+					ts = ast_tone_zone_sound_unref(ts);
+				}
 			}
 			if (skinnydebug)
 				ast_debug(1, "Transfer Masquerading %s to %s\n",

Modified: team/russell/heap/channels/chan_unistim.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/channels/chan_unistim.c?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/channels/chan_unistim.c (original)
+++ team/russell/heap/channels/chan_unistim.c Tue Feb 17 14:57:52 2009
@@ -439,7 +439,7 @@
 	char datetimeformat;	    /*!< format used for displaying time/date */
 	char contrast;			  /*!< contrast */
 	char country[3];			/*!< country used for dial tone frequency */
-	struct tone_zone *tz;	       /*!< Tone zone for res_indications (ring, busy, congestion) */
+	struct ast_tone_zone *tz;	       /*!< Tone zone for res_indications (ring, busy, congestion) */
 	char ringvolume;			/*!< Ring volume */
 	char ringstyle;			 /*!< Ring melody */
 	int rtp_port;			   /*!< RTP port used by the phone */
@@ -4057,17 +4057,17 @@
 	return "UNKNOWN";
 }
 
-static void in_band_indication(struct ast_channel *ast, const struct tone_zone *tz,
+static void in_band_indication(struct ast_channel *ast, const struct ast_tone_zone *tz,
 	const char *indication)
 {
-	const struct tone_zone_sound *ts = NULL;
-
-	ts = ast_get_indication_tone(tz, indication);
-
-	if (ts && ts->data[0])
+	struct ast_tone_zone_sound *ts = NULL;
+
+	if ((ts = ast_get_indication_tone(tz, indication))) {
 		ast_playtones_start(ast, 0, ts->data, 1);
-	else
+		ts = ast_tone_zone_sound_unref(ts);
+	} else {
 		ast_log(LOG_WARNING, "Unable to get indication tone for %s\n", indication);
+	}
 }
 
 static int unistim_indicate(struct ast_channel *ast, int ind, const void *data, 
@@ -5223,6 +5223,9 @@
 		ast_log(LOG_ERROR, "An Unistim device must have at least one line!\n");
 		ast_mutex_destroy(&l->lock);
 		ast_free(l);
+		if (d->tz) {
+			d->tz = ast_tone_zone_unref(d->tz);
+		}
 		ast_free(d);
 		return NULL;
 	}
@@ -5240,6 +5243,9 @@
 			ast_log(LOG_ERROR, "You must specify the mac address with device=\n");
 			ast_mutex_destroy(&l->lock);
 			ast_free(l);
+			if (d->tz) {
+				d->tz = ast_tone_zone_unref(d->tz);
+			}
 			ast_free(d);
 			return NULL;
 		} else
@@ -5461,6 +5467,9 @@
 					d2 = d2->next;
 				}
 			}
+			if (d->tz) {
+				d->tz = ast_tone_zone_unref(d->tz);
+			}
 			ast_free(d);
 			d = devices;
 			continue;

Modified: team/russell/heap/configs/indications.conf.sample
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/configs/indications.conf.sample?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/configs/indications.conf.sample (original)
+++ team/russell/heap/configs/indications.conf.sample Tue Feb 17 14:57:52 2009
@@ -1,6 +1,9 @@
+;
 ; indications.conf
+;
 ; Configuration file for location specific tone indications
-; used by the pbx_indications module.
+;
+
 ;
 ; NOTE:
 ;    When adding countries to this file, please keep them in alphabetical
@@ -9,7 +12,7 @@
 ; The [general] category is for certain global variables.
 ; All other categories are interpreted as location specific indications
 ;
-;
+
 [general]
 country=us		; default location
 
@@ -17,9 +20,6 @@
 ; [example]
 ; description = string
 ;      The full name of your country, in English.
-; alias = iso[,iso]*
-;      List of other countries 2-letter iso codes, which have the same
-;      tone indications.
 ; ringcadence = num[,num]*
 ;      List of durations the physical bell rings.
 ; dial = tonelist
@@ -55,8 +55,6 @@
 ; concisely:
 ;   element = [!]freq[+|*freq2][/duration]
 ;   tonelist = element[,element]*
-;
-; Please note that SPACES ARE NOT ALLOWED in tone lists!
 ;
 
 [at]

Modified: team/russell/heap/funcs/func_channel.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/funcs/func_channel.c?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/funcs/func_channel.c (original)
+++ team/russell/heap/funcs/func_channel.c Tue Feb 17 14:57:52 2009
@@ -296,12 +296,19 @@
 	}
 #endif
 	else if (!strcasecmp(data, "tonezone")) {
-		struct tone_zone *new_zone;
+		struct ast_tone_zone *new_zone;
 		if (!(new_zone = ast_get_indication_zone(value))) {
 			ast_log(LOG_ERROR, "Unknown country code '%s' for tonezone. Check indications.conf for available country codes.\n", value);
 			ret = -1;	
-		} else 
-			chan->zone = new_zone;
+		} else {
+			ast_channel_lock(chan);
+			if (chan->zone) {
+				chan->zone = ast_tone_zone_unref(chan->zone);
+			}
+			chan->zone = ast_tone_zone_ref(new_zone);
+			ast_channel_unlock(chan);
+			new_zone = ast_tone_zone_unref(new_zone);
+		}
 	} else if (!strcasecmp(data, "callgroup"))
 		chan->callgroup = ast_get_group(value);
 	else if (!strcasecmp(data, "txgain")) {

Modified: team/russell/heap/include/asterisk/_private.h
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/include/asterisk/_private.h?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/include/asterisk/_private.h (original)
+++ team/russell/heap/include/asterisk/_private.h Tue Feb 17 14:57:52 2009
@@ -39,6 +39,8 @@
 int ast_http_reload(void);		/*!< Provided by http.c */
 int ast_tps_init(void); 		/*!< Provided by taskprocessor.c */
 int ast_timing_init(void);		/*!< Provided by timing.c */
+int ast_indications_init(void); /*!< Provided by indications.c */
+int ast_indications_reload(void);/*!< Provided by indications.c */
 
 /*!
  * \brief Reload asterisk modules.

Modified: team/russell/heap/include/asterisk/channel.h
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/include/asterisk/channel.h?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/include/asterisk/channel.h (original)
+++ team/russell/heap/include/asterisk/channel.h Tue Feb 17 14:57:52 2009
@@ -424,7 +424,7 @@
 	struct ast_trans_pvt *readtrans;		/*!< Read translation path */
 	struct ast_audiohook_list *audiohooks;
 	struct ast_cdr *cdr;				/*!< Call Detail Record */
-	struct tone_zone *zone;			/*!< Tone zone as set in indications.conf or
+	struct ast_tone_zone *zone;			/*!< Tone zone as set in indications.conf or
 							     in the CHANNEL dialplan function */
 	struct ast_channel_monitor *monitor;		/*!< Channel monitoring */
 #ifdef HAVE_EPOLL

Modified: team/russell/heap/include/asterisk/config.h
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/include/asterisk/config.h?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/include/asterisk/config.h (original)
+++ team/russell/heap/include/asterisk/config.h Tue Feb 17 14:57:52 2009
@@ -257,10 +257,11 @@
 /*! 
  * \brief Retrieve realtime configuration 
  * \param family which family/config to lookup
+ *
  * This will use builtin configuration backends to look up a particular 
  * entity in realtime and return a variable list of its parameters. Unlike
  * the ast_load_realtime, this function can return more than one entry and
- * is thus stored inside a taditional ast_config structure rather than 
+ * is thus stored inside a traditional ast_config structure rather than 
  * just returning a linked list of variables.
  *
  * Note that you should use the constant SENTINEL to terminate arguments, in

Modified: team/russell/heap/include/asterisk/indications.h
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/include/asterisk/indications.h?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/include/asterisk/indications.h (original)
+++ team/russell/heap/include/asterisk/indications.h Tue Feb 17 14:57:52 2009
@@ -1,91 +1,251 @@
 /*
  * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2002, Pauline Middelink
+ * Copyright (C) 2009, Digium, Inc.
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
  * any of the maintainers of this project for assistance;
  * the project provides a web site, mailing lists and IRC
  * channels for your use.
- */
-
-/*! \file
- * \brief BSD Telephony Of Mexico "Tormenta" Tone Zone Support 2/22/01
- * 
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
- *
- * Primary Author: Pauline Middelink <middelink at polyware.nl>
- *
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief Tone Indication Support
+ *
+ * \author Pauline Middelink <middelink at polyware.nl>
+ * \author Russell Bryant <russell at digium.com>
  */
 
 #ifndef _ASTERISK_INDICATIONS_H
 #define _ASTERISK_INDICATIONS_H
 
-#include "asterisk/lock.h"
-
-/*! \brief Description is a series of tones of the format:
-	   [!]freq1[+freq2][/duration] separated by commas.  There
-	   are no spaces.  The sequence is repeated back to the 
-	   first tone description not preceeded by !. Duration is
-	   specified in milliseconds */
-struct tone_zone_sound {
-	const char *name;			/*!< Identifing name */
-	const char *data;			/*!< Actual zone description */
-	AST_LIST_ENTRY(tone_zone_sound) list;
+#include "asterisk/astobj2.h"
+
+/*!
+ * \brief Description of a tone
+ */
+struct ast_tone_zone_sound {
+	/*! \brief Name of the tone.  For example, "busy". */
+	const char *name;
+	/*!
+	 * \brief Description of a tone
+	 *
+	 * The format is a comma separated list of tone parts in the following format:
+	 *
+	 * Format: [!][M]freq[<+|*>freq2][/duration]
+	 *  - '!' - means that the element is NOT repeated
+	 *  - 'M' - interpret the frequencies as midi notes instead of frequencies
+	 *  - freq - The first frequency
+	 *  - freq2 - The second frequency (optional)
+	 *  - '*' - modulate freq by freq2 at a fixed depth of 90%
+	 *  - '+' - combine the frequencies
+	 *  - duration - the length of the tone part (optional, forever if not specified)
+	 */
+	const char *data;
+	/*! \brief Linked list fields for including in the list on an ast_tone_zone */
+	AST_LIST_ENTRY(ast_tone_zone_sound) entry;
+	/*! \brief Flags only used internally */
+	union {
+		uint32_t __padding;
+		struct {
+			unsigned int killme:1;
+		};
+	};
 };
 
-struct tone_zone {
-	AST_RWLIST_ENTRY(tone_zone) list;
-	char country[5];				/*!< Country code */
-	char alias[5];					/*!< is this an alias? */
-	char description[40];				/*!< Description */
-	int  nrringcadence;				/*!< # registered ringcadence elements */
-	int *ringcadence;				/*!< Ring cadence */
-	AST_LIST_HEAD_NOLOCK(, tone_zone_sound) tones;		/*!< The known tones for this zone */
+/*!
+ * \brief A set of tones for a given locale
+ *
+ * \note If a reference to this tone zone is held, then the country
+ *       is guaranteed not to change.  It is safe to read it without
+ *       locking the tone zone.  This is not the case for any other
+ *       field.
+ */
+struct ast_tone_zone {
+	/*! \brief Country code that this set of tones is for */
+	char country[5];
+	/*! 
+	 * \brief Text description of the given country.
+	 *
+	 * This is for nothing more than friendly display to a human.
+	 */
+	char description[40];
+	/*! \brief Number of ring cadence elements in the ringcadence array */
+	unsigned int  nrringcadence;
+	/*! 
+	 * \brief Array of ring cadence parts
+	 *
+	 * Each element is an amount of time in milliseconds.  The first element
+	 * is for time on, and from there it alternates between on and off.
+	 */
+	int *ringcadence;
+	/*! \brief A list of tones for this locale */
+	AST_LIST_HEAD_NOLOCK(, ast_tone_zone_sound) tones;
+	/*! \brief Flags only used internally */
+	union {
+		uint32_t __padding;
+		struct {
+			unsigned int killme:1;
+		};
+	};
 };
 
-/*! \brief set the default tone country */
-int ast_set_indication_country(const char *country);
-
-/*! \brief locate tone_zone, given the country. if country == NULL, use the default country */
-struct tone_zone *ast_get_indication_zone(const char *country);
-/*! \brief locate a tone_zone_sound, given the tone_zone. if tone_zone == NULL, use the default tone_zone */
-struct tone_zone_sound *ast_get_indication_tone(const struct tone_zone *zone, const char *indication);
-/*! \brief deallocate the passed tone zone */
-void ast_destroy_indication_zone(struct tone_zone *zone);
-
-/*! \brief add a new country, if country exists, it will be replaced. */
-int ast_register_indication_country(struct tone_zone *country);
-/*! \brief remove an existing country and all its indications, country must exist */
-int ast_unregister_indication_country(const char *country);
-/*! \brief add a new indication to a tone_zone. tone_zone must exist. if the indication already
- * exists, it will be replaced. */
-int ast_register_indication(struct tone_zone *zone, const char *indication, const char *tonelist);
-/*! \brief remove an existing tone_zone's indication. tone_zone must exist */
-int ast_unregister_indication(struct tone_zone *zone, const char *indication);
-
-/*! \brief Start a tone-list going */
-int ast_playtones_start(struct ast_channel *chan, int vol, const char* tonelist, int interruptible);
-/*! \brief Stop the tones from playing */
+/*!
+ * \brief A description of a part of a tone
+ *
+ * The elements in this structure map to the format described for the data
+ * part of the ast_tone_zone_sound struct.
+ */
+struct ast_tone_zone_part {
+	unsigned int freq1;
+	unsigned int freq2;
+	unsigned int time;
+	unsigned int modulate:1;
+	unsigned int midinote:1;
+};
+
+/*!
+ * \brief Parse a tone part
+ *
+ * \param s The part of a tone to parse.  This should be in the form described for
+ *        the data part of ast_tone_zone_sound.  '!' should be removed if present.
+ * \param tone_data An output parameter that contains the result of the parsing.
+ *
+ * \retval 0 success
+ * \retval -1 failure, and the contents of tone_data are undefined
+ */
+int ast_tone_zone_part_parse(const char *s, struct ast_tone_zone_part *tone_data);
+
+/*!
+ * \brief locate ast_tone_zone
+ *
+ * \param country country to find.  If NULL is provided, get the default.
+ *
+ * \return a reference to the specified country if found or NULL if not found
+ */
+struct ast_tone_zone *ast_get_indication_zone(const char *country);
+
+/*!
+ * \brief Locate a tone zone sound
+ *
+ * \param zone Zone to look in for a sound, if NULL, the default will be used
+ * \param indication Sound to look for, such as "busy"
+ *
+ * \return a reference to the specified sound if it exists, NULL if not
+ */
+struct ast_tone_zone_sound *ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication);
+
+/*!
+ * \brief Start playing a list of tones on a channel
+ *
+ * \param chan the channel to play tones on
+ * \param vol volume
+ * \param tonelist the list of tones to play, comma separated
+ * \param interruptible whether or not this tone can be interrupted
+ *
+ * \retval 0 success
+ * \retval non-zero failure
+ */
+int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible);
+
+/*!
+ * \brief Stop playing tones on a channel
+ *
+ * \param chan the channel to stop tones on
+ */
 void ast_playtones_stop(struct ast_channel *chan);
 
-/*! \brief support for walking through a list of indications */
-struct tone_zone *ast_walk_indications(const struct tone_zone *cur);
-
-#if 0
-extern struct tone_zone *tone_zones;
-extern ast_mutex_t tzlock;
-#endif
+/*!
+ * \brief Get the number of registered tone zones
+ *
+ * \return the total number of registered tone zones
+ */
+int ast_tone_zone_count(void);
+
+/*!
+ * \brief Get an iterator for the available tone zones
+ *
+ * Use ao2_iterator_next() to iterate the tone zones.
+ *
+ * \return an initialized iterator
+ */
+struct ao2_iterator ast_tone_zone_iterator_init(void);
+
+extern struct ast_tone_zone __fake_tone_zone;
+extern struct ast_tone_zone_sound __fake_tone_zone_sound;
+
+#define AST_CHECK_TONE_ZONE(tz) do { \
+	(void) ((tz) == (&__fake_tone_zone)); \
+} while (0)
+
+#define AST_CHECK_TONE_ZONE_SOUND(ts) do { \
+	(void) ((ts) == (&__fake_tone_zone_sound)); \
+} while (0)
+
+/*!
+ * \brief Lock an ast_tone_zone
+ */
+#define ast_tone_zone_lock(tz) ao2_lock(tz)
+
+/*!
+ * \brief Unlock an ast_tone_zone
+ */
+#define ast_tone_zone_unlock(tz) ao2_unlock(tz)
+
+/*!
+ * \brief Trylock an ast_tone_zone
+ */
+#define ast_tone_zone_trylock(tz) ao2_trylock(tz)
+
+/*!
+ * \brief Release a reference to an ast_tone_zone
+ *
+ * \return NULL
+ */
+#define ast_tone_zone_unref(tz) ({  \
+	AST_CHECK_TONE_ZONE(tz); \
+	ao2_ref(tz, -1); \
+	(NULL); \
+})
+
+/*!
+ * \brief Increase the reference count on an ast_tone_zone
+ *
+ * \return The tone zone provided as an argument
+ */
+#define ast_tone_zone_ref(tz) ({ \
+	AST_CHECK_TONE_ZONE(tz); \
+	ao2_ref(tz, +1); \
+	(tz); \
+})
+
+/*!
+ * \brief Release a reference to an ast_tone_zone_sound
+ *
+ * \return NULL
+ */
+#define ast_tone_zone_sound_unref(ts) ({ \
+	AST_CHECK_TONE_ZONE_SOUND(ts); \
+	ao2_ref(ts, -1); \
+	(NULL); \
+})
+
+/*!
+ * \brief Increase the reference count on an ast_tone_zone_sound
+ *
+ * \return The tone zone sound provided as an argument
+ */
+#define ast_tone_zone_sound_ref(ts) ({ \
+	AST_CHECK_TONE_ZONE_SOUND(ts); \
+	ao2_ref(ts, +1); \
+	(ts); \
+})
 
 #endif /* _ASTERISK_INDICATIONS_H */

Modified: team/russell/heap/main/app.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/main/app.c?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/main/app.c (original)
+++ team/russell/heap/main/app.c Tue Feb 17 14:57:52 2009
@@ -75,21 +75,24 @@
 */
 int ast_app_dtget(struct ast_channel *chan, const char *context, char *collect, size_t size, int maxlen, int timeout) 
 {
-	struct tone_zone_sound *ts;
+	struct ast_tone_zone_sound *ts;
 	int res = 0, x = 0;
 
 	if (maxlen > size)
 		maxlen = size;
 	
-	if (!timeout && chan->pbx)
+	if (!timeout && chan->pbx) {
 		timeout = chan->pbx->dtimeoutms / 1000.0;
-	else if (!timeout)
+	} else if (!timeout) {
 		timeout = 5;
-
-	if ((ts = ast_get_indication_tone(chan->zone, "dial")) && ts->data[0])
+	}
+
+	if ((ts = ast_get_indication_tone(chan->zone, "dial"))) {
 		res = ast_playtones_start(chan, 0, ts->data, 0);
-	else 
+		ts = ast_tone_zone_sound_unref(ts);
+	} else {
 		ast_log(LOG_NOTICE, "Huh....? no dial for indications?\n");
+	}
 	
 	for (x = strlen(collect); x < maxlen; ) {
 		res = ast_waitfordigit(chan, timeout);

Modified: team/russell/heap/main/asterisk.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/main/asterisk.c?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/main/asterisk.c (original)
+++ team/russell/heap/main/asterisk.c Tue Feb 17 14:57:52 2009
@@ -3566,6 +3566,11 @@
 		exit(1);
 	}
 
+	if (ast_indications_init()) {
+		printf("%s", term_quit());
+		exit(1);
+	}
+
 	ast_features_init();
 
 	if (init_framer()) {

Modified: team/russell/heap/main/channel.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/main/channel.c?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/main/channel.c (original)
+++ team/russell/heap/main/channel.c Tue Feb 17 14:57:52 2009
@@ -1403,7 +1403,11 @@
 		ast_cdr_discard(chan->cdr);
 		chan->cdr = NULL;
 	}
-	
+
+	if (chan->zone) {
+		chan->zone = ast_tone_zone_unref(chan->zone);
+	}
+
 	ast_mutex_destroy(&chan->lock_dont_use);
 
 	ast_string_field_free_memory(chan);
@@ -2910,7 +2914,7 @@
 	/* By using an enum, we'll get compiler warnings for values not handled 
 	 * in switch statements. */
 	enum ast_control_frame_type condition = _condition;
-	const struct tone_zone_sound *ts = NULL;
+	struct ast_tone_zone_sound *ts = NULL;
 	int res = -1;
 
 	ast_channel_lock(chan);
@@ -2981,10 +2985,11 @@
 		break;
 	}
 
-	if (ts && ts->data[0]) {
+	if (ts) {
 		/* We have a tone to play, yay. */
 		ast_debug(1, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition);
 		ast_playtones_start(chan, 0, ts->data, 1);
+		ts = ast_tone_zone_sound_unref(ts);
 		res = 0;
 		chan->visible_indication = condition;
 	}

Modified: team/russell/heap/main/indications.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/heap/main/indications.c?view=diff&rev=176638&r1=176637&r2=176638
==============================================================================
--- team/russell/heap/main/indications.c (original)
+++ team/russell/heap/main/indications.c Tue Feb 17 14:57:52 2009
@@ -2,7 +2,7 @@
  * Asterisk -- An open source telephony toolkit.
  *
  * Copyright (C) 2002, Pauline Middelink
- *
+ * Copyright (C) 2009, Digium, Inc.
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
@@ -15,17 +15,12 @@
  * at the top of the source tree.
  */
 
-/*! \file
+/*!
+ * \file
+ * \brief Indication Tone Handling
  *
- * \brief Tone Management
- * 
  * \author Pauline Middelink <middelink at polyware.nl>
- *
- * This set of function allow us to play a list of tones on a channel.
- * Each element has two frequencies, which are mixed together and a
- * duration. For silence both frequencies can be set to 0.
- * The playtones can be given as a comma separated string.
- *
+ * \author Russell Bryant <russell at digium.com>
  */
 
 #include "asterisk.h"
@@ -40,22 +35,39 @@
 #include "asterisk/frame.h"
 #include "asterisk/channel.h"
 #include "asterisk/utils.h"
-
-static int midi_tohz[128] = {
-			8,8,9,9,10,10,11,12,12,13,14,
-			15,16,17,18,19,20,21,23,24,25,
-			27,29,30,32,34,36,38,41,43,46,
-			48,51,55,58,61,65,69,73,77,82,
-			87,92,97,103,110,116,123,130,138,146,
-			155,164,174,184,195,207,220,233,246,261,
-			277,293,311,329,349,369,391,415,440,466,
-			493,523,554,587,622,659,698,739,783,830,
-			880,932,987,1046,1108,1174,1244,1318,1396,1479,
-			1567,1661,1760,1864,1975,2093,2217,2349,2489,2637,
-			2793,2959,3135,3322,3520,3729,3951,4186,4434,4698,
-			4978,5274,5587,5919,6271,6644,7040,7458,7902,8372,
-			8869,9397,9956,10548,11175,11839,12543
-			};
+#include "asterisk/cli.h"
+#include "asterisk/module.h"
+#include "asterisk/astobj2.h"
+
+#include "asterisk/_private.h" /* _init(), _reload() */
+
+/* Globals */
+static const char config[] = "indications.conf";
+
+static const int midi_tohz[128] = {
+	8,     8,     9,     9,     10,    10,    11,    12,    12,    13,
+	14,    15,    16,    17,    18,    19,    20,    21,    23,    24,
+	25,    27,    29,    30,    32,    34,    36,    38,    41,    43,
+	46,    48,    51,    55,    58,    61,    65,    69,    73,    77,
+	82,    87,    92,    97,    103,   110,   116,   123,   130,   138,
+	146,   155,   164,   174,   184,   195,   207,   220,   233,   246,
+	261,   277,   293,   311,   329,   349,   369,   391,   415,   440,
+	466,   493,   523,   554,   587,   622,   659,   698,   739,   783,
+	830,   880,   932,   987,   1046,  1108,  1174,  1244,  1318,  1396,
+	1479,  1567,  1661,  1760,  1864,  1975,  2093,  2217,  2349,  2489,
+	2637,  2793,  2959,  3135,  3322,  3520,  3729,  3951,  4186,  4434,
+	4698,  4978,  5274,  5587,  5919,  6271,  6644,  7040,  7458,  7902,
+	8372,  8869,  9397,  9956,  10548, 11175, 11839, 12543
+};
+
+static struct ao2_container *ast_tone_zones;
+
+#define NUM_TONE_ZONE_BUCKETS 53
+
+/*!
+ * \note Access to this is protected by locking the ast_tone_zones container
+ */
+static struct ast_tone_zone *default_tone_zone;
 
 struct playtones_item {
 	int fac1;
@@ -100,21 +112,26 @@
 {
 	struct playtones_state *ps = params;
 
-	if (chan)
+	if (chan) {
 		ast_set_write_format(chan, ps->origwfmt);
-	if (ps->items)
+	}
+
+	if (ps->items) {
 		ast_free(ps->items);
+		ps->items = NULL;
+	}
 
 	ast_free(ps);
 }
 
-static void * playtones_alloc(struct ast_channel *chan, void *params)
+static void *playtones_alloc(struct ast_channel *chan, void *params)
 {
 	struct playtones_def *pd = params;
 	struct playtones_state *ps = NULL;
 
-	if (!(ps = ast_calloc(1, sizeof(*ps))))
+	if (!(ps = ast_calloc(1, sizeof(*ps)))) {
 		return NULL;
+	}
 
 	ps->origwfmt = chan->writeformat;
 
@@ -131,10 +148,11 @@
 	}
 
 	/* Let interrupts interrupt :) */
-	if (pd->interruptible)
+	if (pd->interruptible) {
 		ast_set_flag(chan, AST_FLAG_WRITE_INT);
-	else
+	} else {
 		ast_clear_flag(chan, AST_FLAG_WRITE_INT);
+	}
 
 	return ps;
 }
@@ -144,17 +162,20 @@
 	struct playtones_state *ps = data;
 	struct playtones_item *pi;
 	int x;
-	/* we need to prepare a frame with 16 * timelen samples as we're 
-	 * generating SLIN audio
-	 */
+
+	/* we need to prepare a frame with 16 * timelen samples as we're
+	 * generating SLIN audio */
+
 	len = samples * 2;
 	if (len > sizeof(ps->data) / 2 - 1) {
 		ast_log(LOG_WARNING, "Can't generate that much data!\n");
 		return -1;
 	}
+
 	memset(&ps->f, 0, sizeof(ps->f));
 
 	pi = &ps->items[ps->npos];
+
 	if (ps->oldnpos != ps->npos) {
 		/* Load new parameters */
 		ps->v1_1 = 0;
@@ -165,163 +186,199 @@
 		ps->v3_2 = pi->init_v3_2;
 		ps->oldnpos = ps->npos;
 	}
-	for (x = 0; x < len/2; x++) {
+
+	for (x = 0; x < samples; x++) {
 		ps->v1_1 = ps->v2_1;
 		ps->v2_1 = ps->v3_1;
 		ps->v3_1 = (pi->fac1 * ps->v2_1 >> 15) - ps->v1_1;
-		
+
 		ps->v1_2 = ps->v2_2;
 		ps->v2_2 = ps->v3_2;
 		ps->v3_2 = (pi->fac2 * ps->v2_2 >> 15) - ps->v1_2;
 		if (pi->modulate) {
 			int p;
 			p = ps->v3_2 - 32768;
-			if (p < 0) p = -p;
+			if (p < 0) {
+				p = -p;
+			}
 			p = ((p * 9) / 10) + 1;
 			ps->data[x] = (ps->v3_1 * p) >> 15;
-		} else
-			ps->data[x] = ps->v3_1 + ps->v3_2; 
-	}
-	
+		} else {
+			ps->data[x] = ps->v3_1 + ps->v3_2;
+		}
+	}
+
 	ps->f.frametype = AST_FRAME_VOICE;
 	ps->f.subclass = AST_FORMAT_SLINEAR;
 	ps->f.datalen = len;
 	ps->f.samples = samples;
 	ps->f.offset = AST_FRIENDLY_OFFSET;
 	ps->f.data.ptr = ps->data;
-	ps->f.delivery.tv_sec = 0;
-	ps->f.delivery.tv_usec = 0;
-	ast_write(chan, &ps->f);
+
+	if (ast_write(chan, &ps->f)) {
+		return -1;
+	}
 
 	ps->pos += x;
+
 	if (pi->duration && ps->pos >= pi->duration * 8) {	/* item finished? */
 		ps->pos = 0;					/* start new item */
 		ps->npos++;
 		if (ps->npos >= ps->nitems) {			/* last item? */
-			if (ps->reppos == -1)			/* repeat set? */
+			if (ps->reppos == -1) {			/* repeat set? */
 				return -1;
+			}
 			ps->npos = ps->reppos;			/* redo from top */
 		}
 	}
+
 	return 0;
 }
 
 static struct ast_generator playtones = {
-	alloc: playtones_alloc,
-	release: playtones_release,
-	generate: playtones_generator,
+	.alloc     = playtones_alloc,
+	.release   = playtones_release,
+	.generate  = playtones_generator,
 };
 
+int ast_tone_zone_part_parse(const char *s, struct ast_tone_zone_part *tone_data)
+{
+	if (sscanf(s, "%u+%u/%u", &tone_data->freq1, &tone_data->freq2, 
+			&tone_data->time) == 3) {
+		/* f1+f2/time format */
+	} else if (sscanf(s, "%u+%u", &tone_data->freq1, &tone_data->freq2) == 2) {
+		/* f1+f2 format */
+		tone_data->time = 0;
+	} else if (sscanf(s, "%u*%u/%u", &tone_data->freq1, &tone_data->freq2, 
+			&tone_data->time) == 3) {
+		/* f1*f2/time format */
+		tone_data->modulate = 1;
+	} else if (sscanf(s, "%u*%u", &tone_data->freq1, &tone_data->freq2) == 2) {
+		/* f1*f2 format */
+		tone_data->time = 0;
+		tone_data->modulate = 1;
+	} else if (sscanf(s, "%u/%u", &tone_data->freq1, &tone_data->time) == 2) {
+		/* f1/time format */
+		tone_data->freq2 = 0;
+	} else if (sscanf(s, "%u", &tone_data->freq1) == 1) {
+		/* f1 format */
+		tone_data->freq2 = 0;
+		tone_data->time = 0;
+	} else if (sscanf(s, "M%u+M%u/%u", &tone_data->freq1, &tone_data->freq2, 
+			&tone_data->time) == 3) {
+		/* Mf1+Mf2/time format */
+		tone_data->midinote = 1;
+	} else if (sscanf(s, "M%u+M%u", &tone_data->freq1, &tone_data->freq2) == 2) {
+		/* Mf1+Mf2 format */
+		tone_data->time = 0;
+		tone_data->midinote = 1;
+	} else if (sscanf(s, "M%u*M%u/%u", &tone_data->freq1, &tone_data->freq2, 
+			&tone_data->time) == 3) {
+		/* Mf1*Mf2/time format */
+		tone_data->modulate = 1;
+		tone_data->midinote = 1;
+	} else if (sscanf(s, "M%u*M%u", &tone_data->freq1, &tone_data->freq2) == 2) {
+		/* Mf1*Mf2 format */
+		tone_data->time = 0;
+		tone_data->modulate = 1;
+		tone_data->midinote = 1;
+	} else if (sscanf(s, "M%u/%u", &tone_data->freq1, &tone_data->time) == 2) {
+		/* Mf1/time format */
+		tone_data->freq2 = -1;
+		tone_data->midinote = 1;
+	} else if (sscanf(s, "M%u", &tone_data->freq1) == 1) {
+		/* Mf1 format */
+		tone_data->freq2 = -1;
+		tone_data->time = 0;
+		tone_data->midinote = 1;
+	} else {
+		return -1;
+	}
+
+	return 0;
+}
+
 int ast_playtones_start(struct ast_channel *chan, int vol, const char *playlst, int interruptible)
 {
-	char *s, *data = ast_strdupa(playlst); /* cute */
-	struct playtones_def d = { vol, -1, 0, 1, NULL};
+	char *s, *data = ast_strdupa(playlst);
+	struct playtones_def d = { vol, -1, 0, 1, NULL };
 	char *stringp;
 	char *separator;
-	
-	if (vol < 1)
+	static const float sample_rate = 8000.0;
+	static const float max_sample_val = 32768.0;
+
+	if (vol < 1) {
 		d.vol = 7219; /* Default to -8db */
+	}
 
 	d.interruptible = interruptible;
-	
-	stringp=data;
-	/* the stringp/data is not null here */
+
+	stringp = data;
+
 	/* check if the data is separated with '|' or with ',' by default */
-	if (strchr(stringp,'|'))
+	if (strchr(stringp,'|')) {
 		separator = "|";
-	else
+	} else {
 		separator = ",";
-	s = strsep(&stringp,separator);
-	while (s && *s) {
-		int freq1, freq2, duration, modulate = 0, midinote = 0;
-
-		if (s[0]=='!')
+	}
+
+	while ((s = strsep(&stringp, separator)) && !ast_strlen_zero(s)) {
+		struct ast_tone_zone_part tone_data = {
+			.time = 0,
+		};
+
+		s = ast_strip(s);
+
+		if (s[0]=='!') {
 			s++;
-		else if (d.reppos == -1)
+		} else if (d.reppos == -1) {
 			d.reppos = d.nitems;
-		if (sscanf(s, "%d+%d/%d", &freq1, &freq2, &duration) == 3) {
-			/* f1+f2/time format */
-		} else if (sscanf(s, "%d+%d", &freq1, &freq2) == 2) {
-			/* f1+f2 format */
-			duration = 0;
-		} else if (sscanf(s, "%d*%d/%d", &freq1, &freq2, &duration) == 3) {
-			/* f1*f2/time format */
-			modulate = 1;

[... 1211 lines stripped ...]



More information about the asterisk-commits mailing list