ARI POST DTMF: Make not compete with channel's media thread.

There can be one and only one thread handling a channel's media at a time.
Otherwise, we don't know which thread is going to handle the media frames.

ASTERISK-27625

Change-Id: I4d6a2fe7386ea447ee199003bf8ad681cb30454e
This commit is contained in:
Richard Mudgett
2018-06-13 16:41:43 -05:00
parent 7d874c1af7
commit da54605b8a
3 changed files with 115 additions and 34 deletions

View File

@@ -431,6 +431,32 @@ struct stasis_app_control_dtmf_data {
char dtmf[];
};
static void dtmf_in_bridge(struct ast_channel *chan, struct stasis_app_control_dtmf_data *dtmf_data)
{
if (dtmf_data->before) {
usleep(dtmf_data->before * 1000);
}
ast_dtmf_stream_external(chan, dtmf_data->dtmf, dtmf_data->between, dtmf_data->duration);
if (dtmf_data->after) {
usleep(dtmf_data->after * 1000);
}
}
static void dtmf_no_bridge(struct ast_channel *chan, struct stasis_app_control_dtmf_data *dtmf_data)
{
if (dtmf_data->before) {
ast_safe_sleep(chan, dtmf_data->before);
}
ast_dtmf_stream(chan, NULL, dtmf_data->dtmf, dtmf_data->between, dtmf_data->duration);
if (dtmf_data->after) {
ast_safe_sleep(chan, dtmf_data->after);
}
}
static int app_control_dtmf(struct stasis_app_control *control,
struct ast_channel *chan, void *data)
{
@@ -440,14 +466,10 @@ static int app_control_dtmf(struct stasis_app_control *control,
ast_indicate(chan, AST_CONTROL_PROGRESS);
}
if (dtmf_data->before) {
ast_safe_sleep(chan, dtmf_data->before);
}
ast_dtmf_stream(chan, NULL, dtmf_data->dtmf, dtmf_data->between, dtmf_data->duration);
if (dtmf_data->after) {
ast_safe_sleep(chan, dtmf_data->after);
if (stasis_app_get_bridge(control)) {
dtmf_in_bridge(chan, dtmf_data);
} else {
dtmf_no_bridge(chan, dtmf_data);
}
return 0;