From 913ec9861e07e3f432444f0ffdc57ac03148a3a3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 31 Mar 2011 15:01:58 -0500 Subject: [PATCH] FS-3176 forget the last patch I forgot there is no way to know the right codec using it the file string way, you will just have to manually specify en.PCMA as before but now it should work --- .../applications/mod_dptools/mod_dptools.c | 13 ++- src/switch_ivr_play_say.c | 110 ++++++++++-------- src/switch_loadable_module.c | 13 +-- 3 files changed, 76 insertions(+), 60 deletions(-) diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 038304b672..85bd718345 100755 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -3548,8 +3548,17 @@ static int next_file(switch_file_handle_t *handle) handle->speed = context->fh.speed; handle->interval = context->fh.interval; - if (context->index == 0) { - context->samples = (handle->samplerate / 1000) * 250; + if (switch_test_flag((&context->fh), SWITCH_FILE_NATIVE)) { + switch_set_flag(handle, SWITCH_FILE_NATIVE); + } else { + switch_clear_flag(handle, SWITCH_FILE_NATIVE); + } + + + if (!switch_test_flag(handle, SWITCH_FILE_NATIVE)) { + if (context->index == 0) { + context->samples = (handle->samplerate / 1000) * 250; + } } return 1; diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index 98dfd0f71e..39980f30d1 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -1000,7 +1000,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess switch_file_handle_t lfh; const char *p; char *title = "", *copyright = "", *software = "", *artist = "", *comment = "", *date = ""; - uint8_t asis = 0; char *ext; const char *prefix; const char *timer_name; @@ -1024,6 +1023,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess int more_data = 0; char *playback_vars, *tmp; switch_event_t *event; + uint32_t test_native = 0, last_native = 0; if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) { return SWITCH_STATUS_FALSE; @@ -1073,7 +1073,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess for (cur = 0; switch_channel_ready(channel) && !done && cur < argc; cur++) { file = argv[cur]; - asis = 0; eof = 0; if (cur) { @@ -1168,7 +1167,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess } else { ext = read_impl.iananame; file = switch_core_session_sprintf(session, "%s.%s", file, ext); - asis = 1; } } @@ -1221,9 +1219,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess switch_channel_set_private(channel, "__fh", fh); switch_core_session_io_rwunlock(session); - if (switch_test_flag(fh, SWITCH_FILE_NATIVE)) { - asis = 1; - } if (!abuf) { switch_zmalloc(abuf, FILE_STARTSAMPLES * sizeof(*abuf)); @@ -1275,43 +1270,46 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess switch_assert(fh->audio_buffer); } - if (asis) { + codec_name = "L16"; + + if (!switch_core_codec_ready((&codec))) { + if (switch_core_codec_init(&codec, + codec_name, + NULL, + fh->samplerate, + interval, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, pool) == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), + SWITCH_LOG_DEBUG, "Codec Activated %s@%uhz %u channels %dms\n", codec_name, fh->samplerate, fh->channels, interval); + + + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, + "Raw Codec Activation Failed %s@%uhz %u channels %dms\n", codec_name, fh->samplerate, fh->channels, interval); + switch_core_session_io_write_lock(session); + switch_channel_set_private(channel, "__fh", NULL); + switch_core_session_io_rwunlock(session); + + switch_core_file_close(fh); + + switch_core_session_reset(session, SWITCH_TRUE, SWITCH_FALSE); + status = SWITCH_STATUS_GENERR; + continue; + } + } + + test_native = switch_test_flag(fh, SWITCH_FILE_NATIVE); + + if (test_native) { write_frame.codec = switch_core_session_get_read_codec(session); samples = read_impl.samples_per_packet; framelen = read_impl.encoded_bytes_per_packet; } else { - codec_name = "L16"; - - if (!switch_core_codec_ready((&codec))) { - if (switch_core_codec_init(&codec, - codec_name, - NULL, - fh->samplerate, - interval, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, pool) == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), - SWITCH_LOG_DEBUG, "Codec Activated %s@%uhz %u channels %dms\n", codec_name, fh->samplerate, fh->channels, interval); - - - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, - "Raw Codec Activation Failed %s@%uhz %u channels %dms\n", codec_name, fh->samplerate, fh->channels, interval); - switch_core_session_io_write_lock(session); - switch_channel_set_private(channel, "__fh", NULL); - switch_core_session_io_rwunlock(session); - - switch_core_file_close(fh); - - switch_core_session_reset(session, SWITCH_TRUE, SWITCH_FALSE); - status = SWITCH_STATUS_GENERR; - continue; - } - } - write_frame.codec = &codec; - samples = codec.implementation->samples_per_packet; framelen = codec.implementation->decoded_bytes_per_packet; } + + last_native = test_native; if (timer_name && !timer.samplecount) { uint32_t len; @@ -1429,7 +1427,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess memset(abuf + bread, 255, framelen - bread); } - olen = asis ? framelen : ilen; + olen = switch_test_flag(fh, SWITCH_FILE_NATIVE) ? framelen : ilen; do_speed = 0; } else if (fh->audio_buffer && (eof || (switch_buffer_inuse(fh->audio_buffer) > (switch_size_t) (framelen)))) { if (!(bread = switch_buffer_read(fh->audio_buffer, abuf, framelen))) { @@ -1440,30 +1438,48 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess } } - fh->offset_pos += asis ? bread : bread / 2; + fh->offset_pos += switch_test_flag(fh, SWITCH_FILE_NATIVE) ? bread : bread / 2; if (bread < framelen) { memset(abuf + bread, 255, framelen - bread); } - olen = asis ? framelen : ilen; + olen = switch_test_flag(fh, SWITCH_FILE_NATIVE) ? framelen : ilen; } else { if (eof) { break; } olen = FILE_STARTSAMPLES; - if (!asis) { + if (!switch_test_flag(fh, SWITCH_FILE_NATIVE)) { olen /= 2; } if (switch_core_file_read(fh, abuf, &olen) != SWITCH_STATUS_SUCCESS) { eof++; continue; } - switch_buffer_write(fh->audio_buffer, abuf, asis ? olen : olen * 2); + + test_native = switch_test_flag(fh, SWITCH_FILE_NATIVE); + + if (test_native != last_native) { + if (test_native) { + write_frame.codec = switch_core_session_get_read_codec(session); + samples = read_impl.samples_per_packet; + framelen = read_impl.encoded_bytes_per_packet; + } else { + write_frame.codec = &codec; + samples = codec.implementation->samples_per_packet; + framelen = codec.implementation->decoded_bytes_per_packet; + } + switch_buffer_zero(fh->audio_buffer); + } + + last_native = test_native; + + switch_buffer_write(fh->audio_buffer, abuf, switch_test_flag(fh, SWITCH_FILE_NATIVE) ? olen : olen * 2); olen = switch_buffer_read(fh->audio_buffer, abuf, framelen); fh->offset_pos += olen / 2; - if (!asis) { + if (!switch_test_flag(fh, SWITCH_FILE_NATIVE)) { olen /= 2; } @@ -1473,7 +1489,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess break; } - if (!asis) { + if (!switch_test_flag(fh, SWITCH_FILE_NATIVE)) { if (fh->speed > 2) { fh->speed = 2; } else if (fh->speed < -2) { @@ -1481,7 +1497,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess } } - if (!asis && fh->audio_buffer && last_speed > -1 && last_speed != fh->speed) { + if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->audio_buffer && last_speed > -1 && last_speed != fh->speed) { switch_buffer_zero(fh->sp_audio_buffer); } @@ -1492,7 +1508,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess } - if (!asis && fh->speed && do_speed) { + if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->speed && do_speed) { float factor = 0.25f * abs(fh->speed); switch_size_t newlen, supplement, step; short *bp = write_frame.data; @@ -1583,7 +1599,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess more_data = 0; write_frame.samples = (uint32_t) olen; - if (asis) { + if (switch_test_flag(fh, SWITCH_FILE_NATIVE)) { write_frame.datalen = (uint32_t) olen; } else { write_frame.datalen = write_frame.samples * 2; @@ -1596,12 +1612,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess } #ifndef WIN32 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN - if (!asis && l16) { + if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && l16) { switch_swap_linear(write_frame.data, (int) write_frame.datalen / 2); } #endif #endif - if (!asis && fh->vol) { + if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->vol) { switch_change_sln_volume(write_frame.data, write_frame.datalen / 2, fh->vol); } diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index 0c803a71b4..9804e53238 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -1995,23 +1995,14 @@ SWITCH_DECLARE(void) switch_say_file(switch_say_file_handle_t *sh, const char *f char buf[256] = ""; int ret; va_list ap; - int native = !strcasecmp(sh->ext, "native"); va_start(ap, fmt); if ((ret = switch_vsnprintf(buf, sizeof(buf), fmt, ap)) > 0) { if (!sh->cnt++) { - if (native) { - sh->stream.write_function(&sh->stream, "file_string://%s", buf); - } else { - sh->stream.write_function(&sh->stream, "file_string://%s.%s", buf, sh->ext); - } + sh->stream.write_function(&sh->stream, "file_string://%s.%s", buf, sh->ext); } else { - if (native) { - sh->stream.write_function(&sh->stream, "!%s", buf); - } else { - sh->stream.write_function(&sh->stream, "!%s.%s", buf, sh->ext); - } + sh->stream.write_function(&sh->stream, "!%s.%s", buf, sh->ext); } }