[Freeswitch-branches] [commit] r11438 - in freeswitch/branches/1.0: src src/mod/formats/mod_local_stream support-d

FreeSWITCH SVN mikej at freeswitch.org
Thu Jan 22 15:50:35 PST 2009


Author: mikej
Date: Thu Jan 22 17:50:35 2009
New Revision: 11438

Log:
core: fix buffering issues (r:11152-11157,11162,11191)

Modified:
   freeswitch/branches/1.0/src/mod/formats/mod_local_stream/mod_local_stream.c
   freeswitch/branches/1.0/src/switch_core_file.c
   freeswitch/branches/1.0/support-d/.emacs

Modified: freeswitch/branches/1.0/src/mod/formats/mod_local_stream/mod_local_stream.c
==============================================================================
--- freeswitch/branches/1.0/src/mod/formats/mod_local_stream/mod_local_stream.c	(original)
+++ freeswitch/branches/1.0/src/mod/formats/mod_local_stream/mod_local_stream.c	Thu Jan 22 17:50:35 2009
@@ -32,7 +32,7 @@
  */
 #include <switch.h>
 /* for apr_pstrcat */
-#define DEFAULT_PREBUFFER_SIZE 1024 * 32
+#define DEFAULT_PREBUFFER_SIZE 1024 * 64
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_local_stream_load);
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_local_stream_shutdown);
@@ -183,7 +183,7 @@
 
 			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,
@@ -204,18 +204,26 @@
 			}
 
 			while (RUNNING) {
+				int is_open;
 				switch_core_timer_next(&timer);
 				olen = source->samples;
+				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);
-					break;
+				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);
 				}
 
-				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 (!used && !is_open) {
+					break;
+				}
+
+				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 +293,9 @@
 	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;

Modified: freeswitch/branches/1.0/src/switch_core_file.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_core_file.c	(original)
+++ freeswitch/branches/1.0/src/switch_core_file.c	Thu Jan 22 17:50:35 2009
@@ -158,8 +158,9 @@
 		int asis = switch_test_flag(fh, SWITCH_FILE_NATIVE);
 
 		if (!switch_test_flag(fh, SWITCH_FILE_BUFFER_DONE)) {
-			if (!switch_buffer_inuse(fh->pre_buffer)) {
-				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 ((status = fh->file_interface->file_read(fh, fh->pre_buffer_data, &rlen)) != SWITCH_STATUS_SUCCESS || !rlen) {
 					switch_set_flag(fh, SWITCH_FILE_BUFFER_DONE);
 				} else {
@@ -209,7 +210,7 @@
 				switch_assert(fh->buffer);
 			}
 			if (!fh->dbuf) {
-				fh->dbuflen = want * 2;
+				fh->dbuflen = want * 8;
 				fh->dbuf = switch_core_alloc(fh->memory_pool, fh->dbuflen);
 			}
 			switch_assert(fh->resampler->to_len <= fh->dbuflen);

Modified: freeswitch/branches/1.0/support-d/.emacs
==============================================================================
--- freeswitch/branches/1.0/support-d/.emacs	(original)
+++ freeswitch/branches/1.0/support-d/.emacs	Thu Jan 22 17:50:35 2009
@@ -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)



More information about the Freeswitch-branches mailing list