From a5367cd3866a1bd576b50f251f577a9b60e0a798 Mon Sep 17 00:00:00 2001 From: Brian West Date: Tue, 13 Jan 2009 21:43:55 +0000 Subject: [PATCH] buffer regressions git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11162 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../mod_local_stream/mod_local_stream.c | 24 +++++++++++++------ support-d/.emacs | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/mod/formats/mod_local_stream/mod_local_stream.c b/src/mod/formats/mod_local_stream/mod_local_stream.c index 49ca2bafa7..f099a3fc94 100644 --- a/src/mod/formats/mod_local_stream/mod_local_stream.c +++ b/src/mod/formats/mod_local_stream/mod_local_stream.c @@ -183,7 +183,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void fname = path_buf; fh.prebuf = source->prebuf; - fh.pre_buffer_datalen = 65536; + fh.pre_buffer_datalen = source->prebuf; if (switch_core_file_open(&fh, (char *) fname, @@ -206,16 +206,23 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void while (RUNNING) { switch_core_timer_next(&timer); olen = source->samples; + int is_open = switch_test_flag((&fh), SWITCH_FILE_OPEN); - if (switch_core_file_read(&fh, abuf, &olen) != SWITCH_STATUS_SUCCESS || !olen) { - switch_core_file_close(&fh); + if (is_open) { + if (switch_core_file_read(&fh, abuf, &olen) != SWITCH_STATUS_SUCCESS || !olen) { + switch_core_file_close(&fh); + } + + switch_buffer_write(audio_buffer, abuf, olen * 2); + } + + used = switch_buffer_inuse(audio_buffer); + + if (!used && !is_open) { break; } - switch_buffer_write(audio_buffer, abuf, olen * 2); - used = switch_buffer_inuse(audio_buffer); - - if (used >= source->prebuf || (source->total && used > source->samples * 2)) { + if (!is_open || used >= source->prebuf || (source->total && used > source->samples * 2)) { used = switch_buffer_read(audio_buffer, dist_buf, source->samples * 2); if (source->total) { @@ -285,6 +292,9 @@ static switch_status_t local_stream_file_open(switch_file_handle_t *handle, cons char *alt_path = NULL; switch_status_t status = SWITCH_STATUS_SUCCESS; + /* already buffering a step back, so always disable it */ + handle->pre_buffer_datalen = 0; + if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This format does not support writing!\n"); return SWITCH_STATUS_FALSE; diff --git a/support-d/.emacs b/support-d/.emacs index 2fa7cb24bb..fe2e33af2e 100644 --- a/support-d/.emacs +++ b/support-d/.emacs @@ -7,7 +7,7 @@ ;(setq cperl-hairy t) (global-unset-key "\C-h") (global-set-key "\C-h" 'delete-backward-char) -(load "/usr/share/emacs/site-lisp/rng-auto.el") +;(load "/usr/share/emacs/site-lisp/rng-auto.el") (require 'cc-mode) (defun my-build-tab-stop-list (width)