[Asterisk-code-review] app_dial: Expanded A option to add caller announcement (asterisk[18])

N A asteriskteam at digium.com
Fri May 21 19:19:41 CDT 2021


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15925 )


Change subject: app_dial: Expanded A option to add caller announcement
......................................................................

app_dial: Expanded A option to add caller announcement

Hitherto, the A option has made it possible to play
audio upon answer to the called party only. This option
is expanded to allow for playback of an audio file to
the caller instead of or in addition to the audio
played to the answerer.

ASTERISK-29442

Change-Id: If6eed3ff5c341dc8c588c8210987f2571e891e5e
---
M apps/app_dial.c
A doc/CHANGES-staging/app_dial_announcement.txt
2 files changed, 63 insertions(+), 13 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/25/15925/1

diff --git a/apps/app_dial.c b/apps/app_dial.c
index d611083..f3dd355 100644
--- a/apps/app_dial.c
+++ b/apps/app_dial.c
@@ -93,11 +93,17 @@
 			</parameter>
 			<parameter name="options" required="false">
 				<optionlist>
-				<option name="A">
-					<argument name="x" required="true">
+				<option name="A" argsep=":">
+					<argument name="x">
 						<para>The file to play to the called party</para>
 					</argument>
-					<para>Play an announcement to the called party, where <replaceable>x</replaceable> is the prompt to be played</para>
+					<argument name="y">
+						<para>The file to play to the calling party</para>
+					</argument>
+					<para>Play an announcement to the called and/or calling parties, where <replaceable>x</replaceable>
+					is the prompt to be played to the called party and <replaceable>y</replaceable> is the prompt
+					to be played to the caller. The files may be different and will be played to each party
+					simultaneously.</para>
 				</option>
 				<option name="a">
 					<para>Immediately answer the calling channel when the called channel answers in
@@ -2941,31 +2947,68 @@
 			int digit = 0;
 			struct ast_channel *chans[2];
 			struct ast_channel *active_chan;
+			char *calledfile = NULL, *callerfile = NULL;
+			int calledstream = 0, callerstream = 0;
 
 			chans[0] = chan;
 			chans[1] = peer;
 
-			/* we need to stream the announcement to the called party when the OPT_ARG_ANNOUNCE (-A) is setted */
+			/* we need to stream the announcement(s) when the OPT_ARG_ANNOUNCE (-A) is set */
+			callerfile = opt_args[OPT_ARG_ANNOUNCE];
+			calledfile = strsep(&callerfile, ":");
 
-			/* stream the file */
-			res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], ast_channel_language(peer));
-			if (res) {
-				res = 0;
-				ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", opt_args[OPT_ARG_ANNOUNCE]);
+			/* stream the file(s) */
+			if (!ast_strlen_zero(calledfile)) {
+				res = ast_streamfile(peer, calledfile, ast_channel_language(peer));
+				if (res) {
+					res = 0;
+					ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", calledfile);
+				} else {
+					calledstream = 1;
+				}
+			}
+			if (!ast_strlen_zero(callerfile)) {
+				res = ast_streamfile(chan, callerfile, ast_channel_language(chan));
+				if (res) {
+					res = 0;
+					ast_log(LOG_ERROR, "error streaming file '%s' to caller\n", callerfile);
+				} else {
+					callerstream = 1;
+				}
 			}
 
+			/* can't use ast_waitstream, because we're streaming two files at once, and can't block
+				We'll need to handle both channels at once. */
+
 			ast_channel_set_flag(peer, AST_FLAG_END_DTMF_ONLY);
-			while (ast_channel_stream(peer)) {
-				int ms;
+			while (ast_channel_stream(peer) || ast_channel_stream(chan)) {
+				int ms, ms2;
 
 				ms = ast_sched_wait(ast_channel_sched(peer));
+				ms2 = ast_sched_wait(ast_channel_sched(chan));
 
-				if (ms < 0 && !ast_channel_timingfunc(peer)) {
-					ast_stopstream(peer);
+				if (calledstream) {
+					if (ms < 0 && !ast_channel_timingfunc(peer)) {
+						ast_stopstream(peer);
+						calledstream = 0;
+					}
+				}
+				if (callerstream) {
+					if (ms2 < 0 && !ast_channel_timingfunc(chan)) {
+						ast_stopstream(chan);
+						callerstream = 0;
+					}
+				}
+				
+				if (!calledstream && !callerstream) {
 					break;
 				}
+				
 				if (ms < 0)
 					ms = 1000;
+				
+				if (ms2 < 0)
+					ms2 = 1000;
 
 				active_chan = ast_waitfor_n(chans, 2, &ms);
 				if (active_chan) {
@@ -3017,6 +3060,7 @@
 					ast_frfree(fr);
 				}
 				ast_sched_runq(ast_channel_sched(peer));
+				ast_sched_runq(ast_channel_sched(chan));
 			}
 			ast_channel_clear_flag(peer, AST_FLAG_END_DTMF_ONLY);
 		}
diff --git a/doc/CHANGES-staging/app_dial_announcement.txt b/doc/CHANGES-staging/app_dial_announcement.txt
new file mode 100644
index 0000000..3947b0e
--- /dev/null
+++ b/doc/CHANGES-staging/app_dial_announcement.txt
@@ -0,0 +1,6 @@
+Subject: app_dial announcement option
+
+The A option for Dial now supports
+playing audio to the caller as well
+as the called party.
+

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15925
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: If6eed3ff5c341dc8c588c8210987f2571e891e5e
Gerrit-Change-Number: 15925
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210521/ace8b1cc/attachment.html>


More information about the asterisk-code-review mailing list