/*! the current native samplerate */
uint32_t native_rate;
/*! the number of channels */
- uint8_t channels;
+ uint32_t channels;
/*! integer representation of the format */
unsigned int format;
/*! integer representation of the sections */
const char *prefix;
int max_samples;
switch_event_t *params;
+ uint32_t cur_channels;
+ uint32_t cur_samplerate;
};
/*! \brief Abstract interface to an asr module */
SWITCH_FILE_BUFFER_DONE = (1 << 14),
SWITCH_FILE_WRITE_APPEND = (1 << 15),
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;
typedef uint32_t switch_file_flag_t;
}
handle->samples = context->fh.samples;
- //handle->samplerate = context->fh.samplerate;
- //handle->channels = context->fh.channels;
+ handle->cur_samplerate = context->fh.samplerate;
+ handle->cur_channels = context->fh.channels;
handle->format = context->fh.format;
handle->sections = context->fh.sections;
handle->seekable = context->fh.seekable;
handle->interval = context->fh.interval;
handle->max_samples = 0;
+
if (switch_test_flag((&context->fh), SWITCH_FILE_NATIVE)) {
switch_set_flag(handle, SWITCH_FILE_NATIVE);
} else {
if ((status = next_file(handle)) != SWITCH_STATUS_SUCCESS) {
return status;
}
- *len = llen;
- status = switch_core_file_read(&context->fh, data, len);
+ if (switch_test_flag(handle, SWITCH_FILE_BREAK_ON_CHANGE)) {
+ *len = 0;
+ status = SWITCH_STATUS_BREAK;
+ } else {
+ *len = llen;
+ status = switch_core_file_read(&context->fh, data, len);
+ }
}
return status;
rlen = asis ? fh->pre_buffer_datalen : fh->pre_buffer_datalen / 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);
} else {
fh->samples_in += rlen;
} 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);
goto top;
}
int more_data = 0;
switch_event_t *event;
uint32_t test_native = 0, last_native = 0;
+ uint32_t buflen = 0;
if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
fh->samples = 0;
}
+
+
+
for (cur = 0; switch_channel_ready(channel) && !done && cur < argc; cur++) {
file = argv[cur];
eof = 0;
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.buflen = FILE_STARTSAMPLES;
}
if (sample_start > 0) {
}
}
+ 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 (framelen > FILE_STARTSAMPLES) {
framelen = FILE_STARTSAMPLES;
olen = switch_test_flag(fh, SWITCH_FILE_NATIVE) ? framelen : ilen;
} else {
+ switch_status_t rstatus;
+
if (eof) {
break;
}
if (!switch_test_flag(fh, SWITCH_FILE_NATIVE)) {
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++;
continue;
}