Cleanup ast_dtmf_stream()

* Made ast_dtmf_stream() wait after starting the silence generator rather
than before.

* Made ast_dtmf_stream() put the peer in autoservice for the whole time
things are being done to the chan.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@373966 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett
2012-09-27 22:33:15 +00:00
parent 02ed1bd638
commit a8771e3953

View File

@@ -731,32 +731,25 @@ int ast_vm_test_destroy_user(const char *context, const char *mailbox)
int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration) int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration)
{ {
const char *ptr; const char *ptr;
int res = 0; int res;
struct ast_silence_generator *silgen = NULL; struct ast_silence_generator *silgen = NULL;
if (!between) { if (!between) {
between = 100; between = 100;
} }
if (peer) { if (peer && ast_autoservice_start(peer)) {
res = ast_autoservice_start(peer); return -1;
}
if (!res) {
res = ast_waitfor(chan, 100);
}
/* ast_waitfor will return the number of remaining ms on success */
if (res < 0) {
if (peer) {
ast_autoservice_stop(peer);
}
return res;
} }
/* Need a quiet time before sending digits. */
if (ast_opt_transmit_silence) { if (ast_opt_transmit_silence) {
silgen = ast_channel_start_silence_generator(chan); silgen = ast_channel_start_silence_generator(chan);
} }
res = ast_safe_sleep(chan, 100);
if (res) {
goto dtmf_stream_cleanup;
}
for (ptr = digits; *ptr; ptr++) { for (ptr = digits; *ptr; ptr++) {
if (*ptr == 'w') { if (*ptr == 'w') {
@@ -765,11 +758,11 @@ int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const ch
break; break;
} }
} else if (strchr("0123456789*#abcdfABCDF", *ptr)) { } else if (strchr("0123456789*#abcdfABCDF", *ptr)) {
/* Character represents valid DTMF */
if (*ptr == 'f' || *ptr == 'F') { if (*ptr == 'f' || *ptr == 'F') {
/* ignore return values if not supported by channel */ /* ignore return values if not supported by channel */
ast_indicate(chan, AST_CONTROL_FLASH); ast_indicate(chan, AST_CONTROL_FLASH);
} else { } else {
/* Character represents valid DTMF */
ast_senddigit(chan, *ptr, duration); ast_senddigit(chan, *ptr, duration);
} }
/* pause between digits */ /* pause between digits */
@@ -781,17 +774,13 @@ int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const ch
} }
} }
if (peer) { dtmf_stream_cleanup:
/* Stop autoservice on the peer channel, but don't overwrite any error condition
that has occurred previously while acting on the primary channel */
if (ast_autoservice_stop(peer) && !res) {
res = -1;
}
}
if (silgen) { if (silgen) {
ast_channel_stop_silence_generator(chan, silgen); ast_channel_stop_silence_generator(chan, silgen);
} }
if (peer && ast_autoservice_stop(peer)) {
res = -1;
}
return res; return res;
} }