Index: include/asterisk/features.h =================================================================== --- include/asterisk/features.h (revision 375354) +++ include/asterisk/features.h (working copy) @@ -169,6 +169,18 @@ /*! \brief Determine system call pickup extension */ const char *ast_pickup_ext(void); +/*! + * \brief Simulate a DTMF end on a broken bridge channel. + * + * \param chan Channel sending DTMF that has not ended. + * \param digit DTMF digit to stop. + * \param start DTMF digit start time. + * \param why Reason bridge broken. + * + * \return Nothing + */ +void ast_bridge_end_dtmf(struct ast_channel *chan, char digit, struct timeval start, const char *why); + /*! \brief Bridge a call, optionally allowing redirection */ int ast_bridge_call(struct ast_channel *chan, struct ast_channel *peer,struct ast_bridge_config *config); Index: include/asterisk/channel.h =================================================================== --- include/asterisk/channel.h (revision 375354) +++ include/asterisk/channel.h (working copy) @@ -870,6 +870,8 @@ char macrocontext[AST_MAX_CONTEXT]; /*!< Macro: Current non-macro context. See app_macro.c */ char macroexten[AST_MAX_EXTENSION]; /*!< Macro: Current non-macro extension. See app_macro.c */ char emulate_dtmf_digit; /*!< Digit being emulated */ + char sending_dtmf_digit; /*!< Digit the channel is currently sending. (zero if not sending) */ + struct timeval sending_dtmf_tv; /*!< The time started sending current digit. */ }; /*! \brief ast_channel_tech Properties */ Index: main/channel.c =================================================================== --- main/channel.c (revision 375354) +++ main/channel.c (working copy) @@ -71,6 +71,7 @@ #include "asterisk/stringfields.h" #include "asterisk/global_datastores.h" #include "asterisk/data.h" +#include "asterisk/features.h" #ifdef HAVE_EPOLL #include @@ -4661,6 +4662,11 @@ if (!chan->tech->send_digit_begin) return 0; + ast_channel_lock(chan); + chan->sending_dtmf_digit = digit; + chan->sending_dtmf_tv = ast_tvnow(); + ast_channel_unlock(chan); + if (!chan->tech->send_digit_begin(chan, digit)) return 0; @@ -4684,6 +4690,12 @@ { int res = -1; + ast_channel_lock(chan); + if (chan->sending_dtmf_digit == digit) { + chan->sending_dtmf_digit = 0; + } + ast_channel_unlock(chan); + if (chan->tech->send_digit_end) res = chan->tech->send_digit_end(chan, digit, duration); @@ -6491,6 +6503,8 @@ char orig[AST_CHANNEL_NAME]; char masqn[AST_CHANNEL_NAME]; char zombn[AST_CHANNEL_NAME]; + char clone_sending_dtmf_digit; + struct timeval clone_sending_dtmf_tv; /* XXX This operation is a bit odd. We're essentially putting the guts of * the clone channel into the original channel. Start by killing off the @@ -6600,6 +6614,10 @@ free_translation(clonechan); free_translation(original); + /* Save the current DTMF digit being sent if any. */ + clone_sending_dtmf_digit = clonechan->sending_dtmf_digit; + clone_sending_dtmf_tv = clonechan->sending_dtmf_tv; + /* Save the original name */ ast_copy_string(orig, original->name, sizeof(orig)); /* Save the new name */ @@ -6844,6 +6862,15 @@ ast_channel_unlock(clonechan); + if (clone_sending_dtmf_digit) { + /* + * The clonechan was sending a DTMF digit that was not completed + * before the masquerade. + */ + ast_bridge_end_dtmf(original, clone_sending_dtmf_digit, clone_sending_dtmf_tv, + "masquerade"); + } + /* * If an indication is currently playing, maintain it on the * channel that is taking the place of original. Index: main/features.c =================================================================== --- main/features.c (revision 375354) +++ main/features.c (working copy) @@ -3891,6 +3891,24 @@ ast_channel_unlock(chan); } +void ast_bridge_end_dtmf(struct ast_channel *chan, char digit, struct timeval start, const char *why) +{ + int dead; + long duration; + + ast_channel_lock(chan); + dead = ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan); + ast_channel_unlock(chan); + if (dead) { + return; + } + + duration = ast_tvdiff_ms(ast_tvnow(), start); + ast_senddigit_end(chan, digit, duration); + ast_log(LOG_DTMF, "DTMF end '%c' simulated on %s due to %s, duration %ld ms\n", + digit, chan->name, why, duration); +} + /*! * \brief bridge the call and set CDR * @@ -4337,6 +4355,15 @@ ast_cel_report_event(chan, AST_CEL_BRIDGE_END, NULL, NULL, peer); before_you_go: + if (chan->sending_dtmf_digit) { + ast_bridge_end_dtmf(chan, chan->sending_dtmf_digit, chan->sending_dtmf_tv, + "bridge end"); + } + if (peer->sending_dtmf_digit) { + ast_bridge_end_dtmf(peer, peer->sending_dtmf_digit, peer->sending_dtmf_tv, + "bridge end"); + } + /* Just in case something weird happened and we didn't clean up the silence generator... */ if (silgen) { ast_channel_stop_silence_generator(who == chan ? peer : chan, silgen);