提交 913ec986 authored 作者: Anthony Minessale's avatar Anthony Minessale

FS-3176 forget the last patch I forgot there is no way to know the right codec…

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
上级 e52e44e3
......@@ -3548,9 +3548,18 @@ static int next_file(switch_file_handle_t *handle)
handle->speed = context->fh.speed;
handle->interval = context->fh.interval;
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;
}
......
......@@ -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,11 +1270,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
switch_assert(fh->audio_buffer);
}
if (asis) {
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))) {
......@@ -1307,12 +1297,20 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
}
}
write_frame.codec = &codec;
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 {
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);
}
......
......@@ -1995,24 +1995,15 @@ 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);
}
} else {
if (native) {
sh->stream.write_function(&sh->stream, "!%s", buf);
} else {
sh->stream.write_function(&sh->stream, "!%s.%s", buf, sh->ext);
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论