fix using native_file as ringback on codecs that have passthru only

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14980 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2009-09-25 18:26:47 +00:00
parent 374925d9ba
commit a9936c09e8

View File

@ -673,16 +673,33 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
if (read_codec && ringback_data) {
if (switch_is_file_path(ringback_data)) {
if (!(strrchr(ringback_data, '.') || strstr(ringback_data, SWITCH_URL_SEPARATOR))) {
ringback.asis++;
}
}
if (!ringback.asis) {
if (!(pass = (uint8_t) switch_test_flag(read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH))) {
goto no_ringback;
}
if (switch_core_codec_init(&write_codec,
"L16",
NULL,
read_codec->implementation->actual_samples_per_second,
read_codec->implementation->microseconds_per_packet / 1000,
1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec Error!\n");
if (caller_channel) {
switch_channel_hangup(caller_channel, SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE);
}
read_codec = NULL;
goto done;
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
"Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_packet / 1000);
@ -691,6 +708,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
write_frame.datalen = read_codec->implementation->decoded_bytes_per_packet;
write_frame.samples = write_frame.datalen / 2;
memset(write_frame.data, 255, write_frame.datalen);
switch_core_session_set_read_codec(session, &write_codec);
}
}
if (ringback_data) {
char *tmp_data = NULL;
@ -698,10 +718,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
if (switch_is_file_path(ringback_data)) {
char *ext;
if (strrchr(ringback_data, '.') || strstr(ringback_data, SWITCH_URL_SEPARATOR)) {
switch_core_session_set_read_codec(session, &write_codec);
} else {
ringback.asis++;
if (ringback.asis) {
write_frame.codec = read_codec;
ext = read_codec->implementation->iananame;
tmp_data = switch_mprintf("%s.%s", ringback_data, ext);
@ -751,16 +768,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
}
switch_safe_free(tmp_data);
}
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Codec Error!\n");
if (caller_channel) {
switch_channel_hangup(caller_channel, SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE);
}
read_codec = NULL;
}
}
}
no_ringback:
while (switch_channel_ready(peer_channel)
&& !(switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA))) {
int diff = (int) (switch_micro_time_now() - start);
@ -1726,7 +1737,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
}
if (oglobals.session && (read_codec = switch_core_session_get_read_codec(oglobals.session)) && ringback_data) {
if (switch_is_file_path(ringback_data)) {
if (!(strrchr(ringback_data, '.') || strstr(ringback_data, SWITCH_URL_SEPARATOR))) {
ringback.asis++;
}
}
if (!ringback.asis) {
if (!(pass = (uint8_t) switch_test_flag(read_codec, SWITCH_CODEC_FLAG_PASSTHROUGH))) {
ringback_data = NULL;
goto no_ringback;
}
if (switch_core_codec_init(&write_codec,
"L16",
NULL,
@ -1744,6 +1766,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
write_frame.datalen = read_codec->implementation->decoded_bytes_per_packet;
write_frame.samples = write_frame.datalen / 2;
memset(write_frame.data, 255, write_frame.datalen);
switch_core_session_set_read_codec(oglobals.session, &write_codec);
} else {
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel), SWITCH_LOG_ERROR, "Codec Error!\n");
switch_channel_hangup(caller_channel, SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE);
read_codec = NULL;
goto done;
}
}
if (ringback_data) {
char *tmp_data = NULL;
@ -1753,10 +1783,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
if (switch_is_file_path(ringback_data)) {
char *ext;
if (strrchr(ringback_data, '.') || strstr(ringback_data, SWITCH_URL_SEPARATOR)) {
switch_core_session_set_read_codec(oglobals.session, &write_codec);
} else {
ringback.asis++;
if (ringback.asis) {
write_frame.codec = read_codec;
ext = read_codec->implementation->iananame;
tmp_data = switch_mprintf("%s.%s", ringback_data, ext);
@ -1808,14 +1835,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
}
switch_safe_free(tmp_data);
}
} else {
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(caller_channel), SWITCH_LOG_ERROR, "Codec Error!\n");
switch_channel_hangup(caller_channel, SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE);
read_codec = NULL;
}
}
}
no_ringback:
if (ringback_data) {
oglobals.early_ok = 0;
}