FS-11569 add rate to null endpoint

This commit is contained in:
Seven Du 2018-12-14 10:52:00 +08:00 committed by Chris Rienzo
parent 97f42d429f
commit 1ddd4c992b
2 changed files with 29 additions and 6 deletions

View File

@ -416,8 +416,10 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir,
* switch_channel_t *fst_channel; The outbound null session's channel.
*
* @param name the name of this test
* @param rate the rate of the channel
*/
#define FST_SESSION_BEGIN(name) \
#define FST_SESSION_BEGIN_RATE(name, rate) \
FCT_TEST_BGN(name) \
{ \
switch_core_session_t *fst_session = NULL; \
@ -432,6 +434,7 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir,
fst_requires(switch_core_running()); \
fst_requires(switch_event_create_plain(&fst_originate_vars, SWITCH_EVENT_CHANNEL_DATA) == SWITCH_STATUS_SUCCESS); \
switch_event_add_header_string(fst_originate_vars, SWITCH_STACK_BOTTOM, "origination_caller_id_number", "+15551112222"); \
switch_event_add_header(fst_originate_vars, SWITCH_STACK_BOTTOM, "rate", "%d", rate); \
if (switch_ivr_originate(NULL, &fst_session, &fst_cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, fst_originate_vars, SOF_NONE, NULL, NULL) == SWITCH_STATUS_SUCCESS && fst_session) { \
switch_memory_pool_t *fst_session_pool = switch_core_session_get_pool(fst_session); \
switch_channel_t *fst_channel = switch_core_session_get_channel(fst_session); \
@ -442,6 +445,13 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir,
switch_ivr_record_session(fst_session, (char *)"/tmp/"#name".wav", 0, NULL); \
for(;;) {
/**
* Define a session test in a test suite. This can be used to test IVR functions.
* See FST_SESSION_BEGIN_RATE
*/
#define FST_SESSION_BEGIN(name) FST_SESSION_BEGIN_RATE(name, 8000)
/* BODY OF TEST CASE HERE */
/**

View File

@ -1220,6 +1220,7 @@ struct null_private_object {
switch_caller_profile_t *caller_profile;
switch_frame_t read_frame;
int16_t *null_buf;
int rate;
};
typedef struct null_private_object null_private_t;
@ -1239,20 +1240,19 @@ static switch_status_t null_channel_kill_channel(switch_core_session_t *session,
static switch_status_t null_tech_init(null_private_t *tech_pvt, switch_core_session_t *session)
{
const char *iananame = "L16";
uint32_t rate = 8000;
uint32_t interval = 20;
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_channel_t *channel = switch_core_session_get_channel(session);
const switch_codec_implementation_t *read_impl;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s setup codec %s/%d/%d\n", switch_channel_get_name(channel), iananame, rate,
interval);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s setup codec %s/%d/%d\n",
switch_channel_get_name(channel), iananame, tech_pvt->rate, interval);
status = switch_core_codec_init(&tech_pvt->read_codec,
iananame,
NULL,
NULL,
rate, interval, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session));
tech_pvt->rate, interval, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session));
if (status != SWITCH_STATUS_SUCCESS || !tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) {
goto end;
@ -1262,7 +1262,7 @@ static switch_status_t null_tech_init(null_private_t *tech_pvt, switch_core_sess
iananame,
NULL,
NULL,
rate, interval, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session));
tech_pvt->rate, interval, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session));
if (status != SWITCH_STATUS_SUCCESS) {
@ -1494,6 +1494,19 @@ static switch_call_cause_t null_channel_outgoing_channel(switch_core_session_t *
switch_core_session_add_stream(*new_session, NULL);
if ((tech_pvt = (null_private_t *) switch_core_session_alloc(*new_session, sizeof(null_private_t))) != 0) {
const char *rate_ = switch_event_get_header(var_event, "rate");
int rate = 0;
if (rate_) {
rate = atoi(rate_);
}
if (!(rate > 0 && rate % 8000 == 0)) {
rate = 8000;
}
tech_pvt->rate = rate;
channel = switch_core_session_get_channel(*new_session);
switch_snprintf(name, sizeof(name), "null/%s", outbound_profile->destination_number);
switch_channel_set_name(channel, name);