Skip to content

Commit a099f13

Browse files
InterLinked1gtjoseph
authored andcommitted
app_originate: Add ability to set codecs
A list of codecs to use for dialplan-originated calls can now be specified in Originate, similar to the ability in call files and the manager action. Additionally, we now default to just using the slin codec for originated calls, rather than all the slin* codecs up through slin192, which has been known to cause issues and inconsistencies from AMI and call file behavior. ASTERISK-29543 Change-Id: I96a1aeb83d54b635b7a51e1b4680f03791622883
1 parent 137bd7f commit a099f13

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

Diff for: apps/app_originate.c

+24-17
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ static const char app_originate[] = "Originate";
9595
<argument name="argN" />
9696
</argument>
9797
</option>
98+
<option name="C">
99+
<para>Comma-separated list of codecs to use for this call.
100+
Default is <literal>slin</literal>.</para>
101+
</option>
98102
<option name="c">
99103
<para>The caller ID number to use for the called channel. Default is
100104
the current channel's Caller ID number.</para>
@@ -114,7 +118,7 @@ static const char app_originate[] = "Originate";
114118
</parameter>
115119
</syntax>
116120
<description>
117-
<para>This application originates an outbound call and connects it to a specified extension or application. This application will block until the outgoing call fails or gets answered. At that point, this application will exit with the status variable set and dialplan processing will continue.</para>
121+
<para>This application originates an outbound call and connects it to a specified extension or application. This application will block until the outgoing call fails or gets answered, unless the async option is used. At that point, this application will exit with the status variable set and dialplan processing will continue.</para>
118122
<para>This application sets the following channel variable before exiting:</para>
119123
<variablelist>
120124
<variable name="ORIGINATE_STATUS">
@@ -141,14 +145,16 @@ enum {
141145
OPT_ASYNC = (1 << 2),
142146
OPT_CALLER_NUM = (1 << 3),
143147
OPT_CALLER_NAME = (1 << 4),
144-
OPT_VARIABLES = (1 << 5),
148+
OPT_CODECS = (1 << 5),
149+
OPT_VARIABLES = (1 << 6),
145150
};
146151

147152
enum {
148153
OPT_ARG_PREDIAL_CALLEE,
149154
OPT_ARG_PREDIAL_CALLER,
150155
OPT_ARG_CALLER_NUM,
151156
OPT_ARG_CALLER_NAME,
157+
OPT_ARG_CODECS,
152158
OPT_ARG_VARIABLES,
153159
/* note: this entry _MUST_ be the last one in the enum */
154160
OPT_ARG_ARRAY_SIZE,
@@ -158,6 +164,7 @@ AST_APP_OPTIONS(originate_exec_options, BEGIN_OPTIONS
158164
AST_APP_OPTION('a', OPT_ASYNC),
159165
AST_APP_OPTION_ARG('b', OPT_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLEE),
160166
AST_APP_OPTION_ARG('B', OPT_PREDIAL_CALLER, OPT_ARG_PREDIAL_CALLER),
167+
AST_APP_OPTION_ARG('C', OPT_CODECS, OPT_ARG_CODECS),
161168
AST_APP_OPTION_ARG('c', OPT_CALLER_NUM, OPT_ARG_CALLER_NUM),
162169
AST_APP_OPTION_ARG('n', OPT_CALLER_NAME, OPT_ARG_CALLER_NAME),
163170
AST_APP_OPTION_ARG('v', OPT_VARIABLES, OPT_ARG_VARIABLES),
@@ -178,30 +185,23 @@ static int originate_exec(struct ast_channel *chan, const char *data)
178185
char *opt_args[OPT_ARG_ARRAY_SIZE];
179186
char *predial_callee = NULL;
180187
char *parse, *cnum = NULL, *cname = NULL;
181-
188+
182189
struct ast_variable *vars = NULL;
183190
char *chantech, *chandata;
184191
int res = -1;
185192
int continue_in_dialplan = 0;
186193
int outgoing_status = 0;
187194
unsigned int timeout = 30;
188195
static const char default_exten[] = "s";
189-
struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
196+
struct ast_format_cap *capabilities;
197+
capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
190198

191199
ast_autoservice_start(chan);
192-
if (!cap_slin) {
200+
if (!capabilities) {
193201
goto return_cleanup;
194202
}
195203

196-
ast_format_cap_append(cap_slin, ast_format_slin, 0);
197-
ast_format_cap_append(cap_slin, ast_format_slin12, 0);
198-
ast_format_cap_append(cap_slin, ast_format_slin16, 0);
199-
ast_format_cap_append(cap_slin, ast_format_slin24, 0);
200-
ast_format_cap_append(cap_slin, ast_format_slin32, 0);
201-
ast_format_cap_append(cap_slin, ast_format_slin44, 0);
202-
ast_format_cap_append(cap_slin, ast_format_slin48, 0);
203-
ast_format_cap_append(cap_slin, ast_format_slin96, 0);
204-
ast_format_cap_append(cap_slin, ast_format_slin192, 0);
204+
ast_format_cap_append(capabilities, ast_format_slin, 0);
205205

206206
if (ast_strlen_zero(data)) {
207207
ast_log(LOG_ERROR, "Originate() requires arguments\n");
@@ -257,6 +257,13 @@ static int originate_exec(struct ast_channel *chan, const char *data)
257257
goto return_cleanup;
258258
}
259259

260+
if (ast_test_flag64(&opts, OPT_CODECS)) {
261+
if (!ast_strlen_zero(opt_args[OPT_ARG_CODECS])) {
262+
ast_format_cap_remove_by_type(capabilities, AST_MEDIA_TYPE_UNKNOWN);
263+
ast_format_cap_update_by_allow_disallow(capabilities, opt_args[OPT_ARG_CODECS], 1);
264+
}
265+
}
266+
260267
if (ast_test_flag64(&opts, OPT_CALLER_NUM)) {
261268
if (!ast_strlen_zero(opt_args[OPT_ARG_CALLER_NUM])) {
262269
cnum = opt_args[OPT_ARG_CALLER_NUM];
@@ -318,7 +325,7 @@ static int originate_exec(struct ast_channel *chan, const char *data)
318325
ast_debug(1, "Originating call to '%s/%s' and connecting them to extension %s,%s,%d\n",
319326
chantech, chandata, args.arg1, exten, priority);
320327

321-
res = ast_pbx_outgoing_exten_predial(chantech, cap_slin, chandata,
328+
res = ast_pbx_outgoing_exten_predial(chantech, capabilities, chandata,
322329
timeout * 1000, args.arg1, exten, priority, &outgoing_status,
323330
ast_test_flag64(&opts, OPT_ASYNC) ? AST_OUTGOING_NO_WAIT : AST_OUTGOING_WAIT,
324331
cid_num, cid_name, vars, NULL, NULL, 0, NULL,
@@ -329,7 +336,7 @@ static int originate_exec(struct ast_channel *chan, const char *data)
329336
ast_debug(1, "Originating call to '%s/%s' and connecting them to %s(%s)\n",
330337
chantech, chandata, args.arg1, S_OR(args.arg2, ""));
331338

332-
res = ast_pbx_outgoing_app_predial(chantech, cap_slin, chandata,
339+
res = ast_pbx_outgoing_app_predial(chantech, capabilities, chandata,
333340
timeout * 1000, args.arg1, args.arg2, &outgoing_status,
334341
ast_test_flag64(&opts, OPT_ASYNC) ? AST_OUTGOING_NO_WAIT : AST_OUTGOING_WAIT,
335342
cid_num, cid_name, vars, NULL, NULL, NULL,
@@ -380,7 +387,7 @@ static int originate_exec(struct ast_channel *chan, const char *data)
380387
if (vars) {
381388
ast_variables_destroy(vars);
382389
}
383-
ao2_cleanup(cap_slin);
390+
ao2_cleanup(capabilities);
384391
ast_autoservice_stop(chan);
385392

386393
return continue_in_dialplan ? 0 : -1;

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

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Subject: app_originate
2+
3+
Codecs can now be specified for dialplan-originated
4+
calls, as with call files and the manager action.
5+
By default, only the slin codec is now used, instead
6+
of all the slin* codecs.

0 commit comments

Comments
 (0)