[Freeswitch-svn] [commit] r8706 - in freeswitch/trunk/src: . mod/formats/mod_local_stream

Freeswitch SVN anthm at freeswitch.org
Wed May 28 11:14:18 EDT 2008


Author: anthm
Date: Wed May 28 11:14:18 2008
New Revision: 8706

Modified:
   freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c
   freeswitch/trunk/src/switch_core_file.c
   freeswitch/trunk/src/switch_ivr_play_say.c

Log:
make local_stream more solid

Modified: freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c
==============================================================================
--- freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c	(original)
+++ freeswitch/trunk/src/mod/formats/mod_local_stream/mod_local_stream.c	Wed May 28 11:14:18 2008
@@ -75,6 +75,8 @@
 	switch_mutex_t *mutex;
 	switch_memory_pool_t *pool;
 	int shuffle;
+	switch_thread_rwlock_t *rwlock;
+	int ready;
 };
 
 typedef struct local_stream_source local_stream_source_t;
@@ -115,11 +117,18 @@
 		skip = do_rand();
 	}
 
-	switch_core_hash_insert(globals.source_hash, source->name, source);
+	switch_thread_rwlock_create(&source->rwlock, source->pool);
+	
+	if (RUNNING) {
+		switch_mutex_lock(globals.mutex);
+		switch_core_hash_insert(globals.source_hash, source->name, source);
+		switch_mutex_unlock(globals.mutex);
+		source->ready = 1;
+	}
 
 	while (RUNNING) {
 		const char *fname;
-
+		
 		if (switch_dir_open(&source->dir_handle, source->location, source->pool) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Can't open directory: %s\n", source->location);
 			goto done;
@@ -231,8 +240,14 @@
 	}
 
   done:
+	source->ready = 0;
+	switch_mutex_lock(globals.mutex);
 	switch_core_hash_delete(globals.source_hash, source->name);
+	switch_mutex_unlock(globals.mutex);
 
+	switch_thread_rwlock_wrlock(source->rwlock);
+	switch_thread_rwlock_unlock(source->rwlock);
+	
 	switch_buffer_destroy(&audio_buffer);
 
 	if (fd > -1) {
@@ -264,6 +279,11 @@
 	} else {
 		source = switch_core_hash_find(globals.source_hash, path);
 	}
+	if (source) {
+		if (switch_thread_rwlock_tryrdlock(source->rwlock) != SWITCH_STATUS_SUCCESS) {
+			source = NULL;
+		}
+	}
 	switch_mutex_unlock(globals.mutex);
 
 	if (!source) {
@@ -330,7 +350,8 @@
 	context->source->total--;
 	switch_mutex_unlock(context->source->mutex);
 	switch_buffer_destroy(&context->audio_buffer);
-
+	switch_thread_rwlock_unlock(context->source->rwlock);
+	
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -340,6 +361,11 @@
 	switch_size_t bytes = 0;
 	size_t need = *len * 2;
 
+	if (!context->source->ready) {
+		*len = 0;
+		return SWITCH_STATUS_FALSE;
+	}
+
 	switch_mutex_lock(context->audio_mutex);
 	if ((bytes = switch_buffer_read(context->audio_buffer, data, need))) {
 		*len = bytes / 2;

Modified: freeswitch/trunk/src/switch_core_file.c
==============================================================================
--- freeswitch/trunk/src/switch_core_file.c	(original)
+++ freeswitch/trunk/src/switch_core_file.c	Wed May 28 11:14:18 2008
@@ -133,6 +133,7 @@
 	}
 
 	if ((status = fh->file_interface->file_read(fh, data, len)) != SWITCH_STATUS_SUCCESS) {
+		*len = 0;
 		goto done;
 	}
 

Modified: freeswitch/trunk/src/switch_ivr_play_say.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_play_say.c	(original)
+++ freeswitch/trunk/src/switch_ivr_play_say.c	Wed May 28 11:14:18 2008
@@ -1021,7 +1021,9 @@
 			if (!asis) {
 				olen /= 2;
 			}
-			switch_core_file_read(fh, abuf, &olen);
+			if (switch_core_file_read(fh, abuf, &olen) != SWITCH_STATUS_SUCCESS) {
+				break;
+			}
 			switch_buffer_write(fh->audio_buffer, abuf, asis ? olen : olen * 2);
 			olen = switch_buffer_read(fh->audio_buffer, abuf, framelen);
 			if (!asis) {



More information about the Freeswitch-svn mailing list