diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index 40069b0178..b699c7479a 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -1969,6 +1969,17 @@ int ast_is_deferrable_frame(const struct ast_frame *frame); */ int ast_safe_sleep(struct ast_channel *chan, int ms); +/*! + * \brief Wait for a specified amount of time, looking for hangups, and do not generate silence + * \param chan channel to wait for + * \param ms length of time in milliseconds to sleep. This should never be less than zero. + * \details + * Waits for a specified amount of time, servicing the channel as required. + * \return returns -1 on hangup, otherwise 0. + * \note Unlike ast_safe_sleep this will not generate silence if Asterisk is configured to do so. + */ +int ast_safe_sleep_without_silence(struct ast_channel *chan, int ms); + /*! * \brief Wait for a specified amount of time, looking for hangups and a condition argument * \param chan channel to wait for diff --git a/main/channel.c b/main/channel.c index 42083c3f47..9e33fb25fc 100644 --- a/main/channel.c +++ b/main/channel.c @@ -1491,7 +1491,7 @@ int ast_is_deferrable_frame(const struct ast_frame *frame) } /*! \brief Wait, look for hangups and condition arg */ -int ast_safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*cond)(void*), void *data) +static int safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*cond)(void*), void *data, unsigned int generate_silence) { struct ast_frame *f; struct ast_silence_generator *silgen = NULL; @@ -1503,7 +1503,7 @@ int ast_safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*c AST_LIST_HEAD_INIT_NOLOCK(&deferred_frames); /* If no other generator is present, start silencegen while waiting */ - if (ast_opt_transmit_silence && !ast_channel_generatordata(chan)) { + if (generate_silence && ast_opt_transmit_silence && !ast_channel_generatordata(chan)) { silgen = ast_channel_start_silence_generator(chan); } @@ -1561,10 +1561,20 @@ int ast_safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*c return res; } +int ast_safe_sleep_conditional(struct ast_channel *chan, int timeout_ms, int (*cond)(void*), void *data) +{ + return safe_sleep_conditional(chan, timeout_ms, cond, data, 1); +} + /*! \brief Wait, look for hangups */ int ast_safe_sleep(struct ast_channel *chan, int ms) { - return ast_safe_sleep_conditional(chan, ms, NULL, NULL); + return safe_sleep_conditional(chan, ms, NULL, NULL, 1); +} + +int ast_safe_sleep_without_silence(struct ast_channel *chan, int ms) +{ + return safe_sleep_conditional(chan, ms, NULL, NULL, 0); } struct ast_channel *ast_channel_release(struct ast_channel *chan) diff --git a/main/pbx.c b/main/pbx.c index 0609240a32..d0ee127389 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -8275,7 +8275,7 @@ void wait_for_hangup(struct ast_channel *chan, const void *data) waitsec = -1; if (waitsec > -1) { waittime = waitsec * 1000.0; - ast_safe_sleep(chan, waittime); + ast_safe_sleep_without_silence(chan, waittime); } else do { res = ast_waitfor(chan, -1); if (res < 0)