1 From 1e5a2cfe3037823b17dd4ac47b071f02d6f9825f Mon Sep 17 00:00:00 2001
2 From: Naveen Albert <mail@interlinked.x10host.com>
3 Date: Fri, 21 May 2021 20:08:58 -0400
4 Subject: [PATCH] app_dial: Expanded A option to add caller announcement
6 Hitherto, the A option has made it possible to play
7 audio upon answer to the called party only. This option
8 is expanded to allow for playback of an audio file to
9 the caller instead of or in addition to the audio
10 played to the answerer.
14 Change-Id: If6eed3ff5c341dc8c588c8210987f2571e891e5e
16 apps/app_dial.c | 79 +++++++++++++++----
17 doc/CHANGES-staging/app_dial_announcement.txt | 6 ++
18 2 files changed, 68 insertions(+), 17 deletions(-)
19 create mode 100644 doc/CHANGES-staging/app_dial_announcement.txt
25 <parameter name="options" required="false">
28 - <argument name="x" required="true">
29 + <option name="A" argsep=":">
31 <para>The file to play to the called party</para>
33 - <para>Play an announcement to the called party, where <replaceable>x</replaceable> is the prompt to be played</para>
35 + <para>The file to play to the calling party</para>
37 + <para>Play an announcement to the called and/or calling parties, where <replaceable>x</replaceable>
38 + is the prompt to be played to the called party and <replaceable>y</replaceable> is the prompt
39 + to be played to the caller. The files may be different and will be played to each party
40 + simultaneously.</para>
43 <para>Immediately answer the calling channel when the called channel answers in
44 @@ -2941,33 +2947,71 @@ static int dial_exec_full(struct ast_cha
46 struct ast_channel *chans[2];
47 struct ast_channel *active_chan;
48 + char *calledfile = NULL, *callerfile = NULL;
49 + int calledstream = 0, callerstream = 0;
54 - /* we need to stream the announcement to the called party when the OPT_ARG_ANNOUNCE (-A) is setted */
56 - /* stream the file */
57 - res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], ast_channel_language(peer));
60 - ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", opt_args[OPT_ARG_ANNOUNCE]);
61 + /* we need to stream the announcement(s) when the OPT_ARG_ANNOUNCE (-A) is set */
62 + callerfile = opt_args[OPT_ARG_ANNOUNCE];
63 + calledfile = strsep(&callerfile, ":");
65 + /* stream the file(s) */
66 + if (!ast_strlen_zero(calledfile)) {
67 + res = ast_streamfile(peer, calledfile, ast_channel_language(peer));
70 + ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", calledfile);
75 + if (!ast_strlen_zero(callerfile)) {
76 + res = ast_streamfile(chan, callerfile, ast_channel_language(chan));
79 + ast_log(LOG_ERROR, "error streaming file '%s' to caller\n", callerfile);
85 + /* can't use ast_waitstream, because we're streaming two files at once, and can't block
86 + We'll need to handle both channels at once. */
88 ast_channel_set_flag(peer, AST_FLAG_END_DTMF_ONLY);
89 - while (ast_channel_stream(peer)) {
91 + while (ast_channel_stream(peer) || ast_channel_stream(chan)) {
94 - ms = ast_sched_wait(ast_channel_sched(peer));
95 + mspeer = ast_sched_wait(ast_channel_sched(peer));
96 + mschan = ast_sched_wait(ast_channel_sched(chan));
98 - if (ms < 0 && !ast_channel_timingfunc(peer)) {
99 - ast_stopstream(peer);
100 + if (calledstream) {
101 + if (mspeer < 0 && !ast_channel_timingfunc(peer)) {
102 + ast_stopstream(peer);
106 + if (callerstream) {
107 + if (mschan < 0 && !ast_channel_timingfunc(chan)) {
108 + ast_stopstream(chan);
113 + if (!calledstream && !callerstream) {
119 - active_chan = ast_waitfor_n(chans, 2, &ms);
126 + /* wait for the lowest maximum of the two */
127 + active_chan = ast_waitfor_n(chans, 2, (mspeer > mschan ? &mschan : &mspeer));
129 struct ast_channel *other_chan;
130 struct ast_frame *fr = ast_read(active_chan);
131 @@ -3017,6 +3061,7 @@ static int dial_exec_full(struct ast_cha
134 ast_sched_runq(ast_channel_sched(peer));
135 + ast_sched_runq(ast_channel_sched(chan));
137 ast_channel_clear_flag(peer, AST_FLAG_END_DTMF_ONLY);
140 +++ b/doc/CHANGES-staging/app_dial_announcement.txt
142 +Subject: app_dial announcement option
144 +The A option for Dial now supports
145 +playing audio to the caller as well
146 +as the called party.