FS-5807 contd

This commit is contained in:
Anthony Minessale 2013-09-20 23:34:57 +05:00
parent 235a7c5683
commit 8084c28d62
5 changed files with 48 additions and 11 deletions

View File

@ -310,7 +310,7 @@ struct switch_file_handle {
/*! the current native samplerate */ /*! the current native samplerate */
uint32_t native_rate; uint32_t native_rate;
/*! the number of channels */ /*! the number of channels */
uint8_t channels; uint32_t channels;
/*! integer representation of the format */ /*! integer representation of the format */
unsigned int format; unsigned int format;
/*! integer representation of the sections */ /*! integer representation of the sections */
@ -353,6 +353,8 @@ struct switch_file_handle {
const char *prefix; const char *prefix;
int max_samples; int max_samples;
switch_event_t *params; switch_event_t *params;
uint32_t cur_channels;
uint32_t cur_samplerate;
}; };
/*! \brief Abstract interface to an asr module */ /*! \brief Abstract interface to an asr module */

View File

@ -1581,7 +1581,8 @@ typedef enum {
SWITCH_FILE_BUFFER_DONE = (1 << 14), SWITCH_FILE_BUFFER_DONE = (1 << 14),
SWITCH_FILE_WRITE_APPEND = (1 << 15), SWITCH_FILE_WRITE_APPEND = (1 << 15),
SWITCH_FILE_WRITE_OVER = (1 << 16), SWITCH_FILE_WRITE_OVER = (1 << 16),
SWITCH_FILE_NOMUX = (1 << 17) SWITCH_FILE_NOMUX = (1 << 17),
SWITCH_FILE_BREAK_ON_CHANGE = (1 << 18)
} switch_file_flag_enum_t; } switch_file_flag_enum_t;
typedef uint32_t switch_file_flag_t; typedef uint32_t switch_file_flag_t;

View File

@ -4509,8 +4509,8 @@ static switch_status_t next_file(switch_file_handle_t *handle)
} }
handle->samples = context->fh.samples; handle->samples = context->fh.samples;
//handle->samplerate = context->fh.samplerate; handle->cur_samplerate = context->fh.samplerate;
//handle->channels = context->fh.channels; handle->cur_channels = context->fh.channels;
handle->format = context->fh.format; handle->format = context->fh.format;
handle->sections = context->fh.sections; handle->sections = context->fh.sections;
handle->seekable = context->fh.seekable; handle->seekable = context->fh.seekable;
@ -4518,6 +4518,7 @@ static switch_status_t next_file(switch_file_handle_t *handle)
handle->interval = context->fh.interval; handle->interval = context->fh.interval;
handle->max_samples = 0; handle->max_samples = 0;
if (switch_test_flag((&context->fh), SWITCH_FILE_NATIVE)) { if (switch_test_flag((&context->fh), SWITCH_FILE_NATIVE)) {
switch_set_flag(handle, SWITCH_FILE_NATIVE); switch_set_flag(handle, SWITCH_FILE_NATIVE);
} else { } else {
@ -4602,8 +4603,13 @@ static switch_status_t file_string_file_read(switch_file_handle_t *handle, void
if ((status = next_file(handle)) != SWITCH_STATUS_SUCCESS) { if ((status = next_file(handle)) != SWITCH_STATUS_SUCCESS) {
return status; return status;
} }
*len = llen; if (switch_test_flag(handle, SWITCH_FILE_BREAK_ON_CHANGE)) {
status = switch_core_file_read(&context->fh, data, len); *len = 0;
status = SWITCH_STATUS_BREAK;
} else {
*len = llen;
status = switch_core_file_read(&context->fh, data, len);
}
} }
return status; return status;

View File

@ -292,7 +292,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh,
rlen = asis ? fh->pre_buffer_datalen : fh->pre_buffer_datalen / 2; rlen = asis ? fh->pre_buffer_datalen : fh->pre_buffer_datalen / 2;
if (switch_buffer_inuse(fh->pre_buffer) < rlen * 2) { if (switch_buffer_inuse(fh->pre_buffer) < rlen * 2) {
if ((status = fh->file_interface->file_read(fh, fh->pre_buffer_data, &rlen)) != SWITCH_STATUS_SUCCESS || !rlen) { if ((status = fh->file_interface->file_read(fh, fh->pre_buffer_data, &rlen)) == SWITCH_STATUS_BREAK) {
return SWITCH_STATUS_BREAK;
}
if (status != SWITCH_STATUS_SUCCESS || !rlen) {
switch_set_flag(fh, SWITCH_FILE_BUFFER_DONE); switch_set_flag(fh, SWITCH_FILE_BUFFER_DONE);
} else { } else {
fh->samples_in += rlen; fh->samples_in += rlen;
@ -316,7 +321,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh,
} else { } else {
if ((status = fh->file_interface->file_read(fh, data, len)) != SWITCH_STATUS_SUCCESS || !*len) { if ((status = fh->file_interface->file_read(fh, data, len)) == SWITCH_STATUS_BREAK) {
return SWITCH_STATUS_BREAK;
}
if (status != SWITCH_STATUS_SUCCESS || !*len) {
switch_set_flag(fh, SWITCH_FILE_DONE); switch_set_flag(fh, SWITCH_FILE_DONE);
goto top; goto top;
} }

View File

@ -1049,6 +1049,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
int more_data = 0; int more_data = 0;
switch_event_t *event; switch_event_t *event;
uint32_t test_native = 0, last_native = 0; uint32_t test_native = 0, last_native = 0;
uint32_t buflen = 0;
if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) { if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
@ -1110,6 +1111,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
fh->samples = 0; fh->samples = 0;
} }
for (cur = 0; switch_channel_ready(channel) && !done && cur < argc; cur++) { for (cur = 0; switch_channel_ready(channel) && !done && cur < argc; cur++) {
file = argv[cur]; file = argv[cur];
eof = 0; eof = 0;
@ -1255,9 +1259,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
if (!abuf) { if (!abuf) {
switch_zmalloc(abuf, FILE_STARTSAMPLES * sizeof(*abuf) * fh->channels); buflen = write_frame.buflen = FILE_STARTSAMPLES * sizeof(*abuf) * fh->channels;
switch_zmalloc(abuf, write_frame.buflen);
write_frame.data = abuf; write_frame.data = abuf;
write_frame.buflen = FILE_STARTSAMPLES;
} }
if (sample_start > 0) { if (sample_start > 0) {
@ -1454,6 +1458,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
} }
} }
buflen = FILE_STARTSAMPLES * sizeof(*abuf) * fh->cur_channels;
if (buflen > write_frame.buflen) {
abuf = realloc(abuf, buflen);
write_frame.data = abuf;
write_frame.buflen = buflen;
}
if (switch_test_flag(fh, SWITCH_FILE_PAUSE)) { if (switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
if (framelen > FILE_STARTSAMPLES) { if (framelen > FILE_STARTSAMPLES) {
framelen = FILE_STARTSAMPLES; framelen = FILE_STARTSAMPLES;
@ -1493,6 +1505,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
olen = switch_test_flag(fh, SWITCH_FILE_NATIVE) ? framelen : ilen; olen = switch_test_flag(fh, SWITCH_FILE_NATIVE) ? framelen : ilen;
} else { } else {
switch_status_t rstatus;
if (eof) { if (eof) {
break; break;
} }
@ -1500,7 +1514,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
if (!switch_test_flag(fh, SWITCH_FILE_NATIVE)) { if (!switch_test_flag(fh, SWITCH_FILE_NATIVE)) {
olen /= 2; olen /= 2;
} }
if (switch_core_file_read(fh, abuf, &olen) != SWITCH_STATUS_SUCCESS) { switch_set_flag(fh, SWITCH_FILE_BREAK_ON_CHANGE);
if ((rstatus = switch_core_file_read(fh, abuf, &olen)) == SWITCH_STATUS_BREAK) {
continue;
}
if (rstatus != SWITCH_STATUS_SUCCESS) {
eof++; eof++;
continue; continue;
} }