[Freeswitch-svn] [commit] r2775 - in freeswitch/trunk/src: . mod/timers/mod_softtimer

Freeswitch SVN anthm at freeswitch.org
Thu Sep 21 22:10:27 EDT 2006


Author: anthm
Date: Thu Sep 21 22:10:27 2006
New Revision: 2775

Modified:
   freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c
   freeswitch/trunk/src/switch_buffer.c
   freeswitch/trunk/src/switch_core.c
   freeswitch/trunk/src/switch_ivr.c

Log:
more optimizationification

Modified: freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c
==============================================================================
--- freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c	(original)
+++ freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c	Thu Sep 21 22:10:27 2006
@@ -155,8 +155,12 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
+/* I cant resist setting this to 10ms, we dont even run anything smaller than 20ms so this is already 
+   twice the granularity we need, we'll change it if we need anything smaller
+*/
 
-
+#define STEP_MS 10
+#define STEP_MIC 10000
 SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
 {
 	switch_time_t reference = switch_time_now();
@@ -169,13 +173,13 @@
 	globals.RUNNING = 1;
 
 	while(globals.RUNNING == 1) {
-		reference += 1000;
+		reference += STEP_MIC;
 
 		while (switch_time_now() < reference) {
-			switch_yield(1000);
+			switch_yield(STEP_MIC);
 		}
 
-		current_ms++;
+		current_ms += STEP_MS;
 
 		for (x = 0; x < MAX_ELEMENTS; x++) {
 			int i = x, index;

Modified: freeswitch/trunk/src/switch_buffer.c
==============================================================================
--- freeswitch/trunk/src/switch_buffer.c	(original)
+++ freeswitch/trunk/src/switch_buffer.c	Thu Sep 21 22:10:27 2006
@@ -42,6 +42,7 @@
 	switch_byte_t *data;
 	switch_byte_t *head;
 	switch_size_t used;
+	switch_size_t actually_used;
 	switch_size_t datalen;
 	switch_size_t max_len;
 	switch_size_t blocksize;
@@ -146,7 +147,7 @@
 	memmove(buffer->data, buffer->data + reading, reading);
 	buffer->head = buffer->data;
 	buffer->used -= reading;
-
+	buffer->actually_used = buffer->used;
 	return buffer->used;
 }
 
@@ -177,7 +178,7 @@
 
 SWITCH_DECLARE(switch_size_t) switch_buffer_write(switch_buffer_t *buffer, void *data, switch_size_t datalen)
 {
-	switch_size_t freespace;
+	switch_size_t freespace, actual_freespace;
 
 	assert(buffer != NULL);
 	assert(data != NULL);
@@ -187,13 +188,22 @@
 		return buffer->used;
 	}
 
+	actual_freespace = buffer->datalen - buffer->actually_used;
+
+	if (actual_freespace < datalen) {
+		memmove(buffer->data, buffer->head, buffer->used);
+		buffer->head = buffer->data;
+		buffer->actually_used = buffer->used;
+	}
+
 	freespace = buffer->datalen - buffer->used;
 
+	/*
 	if (buffer->data != buffer->head) {
 		memmove(buffer->data, buffer->head, buffer->used);
 		buffer->head = buffer->data;
 	}
-
+	*/
 	if (switch_test_flag(buffer, SWITCH_BUFFER_FLAG_DYNAMIC)) {
 		if (freespace < datalen) {
 			switch_size_t new_size, new_block_size;
@@ -218,8 +228,9 @@
 	if (freespace < datalen) {
 		return 0;
 	} else {
-		memcpy(buffer->data + buffer->used, data, datalen);
+		memcpy(buffer->head + buffer->used, data, datalen);
 		buffer->used += datalen;
+		buffer->actually_used += datalen;
 	}
 	//if (buffer->id == 4) printf("%u i %d = %d\n", buffer->id, (uint32_t)datalen, (uint32_t)buffer->used);
 

Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c	(original)
+++ freeswitch/trunk/src/switch_core.c	Thu Sep 21 22:10:27 2006
@@ -52,6 +52,8 @@
 #define SWITCH_EVENT_QUEUE_LEN 256
 #define SWITCH_SQL_QUEUE_LEN 2000
 
+#define SWITCH_BUFFER_BLOCK_FRAMES 25
+#define SWITCH_BUFFER_START_FRAMES 50
 
 struct switch_media_bug {
 	switch_buffer_t *raw_write_buffer;
@@ -253,10 +255,10 @@
 	bug->user_data = user_data;
 	bug->session = session;
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Attaching BUG to %s\n", switch_channel_get_name(session->channel));
-	bytes = session->read_codec->implementation->bytes_per_frame * 2;
-	switch_buffer_create_dynamic(&bug->raw_read_buffer, bytes, bytes, MAX_BUG_BUFFER);
-	bytes = session->write_codec->implementation->bytes_per_frame * 2;
-	switch_buffer_create_dynamic(&bug->raw_write_buffer, bytes, bytes, MAX_BUG_BUFFER);
+	bytes = session->read_codec->implementation->bytes_per_frame;
+	switch_buffer_create_dynamic(&bug->raw_read_buffer, bytes * SWITCH_BUFFER_BLOCK_FRAMES, bytes * SWITCH_BUFFER_START_FRAMES, MAX_BUG_BUFFER);
+	bytes = session->write_codec->implementation->bytes_per_frame;
+	switch_buffer_create_dynamic(&bug->raw_write_buffer, bytes * SWITCH_BUFFER_BLOCK_FRAMES, bytes * SWITCH_BUFFER_START_FRAMES, MAX_BUG_BUFFER);
 	switch_mutex_init(&bug->read_mutex, SWITCH_MUTEX_NESTED, session->pool);
 	switch_mutex_init(&bug->write_mutex, SWITCH_MUTEX_NESTED, session->pool);
 
@@ -1701,9 +1703,9 @@
 				perfect = TRUE;
 			} else {
 				if (!session->raw_read_buffer) {
-					switch_size_t bytes = session->read_codec->implementation->bytes_per_frame * 2;
+					switch_size_t bytes = session->read_codec->implementation->bytes_per_frame;
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Engaging Read Buffer at %u bytes\n", bytes);
-					switch_buffer_create_dynamic(&session->raw_read_buffer, bytes, bytes, 0);
+					switch_buffer_create_dynamic(&session->raw_read_buffer, bytes * SWITCH_BUFFER_BLOCK_FRAMES, bytes * SWITCH_BUFFER_START_FRAMES, 0);
 				}
 				if (!switch_buffer_write(session->raw_read_buffer, read_frame->data, read_frame->datalen)) {
 					status = SWITCH_STATUS_MEMERR;
@@ -1932,13 +1934,15 @@
 				perfect = TRUE;
 			} else {
 				if (!session->raw_write_buffer) {
-					switch_size_t bytes = session->write_codec->implementation->bytes_per_frame * 2;
+					switch_size_t bytes = session->write_codec->implementation->bytes_per_frame;
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
 										  "Engaging Write Buffer at %u bytes to accomodate %u->%u\n",
 										  bytes,
 										  write_frame->datalen, session->write_codec->implementation->bytes_per_frame);
-					if ((status =
-						 switch_buffer_create_dynamic(&session->raw_write_buffer, bytes, bytes, 0)) != SWITCH_STATUS_SUCCESS) {
+					if ((status =switch_buffer_create_dynamic(&session->raw_write_buffer,
+															  bytes * SWITCH_BUFFER_BLOCK_FRAMES,
+															  bytes * SWITCH_BUFFER_START_FRAMES,
+															  0)) != SWITCH_STATUS_SUCCESS) {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Write Buffer Failed!\n");
 						return status;
 					}

Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c	(original)
+++ freeswitch/trunk/src/switch_ivr.c	Thu Sep 21 22:10:27 2006
@@ -580,8 +580,10 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-#define FILE_STARTSAMPLES 512 * 128
-#define FILE_BLOCKSIZE 1024
+#define FILE_STARTSAMPLES 512 * 64
+#define FILE_BLOCKSIZE 1024 * 8
+#define FILE_BUFSIZE 1024 * 64
+
 SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *session, 
 												   switch_file_handle_t *fh,
 												   char *file,
@@ -679,7 +681,7 @@
 	interval = read_codec->implementation->microseconds_per_frame / 1000;
 
 	if (!fh->audio_buffer) {
-		switch_buffer_create_dynamic(&fh->audio_buffer, FILE_BLOCKSIZE, (FILE_STARTSAMPLES * sizeof(int16_t)) + FILE_BLOCKSIZE, 0);
+		switch_buffer_create_dynamic(&fh->audio_buffer, FILE_BLOCKSIZE, FILE_BUFSIZE, 0);
 	} 
 
 	codec_name = "L16";



More information about the Freeswitch-svn mailing list