mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-10-29 14:44:17 +00:00
fix buffering issue in mod_shout/core
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11200 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
1 parent
748716a56f
commit
cbc680adc0
3 files changed
+44
-23
No files matched your search
+16
-10
@@ -119,7 +119,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file,
|
||||
|
||||
if (fh->pre_buffer_datalen) {
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Prebuffering %d bytes\n", (int)fh->pre_buffer_datalen);
|
||||
switch_buffer_create_dynamic(&fh->pre_buffer, fh->pre_buffer_datalen, fh->pre_buffer_datalen / 2, 0);
|
||||
switch_buffer_create_dynamic(&fh->pre_buffer, fh->pre_buffer_datalen * fh->channels, fh->pre_buffer_datalen * fh->channels / 2, 0);
|
||||
fh->pre_buffer_data = switch_core_alloc(fh->memory_pool, fh->pre_buffer_datalen);
|
||||
}
|
||||
|
||||
@@ -248,16 +248,20 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
|
||||
if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->native_rate != fh->samplerate) {
|
||||
if (!fh->resampler) {
|
||||
if (switch_resample_create(&fh->resampler,
|
||||
fh->native_rate, orig_len, fh->samplerate, (uint32_t) orig_len, fh->memory_pool) != SWITCH_STATUS_SUCCESS) {
|
||||
fh->native_rate,
|
||||
orig_len * fh->channels,
|
||||
fh->samplerate,
|
||||
(uint32_t) orig_len *fh->channels,
|
||||
fh->memory_pool) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
}
|
||||
|
||||
fh->resampler->from_len = switch_short_to_float(data, fh->resampler->from, (int) *len);
|
||||
fh->resampler->from_len = switch_short_to_float(data, fh->resampler->from, (int) *len * fh->channels);
|
||||
fh->resampler->to_len =
|
||||
switch_resample_process(fh->resampler, fh->resampler->from, fh->resampler->from_len, fh->resampler->to, fh->resampler->to_size, 0);
|
||||
if (fh->resampler->to_len > orig_len) {
|
||||
if (fh->resampler->to_len > orig_len * fh->channels) {
|
||||
if (!fh->dbuf) {
|
||||
fh->dbuflen = fh->resampler->to_len * 2;
|
||||
fh->dbuf = switch_core_alloc(fh->memory_pool, fh->dbuflen);
|
||||
@@ -269,7 +273,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
|
||||
switch_float_to_short(fh->resampler->to, data, fh->resampler->to_len);
|
||||
}
|
||||
|
||||
*len = fh->resampler->to_len;
|
||||
*len = fh->resampler->to_len / fh->channels;
|
||||
|
||||
}
|
||||
|
||||
@@ -282,13 +286,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
|
||||
switch_size_t rlen, blen;
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
int asis = switch_test_flag(fh, SWITCH_FILE_NATIVE);
|
||||
|
||||
switch_buffer_write(fh->pre_buffer, data, asis ? *len : *len * 2);
|
||||
|
||||
switch_buffer_write(fh->pre_buffer, data, (asis ? *len : *len * 2) * fh->channels);
|
||||
|
||||
rlen = switch_buffer_inuse(fh->pre_buffer);
|
||||
if (rlen >= fh->pre_buffer_datalen) {
|
||||
blen = switch_buffer_read(fh->pre_buffer, fh->pre_buffer_data, fh->pre_buffer_datalen);
|
||||
if (!asis) blen /= 2;
|
||||
if (fh->channels) blen /= fh->channels;
|
||||
if ((status = fh->file_interface->file_write(fh, fh->pre_buffer_data, &blen)) != SWITCH_STATUS_SUCCESS) {
|
||||
*len = 0;
|
||||
}
|
||||
@@ -354,9 +359,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_close(switch_file_handle_t *fh)
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
switch_clear_flag(fh, SWITCH_FILE_OPEN);
|
||||
status = fh->file_interface->file_close(fh);
|
||||
|
||||
if (fh->buffer) {
|
||||
switch_buffer_destroy(&fh->buffer);
|
||||
}
|
||||
@@ -369,6 +371,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_close(switch_file_handle_t *fh)
|
||||
while((rlen = switch_buffer_inuse(fh->pre_buffer))) {
|
||||
blen = switch_buffer_read(fh->pre_buffer, fh->pre_buffer_data, fh->pre_buffer_datalen);
|
||||
if (asis) blen /= 2;
|
||||
if (fh->channels) blen /= fh->channels;
|
||||
if (fh->file_interface->file_write(fh, fh->pre_buffer_data, &blen) != SWITCH_STATUS_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
@@ -378,6 +381,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_close(switch_file_handle_t *fh)
|
||||
switch_buffer_destroy(&fh->pre_buffer);
|
||||
}
|
||||
|
||||
switch_clear_flag(fh, SWITCH_FILE_OPEN);
|
||||
status = fh->file_interface->file_close(fh);
|
||||
|
||||
switch_resample_destroy(&fh->resampler);
|
||||
|
||||
UNPROTECT_INTERFACE(fh->file_interface);
|
||||
|
||||
Reference in new issue
Block a user