Skip to content

Commit 1e5a2cf

Browse files
InterLinked1gtjoseph
authored andcommitted
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
1 parent 5382b9d commit 1e5a2cf

File tree

2 files changed

+68
-17
lines changed

2 files changed

+68
-17
lines changed

Diff for: apps/app_dial.c

+62-17
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,17 @@
9393
</parameter>
9494
<parameter name="options" required="false">
9595
<optionlist>
96-
<option name="A">
97-
<argument name="x" required="true">
96+
<option name="A" argsep=":">
97+
<argument name="x">
9898
<para>The file to play to the called party</para>
9999
</argument>
100-
<para>Play an announcement to the called party, where <replaceable>x</replaceable> is the prompt to be played</para>
100+
<argument name="y">
101+
<para>The file to play to the calling party</para>
102+
</argument>
103+
<para>Play an announcement to the called and/or calling parties, where <replaceable>x</replaceable>
104+
is the prompt to be played to the called party and <replaceable>y</replaceable> is the prompt
105+
to be played to the caller. The files may be different and will be played to each party
106+
simultaneously.</para>
101107
</option>
102108
<option name="a">
103109
<para>Immediately answer the calling channel when the called channel answers in
@@ -2941,33 +2947,71 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
29412947
int digit = 0;
29422948
struct ast_channel *chans[2];
29432949
struct ast_channel *active_chan;
2950+
char *calledfile = NULL, *callerfile = NULL;
2951+
int calledstream = 0, callerstream = 0;
29442952

29452953
chans[0] = chan;
29462954
chans[1] = peer;
29472955

2948-
/* we need to stream the announcement to the called party when the OPT_ARG_ANNOUNCE (-A) is setted */
2956+
/* we need to stream the announcement(s) when the OPT_ARG_ANNOUNCE (-A) is set */
2957+
callerfile = opt_args[OPT_ARG_ANNOUNCE];
2958+
calledfile = strsep(&callerfile, ":");
29492959

2950-
/* stream the file */
2951-
res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], ast_channel_language(peer));
2952-
if (res) {
2953-
res = 0;
2954-
ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", opt_args[OPT_ARG_ANNOUNCE]);
2960+
/* stream the file(s) */
2961+
if (!ast_strlen_zero(calledfile)) {
2962+
res = ast_streamfile(peer, calledfile, ast_channel_language(peer));
2963+
if (res) {
2964+
res = 0;
2965+
ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", calledfile);
2966+
} else {
2967+
calledstream = 1;
2968+
}
2969+
}
2970+
if (!ast_strlen_zero(callerfile)) {
2971+
res = ast_streamfile(chan, callerfile, ast_channel_language(chan));
2972+
if (res) {
2973+
res = 0;
2974+
ast_log(LOG_ERROR, "error streaming file '%s' to caller\n", callerfile);
2975+
} else {
2976+
callerstream = 1;
2977+
}
29552978
}
29562979

2980+
/* can't use ast_waitstream, because we're streaming two files at once, and can't block
2981+
We'll need to handle both channels at once. */
2982+
29572983
ast_channel_set_flag(peer, AST_FLAG_END_DTMF_ONLY);
2958-
while (ast_channel_stream(peer)) {
2959-
int ms;
2984+
while (ast_channel_stream(peer) || ast_channel_stream(chan)) {
2985+
int mspeer, mschan;
2986+
2987+
mspeer = ast_sched_wait(ast_channel_sched(peer));
2988+
mschan = ast_sched_wait(ast_channel_sched(chan));
29602989

2961-
ms = ast_sched_wait(ast_channel_sched(peer));
2990+
if (calledstream) {
2991+
if (mspeer < 0 && !ast_channel_timingfunc(peer)) {
2992+
ast_stopstream(peer);
2993+
calledstream = 0;
2994+
}
2995+
}
2996+
if (callerstream) {
2997+
if (mschan < 0 && !ast_channel_timingfunc(chan)) {
2998+
ast_stopstream(chan);
2999+
callerstream = 0;
3000+
}
3001+
}
29623002

2963-
if (ms < 0 && !ast_channel_timingfunc(peer)) {
2964-
ast_stopstream(peer);
3003+
if (!calledstream && !callerstream) {
29653004
break;
29663005
}
2967-
if (ms < 0)
2968-
ms = 1000;
29693006

2970-
active_chan = ast_waitfor_n(chans, 2, &ms);
3007+
if (mspeer < 0)
3008+
mspeer = 1000;
3009+
3010+
if (mschan < 0)
3011+
mschan = 1000;
3012+
3013+
/* wait for the lowest maximum of the two */
3014+
active_chan = ast_waitfor_n(chans, 2, (mspeer > mschan ? &mschan : &mspeer));
29713015
if (active_chan) {
29723016
struct ast_channel *other_chan;
29733017
struct ast_frame *fr = ast_read(active_chan);
@@ -3017,6 +3061,7 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
30173061
ast_frfree(fr);
30183062
}
30193063
ast_sched_runq(ast_channel_sched(peer));
3064+
ast_sched_runq(ast_channel_sched(chan));
30203065
}
30213066
ast_channel_clear_flag(peer, AST_FLAG_END_DTMF_ONLY);
30223067
}

Diff for: doc/CHANGES-staging/app_dial_announcement.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Subject: app_dial announcement option
2+
3+
The A option for Dial now supports
4+
playing audio to the caller as well
5+
as the called party.
6+

0 commit comments

Comments
 (0)