test_channel_feature_hooks.c: Fix unit test for DTMF hooks.

Fix the failing /channels/features/test_features_channel_dtmf unit test.

DTMF emulation does not work without a stream of packets to prod the
emulation code.

Review: https://reviewboard.asterisk.org/r/4199/
........

Merged revisions 428604 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@428605 65c4cc65-6c06-0410-ace0-fbb531ad65f3
changes/42/42/1
Richard Mudgett 11 years ago
parent c38ffca9a1
commit 3e08619faf

@ -76,12 +76,10 @@ static void wait_for_bridged(struct ast_channel *channel)
/*! \brief Wait until a channel is not bridged */ /*! \brief Wait until a channel is not bridged */
static void wait_for_unbridged(struct ast_channel *channel) static void wait_for_unbridged(struct ast_channel *channel)
{ {
struct timespec short_sleep = {0, 1000000};
ast_channel_lock(channel); ast_channel_lock(channel);
while (ast_channel_is_bridged(channel)) { while (ast_channel_is_bridged(channel)) {
ast_channel_unlock(channel); ast_channel_unlock(channel);
while ((nanosleep(&short_sleep, &short_sleep) == -1) && (errno == EINTR)) { test_nanosleep(0, 1000000);
}
ast_channel_lock(channel); ast_channel_lock(channel);
} }
ast_channel_unlock(channel); ast_channel_unlock(channel);
@ -130,6 +128,29 @@ static int feature_callback(struct ast_bridge_channel *bridge_channel, void *obj
return 0; return 0;
} }
/* Need to post null frames periodically so DTMF emulation can work. */
static void stream_periodic_frames(struct ast_channel *chan, int ms, int interval_ms)
{
long nanosecs;
ast_assert(chan != NULL);
ast_assert(0 < ms);
ast_assert(0 < interval_ms);
nanosecs = interval_ms * 1000000L;
while (0 < ms) {
ast_queue_frame(chan, &ast_null_frame);
if (interval_ms < ms) {
ms -= interval_ms;
} else {
nanosecs = ms * 1000000L;
ms = 0;
}
test_nanosleep(0, nanosecs);
}
}
AST_TEST_DEFINE(test_features_channel_dtmf) AST_TEST_DEFINE(test_features_channel_dtmf)
{ {
RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release); RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
@ -185,7 +206,7 @@ AST_TEST_DEFINE(test_features_channel_dtmf)
ast_queue_frame(chan_alice, &f); ast_queue_frame(chan_alice, &f);
ast_queue_frame(chan_alice, &f); ast_queue_frame(chan_alice, &f);
test_nanosleep(1, 0); stream_periodic_frames(chan_alice, 1000, 20);
/* Remove the channels from the bridge */ /* Remove the channels from the bridge */
ast_test_validate(test, !ast_bridge_depart(chan_alice)); ast_test_validate(test, !ast_bridge_depart(chan_alice));
@ -208,7 +229,7 @@ AST_TEST_DEFINE(test_features_channel_dtmf)
ast_queue_frame(chan_alice, &f); ast_queue_frame(chan_alice, &f);
ast_queue_frame(chan_alice, &f); ast_queue_frame(chan_alice, &f);
test_nanosleep(1, 0); stream_periodic_frames(chan_alice, 1000, 20);
/* Remove the channels from the bridge */ /* Remove the channels from the bridge */
ast_test_validate(test, !ast_bridge_depart(chan_alice)); ast_test_validate(test, !ast_bridge_depart(chan_alice));

Loading…
Cancel
Save