[Asterisk-Dev] (patch) PlayDialtone

The Traveller traveler at xs4all.nl
Tue May 27 11:48:58 MST 2003


Yo all,

As there was intrest for it on IRC, here's a small patch to add
a version of "Playtones" which is interruptable by DTMF and acts
much like "BackGround" does for playing audio-files.  I needed this to
have a way to play a second dial-tone to callers, which obviously also
requires the ability to receive DTMF during the tone.  I previously used
a recording of the dialtone, played through "BackGround", but find this
solution much cleaner.

Mark didn't like the way I implemented it and therefore it's not in the
mainstream code yet, until he writes it the way he wants it.  Until then,
here's my patch.  I've been using it for months now without any problems.



   Grtz,

      Oliver



  -= Info about application 'PlayDialtone' =-

[Synopsis]:
  Play an interruptable tone list

[Description]:
Play a tone list, either registered (through indications.conf) or a direct
list of tones and durations.  Interrupt the tones after a digit is dialed.
-------------- next part --------------
Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.21
diff -u -r1.21 pbx.c
--- pbx.c	22 May 2003 04:38:46 -0000	1.21
+++ pbx.c	27 May 2003 18:45:15 -0000
@@ -1738,6 +1738,8 @@
 				/* As long as we're willing to wait, and as long as it's not defined, 
 				   keep reading digits until we can't possibly get a right answer anymore.  */
 				digit = ast_waitfordigit(c, waittime * 1000);
+				if (c->writeinterrupt)
+					ast_deactivate_generator(c);
 				if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
 					c->_softhangup = 0;
 				} else {
Index: res/res_indications.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_indications.c,v
retrieving revision 1.2
diff -u -r1.2 res_indications.c
--- res/res_indications.c	27 Apr 2003 21:34:27 -0000	1.2
+++ res/res_indications.c	27 May 2003 18:45:15 -0000
@@ -201,6 +201,28 @@
 }
 
 /*
+ * PlayDialtone command stuff
+ */
+static int handle_playdialtone(struct ast_channel *chan, void *data)
+{
+	struct tone_zone_sound *ts;
+	int res;
+ 
+	if (!data || !((char*)data)[0]) {
+		ast_log(LOG_NOTICE,"Nothing to play\n");
+		return -1;
+	}
+	ts = ast_get_indication_tone(chan->zone, (const char*)data);
+	if (ts && ts->data[0])
+		res = ast_playtones_start(chan, 0, ts->data, 1);
+	else
+		res = ast_playtones_start(chan, 0, (const char*)data, 1);
+	if (res)
+		ast_log(LOG_NOTICE,"Unable to start playdialtone\n");
+	return res;
+}
+
+/*
  * StopPlaylist command stuff
  */
 static int handle_stopplaytones(struct ast_channel *chan, void *data)
@@ -377,6 +399,7 @@
 	ast_cli_register(&remove_indication_cli);
 	ast_cli_register(&show_indications_cli);
 	ast_register_application("Playtones", handle_playtones, "Play a tone list","Play a tone list, either registered (through indications.conf) or a direct list of tones and durations.");
+	ast_register_application("PlayDialtone", handle_playdialtone, "Play an interruptable tone list","Play a tone list, either registered (through indications.conf) or a direct list of tones and durations.  Interrupt the tones after a digit is dialed.");
 	ast_register_application("StopPlaytones", handle_stopplaytones, "Stop playing a tone list","Stop playing a tone list");
 
 	return 0;


More information about the asterisk-dev mailing list