[Freeswitch-svn] [commit] r11426 - in freeswitch/branches/1.0/src: . include mod/applications/mod_conference mod/applications/mod_rss mod/endpoints/mod_loopback mod/endpoints/mod_sofia mod/event_handlers/mod_erlang_event mod/event_handlers/mod_event_socket mod/formats/mod_local_stream

FreeSWITCH SVN mikej at freeswitch.org
Thu Jan 22 15:01:57 PST 2009


Author: mikej
Date: Thu Jan 22 17:01:56 2009
New Revision: 11426

Log:
core: fix codec and media handling issues (r:11104) 

Modified:
   freeswitch/branches/1.0/src/include/switch_core.h
   freeswitch/branches/1.0/src/include/switch_module_interfaces.h
   freeswitch/branches/1.0/src/include/switch_types.h
   freeswitch/branches/1.0/src/mod/applications/mod_conference/mod_conference.c
   freeswitch/branches/1.0/src/mod/applications/mod_rss/mod_rss.c
   freeswitch/branches/1.0/src/mod/endpoints/mod_loopback/mod_loopback.c
   freeswitch/branches/1.0/src/mod/endpoints/mod_sofia/sofia_glue.c
   freeswitch/branches/1.0/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
   freeswitch/branches/1.0/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
   freeswitch/branches/1.0/src/mod/formats/mod_local_stream/mod_local_stream.c
   freeswitch/branches/1.0/src/switch_core.c
   freeswitch/branches/1.0/src/switch_core_file.c
   freeswitch/branches/1.0/src/switch_core_io.c
   freeswitch/branches/1.0/src/switch_core_session.c
   freeswitch/branches/1.0/src/switch_core_state_machine.c
   freeswitch/branches/1.0/src/switch_ivr.c
   freeswitch/branches/1.0/src/switch_ivr_async.c
   freeswitch/branches/1.0/src/switch_ivr_bridge.c
   freeswitch/branches/1.0/src/switch_ivr_originate.c
   freeswitch/branches/1.0/src/switch_ivr_play_say.c

Modified: freeswitch/branches/1.0/src/include/switch_core.h
==============================================================================
--- freeswitch/branches/1.0/src/include/switch_core.h	(original)
+++ freeswitch/branches/1.0/src/include/switch_core.h	Thu Jan 22 17:01:56 2009
@@ -330,7 +330,7 @@
   \return success if it is safe to read from the session
 */
 #ifdef SWITCH_DEBUG_RWLOCKS
-#define switch_core_session_read_lock(session) switch_core_session_perform_read_lock_hangup(session, __FILE__, __SWITCH_FUNC__, __LINE__)
+#define switch_core_session_read_lock_hangup(session) switch_core_session_perform_read_lock_hangup(session, __FILE__, __SWITCH_FUNC__, __LINE__)
 #else
 SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock_hangup(_In_ switch_core_session_t *session);
 #endif
@@ -901,7 +901,7 @@
   \param session the session to reset
   \param flush_dtmf flush all queued dtmf events too
 */
-SWITCH_DECLARE(void) switch_core_session_reset(_In_ switch_core_session_t *session, switch_bool_t flush_dtmf);
+SWITCH_DECLARE(void) switch_core_session_reset(_In_ switch_core_session_t *session, switch_bool_t flush_dtmf, switch_bool_t reset_read_codec);
 
 /*! 
   \brief Write a frame to a session

Modified: freeswitch/branches/1.0/src/include/switch_module_interfaces.h
==============================================================================
--- freeswitch/branches/1.0/src/include/switch_module_interfaces.h	(original)
+++ freeswitch/branches/1.0/src/include/switch_module_interfaces.h	Thu Jan 22 17:01:56 2009
@@ -320,6 +320,9 @@
 	switch_buffer_t *buffer;
 	switch_byte_t *dbuf;
 	switch_size_t dbuflen;
+	switch_buffer_t *pre_buffer;
+	unsigned char *pre_buffer_data;
+	switch_size_t pre_buffer_datalen;
 	const char *file;
 	const char *func;
 	int line;

Modified: freeswitch/branches/1.0/src/include/switch_types.h
==============================================================================
--- freeswitch/branches/1.0/src/include/switch_types.h	(original)
+++ freeswitch/branches/1.0/src/include/switch_types.h	Thu Jan 22 17:01:56 2009
@@ -166,7 +166,9 @@
 #define SWITCH_SPEECH_KEY "speech"
 #define SWITCH_UUID_BRIDGE "uuid_bridge"
 #define SWITCH_BITS_PER_BYTE 8
-	typedef uint8_t switch_byte_t;
+#define SWITCH_DEFAULT_FILE_BUFFER_LEN 65536
+
+typedef uint8_t switch_byte_t;
 
 typedef struct {
 	char digit;
@@ -1061,7 +1063,9 @@
 	SWITCH_FILE_NATIVE = (1 << 9),
 	SWITCH_FILE_SEEK = (1 << 10),
 	SWITCH_FILE_OPEN = (1 << 11),
-	SWITCH_FILE_CALLBACK = (1 << 12)
+	SWITCH_FILE_CALLBACK = (1 << 12),
+	SWITCH_FILE_DONE = (1 << 13),
+	SWITCH_FILE_BUFFER_DONE = (1 << 14)
 } switch_file_flag_enum_t;
 typedef uint32_t switch_file_flag_t;
 

Modified: freeswitch/branches/1.0/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/branches/1.0/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/branches/1.0/src/mod/applications/mod_conference/mod_conference.c	Thu Jan 22 17:01:56 2009
@@ -1,4 +1,4 @@
-/* 
+/*
  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  * Copyright (C) 2005/2006, Anthony Minessale II <anthmct at yahoo.com>
  *
@@ -139,7 +139,8 @@
 	MFLAG_FLUSH_BUFFER = (1 << 8),
 	MFLAG_ENDCONF = (1 << 9),
 	MFLAG_HAS_AUDIO = (1 << 10),
-	MFLAG_TALKING = (1 << 11)
+	MFLAG_TALKING = (1 << 11),
+	MFLAG_RESTART = (1 << 12)
 } member_flag_t;
 
 typedef enum {
@@ -337,6 +338,7 @@
 } api_command_t;
 
 /* Function Prototypes */
+static int setup_media(conference_member_t *member, conference_obj_t *conference);
 static uint32_t next_member_id(void);
 static conference_relationship_t *member_get_relationship(conference_member_t *member, conference_member_t *other_member);
 static conference_member_t *conference_member_get(conference_obj_t *conference, uint32_t id);
@@ -1758,18 +1760,43 @@
 /* NB. this starts the input thread after some initial setup for the call leg */
 static void conference_loop_output(conference_member_t *member)
 {
-	switch_channel_t *channel = switch_core_session_get_channel(member->session);
+	switch_channel_t *channel;
 	switch_frame_t write_frame = { 0 };
-	uint8_t *data;
+	uint8_t *data = NULL;
 	switch_timer_t timer = { 0 };
-	switch_codec_t *read_codec = switch_core_session_get_read_codec(member->session);
-	uint32_t interval = read_codec->implementation->microseconds_per_packet / 1000;
-	uint32_t samples = switch_samples_per_packet(member->conference->rate, interval);
-	uint32_t csamples = samples;
-	uint32_t tsamples = member->orig_read_codec->implementation->samples_per_packet;
-	uint32_t flush_len = 0;
-	uint32_t low_count = 0, bytes = samples * 2;
-	call_list_t *call_list = NULL, *cp = NULL;
+	switch_codec_t *read_codec;
+	uint32_t interval;
+	uint32_t samples;
+	uint32_t csamples;
+	uint32_t tsamples;
+	uint32_t flush_len;
+	uint32_t low_count, bytes;
+	call_list_t *call_list, *cp;
+	int restarting = -1;
+
+ top:
+
+	restarting++;
+	
+	if (switch_test_flag(member, MFLAG_RESTART)) {
+		switch_clear_flag(member, MFLAG_RESTART);
+		switch_set_flag_locked(member, MFLAG_FLUSH_BUFFER);
+		switch_core_timer_destroy(&timer);
+	}
+
+	channel = switch_core_session_get_channel(member->session);
+	read_codec = switch_core_session_get_read_codec(member->session);
+	interval = read_codec->implementation->microseconds_per_packet / 1000;
+	samples = switch_samples_per_packet(member->conference->rate, interval);
+	csamples = samples;
+	tsamples = member->orig_read_codec->implementation->samples_per_packet;
+	flush_len = 0;
+	low_count = 0;
+	bytes = samples * 2;
+	call_list = NULL;
+	cp = NULL;
+
+
 
 	switch_assert(member->conference != NULL);
 
@@ -1783,62 +1810,72 @@
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setup timer %s success interval: %u  samples: %u\n",
 					  member->conference->timer_name, interval, tsamples);
 
-	write_frame.data = data = switch_core_session_alloc(member->session, SWITCH_RECOMMENDED_BUFFER_SIZE);
-	write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
+	if (!restarting) {
+		write_frame.data = data = switch_core_session_alloc(member->session, SWITCH_RECOMMENDED_BUFFER_SIZE);
+		write_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
+	}
+
 	write_frame.codec = &member->write_codec;
 
 	if (!switch_test_flag(member->conference, CFLAG_ANSWERED)) {
 		switch_channel_answer(channel);
 	}
 
-	/* Start the input thread */
-	launch_conference_loop_input(member, switch_core_session_get_pool(member->session));
-
-	/* build a digit stream object */
-	if (member->conference->dtmf_parser != NULL
-		&& switch_ivr_digit_stream_new(member->conference->dtmf_parser, &member->digit_stream) != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Danger Will Robinson, there is no digit parser stream object\n");
-	}
-
-	if ((call_list = switch_channel_get_private(channel, "_conference_autocall_list_"))) {
-		const char *cid_name = switch_channel_get_variable(channel, "conference_auto_outcall_caller_id_name");
-		const char *cid_num = switch_channel_get_variable(channel, "conference_auto_outcall_caller_id_number");
-		const char *toval = switch_channel_get_variable(channel, "conference_auto_outcall_timeout");
-		const char *flags = switch_channel_get_variable(channel, "conference_auto_outcall_flags");
-		const char *ann = switch_channel_get_variable(channel, "conference_auto_outcall_announce");
-		const char *prefix = switch_channel_get_variable(channel, "conference_auto_outcall_prefix");
-		int to = 60;
+	if (!restarting) {
+		/* Start the input thread */
+		launch_conference_loop_input(member, switch_core_session_get_pool(member->session));
 		
-		if (ann) {
-			member->conference->special_announce = switch_core_strdup(member->conference->pool, ann);
+		/* build a digit stream object */
+		if (member->conference->dtmf_parser != NULL
+			&& switch_ivr_digit_stream_new(member->conference->dtmf_parser, &member->digit_stream) != SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Danger Will Robinson, there is no digit parser stream object\n");
 		}
 
-		switch_channel_set_private(channel, "_conference_autocall_list_", NULL);
+		if ((call_list = switch_channel_get_private(channel, "_conference_autocall_list_"))) {
+			const char *cid_name = switch_channel_get_variable(channel, "conference_auto_outcall_caller_id_name");
+			const char *cid_num = switch_channel_get_variable(channel, "conference_auto_outcall_caller_id_number");
+			const char *toval = switch_channel_get_variable(channel, "conference_auto_outcall_timeout");
+			const char *flags = switch_channel_get_variable(channel, "conference_auto_outcall_flags");
+			const char *ann = switch_channel_get_variable(channel, "conference_auto_outcall_announce");
+			const char *prefix = switch_channel_get_variable(channel, "conference_auto_outcall_prefix");
+			int to = 60;
+		
+			if (ann) {
+				member->conference->special_announce = switch_core_strdup(member->conference->pool, ann);
+			}
+
+			switch_channel_set_private(channel, "_conference_autocall_list_", NULL);
 
-		if (toval) {
-			to = atoi(toval);
-			if (to < 10 || to > 500) {
-				to = 60;
+			if (toval) {
+				to = atoi(toval);
+				if (to < 10 || to > 500) {
+					to = 60;
+				}
 			}
-		}
 
-		for (cp = call_list; cp; cp = cp->next) {
-			int argc;
-			char *argv[512] = { 0 };
-			char *cpstr = strdup(cp->string);
-			int x = 0;
+			for (cp = call_list; cp; cp = cp->next) {
+				int argc;
+				char *argv[512] = { 0 };
+				char *cpstr = strdup(cp->string);
+				int x = 0;
 
-			switch_assert(cpstr);
-			argc = switch_separate_string(cpstr, ',', argv, (sizeof(argv) / sizeof(argv[0])));
-			for (x = 0; x < argc; x++) {
-				char *dial_str = switch_mprintf("%s%s", switch_str_nil(prefix), argv[x]);
-				switch_assert(dial_str);
-				conference_outcall_bg(member->conference, NULL, NULL, dial_str, to, switch_str_nil(flags), cid_name, cid_num);
-				switch_safe_free(dial_str);
+				switch_assert(cpstr);
+				argc = switch_separate_string(cpstr, ',', argv, (sizeof(argv) / sizeof(argv[0])));
+				for (x = 0; x < argc; x++) {
+					char *dial_str = switch_mprintf("%s%s", switch_str_nil(prefix), argv[x]);
+					switch_assert(dial_str);
+					conference_outcall_bg(member->conference, NULL, NULL, dial_str, to, switch_str_nil(flags), cid_name, cid_num);
+					switch_safe_free(dial_str);
+				}
+				switch_safe_free(cpstr);
 			}
-			switch_safe_free(cpstr);
 		}
 	}
+
+	if (restarting) {
+		switch_channel_clear_flag(channel, CF_SERVICE);
+	}
+
 	/* Fair WARNING, If you expect the caller to hear anything or for digit handling to be processed,      */
 	/* you better not block this thread loop for more than the duration of member->conference->timer_name!  */
 	while (switch_test_flag(member, MFLAG_RUNNING) && switch_test_flag(member, MFLAG_ITHREAD)
@@ -1852,6 +1889,10 @@
 		switch_size_t file_sample_len = csamples;
 		switch_size_t file_data_len = file_sample_len * 2;
 
+		if (switch_test_flag(member, MFLAG_RESTART)) {
+			goto top;
+		}
+
 		switch_mutex_lock(member->flag_mutex);
 
 		if (switch_core_session_dequeue_event(member->session, &event) == SWITCH_STATUS_SUCCESS) {
@@ -2145,6 +2186,8 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Joining Conference\n");
 		goto end;
 	}
+	
+	fh.pre_buffer_datalen = SWITCH_DEFAULT_FILE_BUFFER_LEN;
 
 	if (switch_core_file_open(&fh,
 							  rec->path, (uint8_t) 1, conference->rate, SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT,
@@ -2371,6 +2414,7 @@
 	fnode->leadin = leadin;
 
 	/* Open the file */
+	fnode->fh.pre_buffer_datalen = SWITCH_DEFAULT_FILE_BUFFER_LEN;
 	if (switch_core_file_open(&fnode->fh, file, (uint8_t) 1, conference->rate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, pool) !=
 		SWITCH_STATUS_SUCCESS) {
 		switch_core_destroy_memory_pool(&pool);
@@ -2465,6 +2509,7 @@
 	fnode->type = NODE_TYPE_FILE;
 	fnode->leadin = leadin;
 	/* Open the file */
+	fnode->fh.pre_buffer_datalen = SWITCH_DEFAULT_FILE_BUFFER_LEN;
 	if (switch_core_file_open(&fnode->fh,
 							  file, (uint8_t) 1, member->conference->rate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
 							  pool) != SWITCH_STATUS_SUCCESS) {
@@ -3631,9 +3676,21 @@
 			switch_mutex_lock(member->flag_mutex);
 			conference_del_member(conference, member);
 			conference_add_member(new_conference, member);
+
+			if (conference->rate != new_conference->rate) {
+				if(setup_media(member, new_conference)) {
+					switch_clear_flag_locked(member, MFLAG_RUNNING);
+				} else {
+					switch_channel_set_flag(channel, CF_SERVICE);
+					switch_set_flag(member, MFLAG_RESTART);
+				}
+			}
+
 			switch_mutex_unlock(new_conference->mutex);
 			switch_mutex_unlock(member->flag_mutex);
-			stream->write_function(stream, "OK Members sent to conference %s.\n", argv[2]);
+
+			
+			stream->write_function(stream, "OK Member '%d' sent to conference %s.\n", member->id, argv[2]);
 
 			/* tell them what happened */
 			if (test_eflag(conference, EFLAG_TRANSFER) &&
@@ -4349,6 +4406,111 @@
 	switch_channel_set_private(channel, "_conference_autocall_list_", call_list);
 }
 
+
+static int setup_media(conference_member_t *member, conference_obj_t *conference)
+{
+	switch_codec_t *read_codec;
+
+	
+	switch_core_session_reset(member->session, SWITCH_TRUE, SWITCH_FALSE);
+
+	if (member->read_codec.implementation) {
+		switch_core_codec_destroy(&member->read_codec);
+	}
+
+	if (member->read_resampler) {
+		switch_resample_destroy(&member->read_resampler);
+	}
+
+	read_codec = switch_core_session_get_read_codec(member->session);
+	member->orig_read_codec = read_codec;
+	member->native_rate = read_codec->implementation->samples_per_second;
+
+	/* Setup a Signed Linear codec for reading audio. */
+	if (switch_core_codec_init(&member->read_codec,
+							   "L16",
+							   NULL, read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_packet / 1000,
+							   1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, member->pool) == SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+						  "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
+						  read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_packet / 1000);
+
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
+						  read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_packet / 1000);
+
+		goto done;
+	}
+
+	if (!member->frame_size) {
+		member->frame_size = SWITCH_RECOMMENDED_BUFFER_SIZE;
+		member->frame = switch_core_alloc(member->pool, member->frame_size);
+		member->mux_frame = switch_core_alloc(member->pool, member->frame_size);
+	}
+
+	if (read_codec->implementation->actual_samples_per_second != conference->rate) {
+		if (switch_resample_create(&member->read_resampler,
+								   read_codec->implementation->actual_samples_per_second,
+								   member->frame_size, conference->rate, member->frame_size, member->pool) != SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
+			goto done;
+		}
+
+
+		member->resample_out = switch_core_alloc(member->pool, member->frame_size);
+		member->resample_out_len = member->frame_size;
+
+		/* Setup an audio buffer for the resampled audio */
+		if (switch_buffer_create_dynamic(&member->resample_buffer, CONF_DBLOCK_SIZE, CONF_DBUFFER_SIZE, CONF_DBUFFER_MAX)
+			!= SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error Creating Audio Buffer!\n");
+			goto done;
+		}
+	}
+
+
+	/* Setup a Signed Linear codec for writing audio. */
+	if (switch_core_codec_init(&member->write_codec,
+							   "L16",
+							   NULL,
+							   conference->rate,
+							   read_codec->implementation->microseconds_per_packet / 1000,
+							   1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, member->pool) == SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+						  "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
+						  conference->rate, read_codec->implementation->microseconds_per_packet / 1000);
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
+						  conference->rate, read_codec->implementation->microseconds_per_packet / 1000);
+		goto codec_done2;
+	}
+
+	/* Setup an audio buffer for the incoming audio */
+	if (switch_buffer_create_dynamic(&member->audio_buffer, CONF_DBLOCK_SIZE, CONF_DBUFFER_SIZE, CONF_DBUFFER_MAX) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error Creating Audio Buffer!\n");
+		goto codec_done1;
+	}
+
+	/* Setup an audio buffer for the outgoing audio */
+	if (switch_buffer_create_dynamic(&member->mux_buffer, CONF_DBLOCK_SIZE, CONF_DBUFFER_SIZE, CONF_DBUFFER_MAX) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error Creating Audio Buffer!\n");
+		goto codec_done1;
+	}
+
+	return 0;
+
+ codec_done1:
+	switch_core_codec_destroy(&member->read_codec);
+ codec_done2:
+	switch_core_codec_destroy(&member->write_codec);
+ done:
+
+	return -1;
+	
+
+}
+
+
 /* Application interface function that is called from the dialplan to join the channel to a conference */
 SWITCH_STANDARD_APP(conference_function)
 {
@@ -4632,84 +4794,16 @@
 			switch_set_flag(conference, CFLAG_ANSWERED);
 	}
 
-	member.orig_read_codec = read_codec;
-	member.native_rate = read_codec->implementation->samples_per_second;
+	member.session = session;
 	member.pool = switch_core_session_get_pool(session);
 
-	/* Setup a Signed Linear codec for reading audio. */
-	if (switch_core_codec_init(&member.read_codec,
-							   "L16",
-							   NULL, read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_packet / 1000,
-							   1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, member.pool) == SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-						  "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
-						  read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_packet / 1000);
-
-	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
-						  read_codec->implementation->actual_samples_per_second, read_codec->implementation->microseconds_per_packet / 1000);
-
+	if (setup_media(&member, conference)) {
 		flags = 0;
 		goto done;
 	}
 
-	member.frame_size = SWITCH_RECOMMENDED_BUFFER_SIZE;
-	member.frame = switch_core_alloc(member.pool, member.frame_size);
-	member.mux_frame = switch_core_alloc(member.pool, member.frame_size);
-
-	if (read_codec->implementation->actual_samples_per_second != conference->rate) {
-		if (switch_resample_create(&member.read_resampler,
-								   read_codec->implementation->actual_samples_per_second,
-								   member.frame_size, conference->rate, member.frame_size, member.pool) != SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
-			goto done;
-		}
-
-
-		member.resample_out = switch_core_alloc(member.pool, member.frame_size);
-		member.resample_out_len = member.frame_size;
-
-		/* Setup an audio buffer for the resampled audio */
-		if (switch_buffer_create_dynamic(&member.resample_buffer, CONF_DBLOCK_SIZE, CONF_DBUFFER_SIZE, CONF_DBUFFER_MAX)
-			!= SWITCH_STATUS_SUCCESS) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error Creating Audio Buffer!\n");
-			goto done;
-		}
-	}
-
-
-	/* Setup a Signed Linear codec for writing audio. */
-	if (switch_core_codec_init(&member.write_codec,
-							   "L16",
-							   NULL,
-							   conference->rate,
-							   read_codec->implementation->microseconds_per_packet / 1000,
-							   1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, member.pool) == SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-						  "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
-						  conference->rate, read_codec->implementation->microseconds_per_packet / 1000);
-	} else {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
-						  conference->rate, read_codec->implementation->microseconds_per_packet / 1000);
-		flags = 0;
-		goto codec_done2;
-	}
-
-	/* Setup an audio buffer for the incoming audio */
-	if (switch_buffer_create_dynamic(&member.audio_buffer, CONF_DBLOCK_SIZE, CONF_DBUFFER_SIZE, CONF_DBUFFER_MAX) != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error Creating Audio Buffer!\n");
-		goto codec_done1;
-	}
-
-	/* Setup an audio buffer for the outgoing audio */
-	if (switch_buffer_create_dynamic(&member.mux_buffer, CONF_DBLOCK_SIZE, CONF_DBUFFER_SIZE, CONF_DBUFFER_MAX) != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error Creating Audio Buffer!\n");
-		goto codec_done1;
-	}
-
 	/* Prepare MUTEXS */
 	member.id = next_member_id();
-	member.session = session;
 	switch_mutex_init(&member.flag_mutex, SWITCH_MUTEX_NESTED, member.pool);
 	switch_mutex_init(&member.audio_in_mutex, SWITCH_MUTEX_NESTED, member.pool);
 	switch_mutex_init(&member.audio_out_mutex, SWITCH_MUTEX_NESTED, member.pool);
@@ -4724,7 +4818,8 @@
 
 	/* Add the caller to the conference */
 	if (conference_add_member(conference, &member) != SWITCH_STATUS_SUCCESS) {
-		goto codec_done1;
+		switch_core_codec_destroy(&member.read_codec);
+		goto done;
 	}
 
 	msg.from = __FILE__;
@@ -4747,12 +4842,14 @@
 	/* Put the original codec back */
 	switch_core_session_set_read_codec(member.session, NULL);
 
-	/* Clean Up.  codec_done(X): is for error situations after the codecs were setup and done: is for situations before */
-  codec_done1:
-	switch_core_codec_destroy(&member.read_codec);
-  codec_done2:
-	switch_core_codec_destroy(&member.write_codec);
+	/* Clean Up. */
+
   done:
+
+	if (member.read_resampler) {
+		switch_resample_destroy(&member.read_resampler);
+	}
+
 	switch_event_destroy(&params);
 	switch_buffer_destroy(&member.resample_buffer);
 	switch_buffer_destroy(&member.audio_buffer);
@@ -4796,7 +4893,7 @@
 		}
 	}
 
-	switch_core_session_reset(session, SWITCH_TRUE);
+	switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 
 	/* release the readlock */
 	if (rl) {

Modified: freeswitch/branches/1.0/src/mod/applications/mod_rss/mod_rss.c
==============================================================================
--- freeswitch/branches/1.0/src/mod/applications/mod_rss/mod_rss.c	(original)
+++ freeswitch/branches/1.0/src/mod/applications/mod_rss/mod_rss.c	Thu Jan 22 17:01:56 2009
@@ -619,7 +619,7 @@
 	}
 
 	switch_xml_free(xml);
-	switch_core_session_reset(session, SWITCH_TRUE);
+	switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 }
 
 

Modified: freeswitch/branches/1.0/src/mod/endpoints/mod_loopback/mod_loopback.c
==============================================================================
--- freeswitch/branches/1.0/src/mod/endpoints/mod_loopback/mod_loopback.c	(original)
+++ freeswitch/branches/1.0/src/mod/endpoints/mod_loopback/mod_loopback.c	Thu Jan 22 17:01:56 2009
@@ -264,7 +264,10 @@
 	}
 	
 	if (tech_pvt->other_session) {
-		switch_core_session_read_lock(tech_pvt->other_session);
+		if (switch_core_session_read_lock(tech_pvt->other_session) != SWITCH_STATUS_SUCCESS) {
+			switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+			goto end;
+		}
 	} else {
 		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 		goto end;

Modified: freeswitch/branches/1.0/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/branches/1.0/src/mod/endpoints/mod_sofia/sofia_glue.c	(original)
+++ freeswitch/branches/1.0/src/mod/endpoints/mod_sofia/sofia_glue.c	Thu Jan 22 17:01:56 2009
@@ -1623,7 +1623,7 @@
 			resetting = 1;
 			switch_core_codec_destroy(&tech_pvt->read_codec);
 			switch_core_codec_destroy(&tech_pvt->write_codec);
-			switch_core_session_reset(tech_pvt->session, SWITCH_TRUE);
+			switch_core_session_reset(tech_pvt->session, SWITCH_TRUE, SWITCH_TRUE);
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Already using %s\n", tech_pvt->read_codec.implementation->iananame);
 			switch_goto_status(SWITCH_STATUS_SUCCESS, end);

Modified: freeswitch/branches/1.0/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
==============================================================================
--- freeswitch/branches/1.0/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c	(original)
+++ freeswitch/branches/1.0/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c	Thu Jan 22 17:01:56 2009
@@ -1202,7 +1202,9 @@
 
 	if ((session = listener->session)) {
 		channel = switch_core_session_get_channel(session);
-		switch_core_session_read_lock(session);
+		if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
+			goto done;
+		}
 	}
 
 	if (switch_strlen_zero(listener->remote_ip)) {

Modified: freeswitch/branches/1.0/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/branches/1.0/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	(original)
+++ freeswitch/branches/1.0/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	Thu Jan 22 17:01:56 2009
@@ -1770,7 +1770,9 @@
 	
 	if ((session = listener->session)) {
 		channel = switch_core_session_get_channel(session);
-		switch_core_session_read_lock(session);
+		if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
+			goto done;
+		}
 	}
 
 	if (prefs.acl_count && listener->sa && !switch_strlen_zero(listener->remote_ip)) {

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:01:56 2009
@@ -183,6 +183,7 @@
 
 			fname = path_buf;
 			fh.prebuf = source->prebuf;
+			fh.pre_buffer_datalen = 65536;
 
 			if (switch_core_file_open(&fh,
 									  (char *) fname,

Modified: freeswitch/branches/1.0/src/switch_core.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_core.c	(original)
+++ freeswitch/branches/1.0/src/switch_core.c	Thu Jan 22 17:01:56 2009
@@ -277,7 +277,10 @@
 	switch_assert(thread != NULL);
 	switch_assert(session != NULL);
 
-	switch_core_session_read_lock(session);
+	if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
+		return NULL;
+	}
+
 	channel = switch_core_session_get_channel(session);
 
 	switch_channel_set_flag(channel, CF_SERVICE);

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:01:56 2009
@@ -117,6 +117,12 @@
 		}
 	}
 
+	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);
+		fh->pre_buffer_data = switch_core_alloc(fh->memory_pool, fh->pre_buffer_datalen);
+	}
+
 	switch_set_flag(fh, SWITCH_FILE_OPEN);
 
 	return status;
@@ -124,26 +130,61 @@
 
 SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh, void *data, switch_size_t *len)
 {
-	switch_status_t status;
+	switch_status_t status = SWITCH_STATUS_FALSE;
 	switch_size_t want, got, orig_len = *len;
 
 	switch_assert(fh != NULL);
 	switch_assert(fh->file_interface != NULL);
 
+ top:
+
 	if (fh->buffer && switch_buffer_inuse(fh->buffer) >= *len * 2) {
 		*len = switch_buffer_read(fh->buffer, data, orig_len * 2) / 2;
 		return SWITCH_STATUS_SUCCESS;
 	}
-
+	
+	if (switch_test_flag(fh, SWITCH_FILE_DONE)) {
+		switch_clear_flag(fh, SWITCH_FILE_DONE);
+		*len = 0;
+		return SWITCH_STATUS_FALSE;
+	}
+	
 	want = *len;
 
  more:
 	
-	if ((status = fh->file_interface->file_read(fh, data, len)) != SWITCH_STATUS_SUCCESS || !*len) {
-		*len = 0;
-		goto done;
+	if (fh->pre_buffer) {
+		switch_size_t rlen;
+		if (!switch_test_flag(fh, SWITCH_FILE_BUFFER_DONE)) {
+			if (!switch_buffer_inuse(fh->pre_buffer)) {
+				rlen = fh->pre_buffer_datalen / 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 {
+					switch_buffer_write(fh->pre_buffer, fh->pre_buffer_data, rlen * 2);
+				}
+			}
+		}
+
+		rlen = switch_buffer_read(fh->pre_buffer, data, *len * 2);
+		*len = rlen / 2;
+		
+		if (*len == 0) {
+			switch_set_flag(fh, SWITCH_FILE_DONE);
+            goto top;
+		} else {
+			status = SWITCH_STATUS_SUCCESS;
+		}
+
+	} else {
+
+		if ((status = fh->file_interface->file_read(fh, data, len)) != SWITCH_STATUS_SUCCESS || !*len) {
+			switch_set_flag(fh, SWITCH_FILE_DONE);
+			goto top;
+		}
 	}
 
+
 	got = *len;
 	
 	if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->native_rate != fh->samplerate) {
@@ -187,8 +228,6 @@
 
 	}
 	
-  done:
-
 	return status;
 }
 
@@ -235,7 +274,26 @@
 		return SWITCH_STATUS_SUCCESS;
 	}
 
-	return fh->file_interface->file_write(fh, data, len);
+
+	if (fh->pre_buffer) {
+		switch_size_t rlen, blen;
+		switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+		switch_buffer_write(fh->pre_buffer, data, *len * 2);
+
+		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);
+			blen /= 2;
+			if ((status = fh->file_interface->file_write(fh, fh->pre_buffer_data, &blen)) != SWITCH_STATUS_SUCCESS) {
+				*len = 0;
+			}
+		}
+		
+		return status;
+	} else {
+		return fh->file_interface->file_write(fh, data, len);
+	}
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_file_seek(switch_file_handle_t *fh, unsigned int *cur_pos, int64_t samples, int whence)
@@ -295,6 +353,21 @@
 		switch_buffer_destroy(&fh->buffer);
 	}
 
+	if (fh->pre_buffer) {
+		if (switch_test_flag(fh, SWITCH_FILE_FLAG_WRITE)) {
+			switch_size_t rlen, blen;
+			while((rlen = switch_buffer_inuse(fh->pre_buffer))) {
+				blen = switch_buffer_read(fh->pre_buffer, fh->pre_buffer_data, fh->pre_buffer_datalen);
+				blen /= 2;
+				if (fh->file_interface->file_write(fh, fh->pre_buffer_data, &blen) != SWITCH_STATUS_SUCCESS) {
+					break;
+				}
+			}
+		}
+
+		switch_buffer_destroy(&fh->pre_buffer);
+	}
+
 	switch_resample_destroy(&fh->resampler);
 
 	UNPROTECT_INTERFACE(fh->file_interface);

Modified: freeswitch/branches/1.0/src/switch_core_io.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_core_io.c	(original)
+++ freeswitch/branches/1.0/src/switch_core_io.c	Thu Jan 22 17:01:56 2009
@@ -805,7 +805,7 @@
 	}
 
 	if (session->write_codec) {
-		if (write_frame->datalen == session->write_codec->implementation->decoded_bytes_per_packet) {
+		if (write_frame->codec->implementation->decoded_bytes_per_packet == session->write_codec->implementation->decoded_bytes_per_packet) {
 			perfect = TRUE;
 		} else {
 			if (!session->raw_write_buffer) {
@@ -828,6 +828,12 @@
 		}
 
 		if (perfect) {
+
+			if (write_frame->datalen < session->write_codec->implementation->decoded_bytes_per_packet) {
+				memset(write_frame->data, 255, session->write_codec->implementation->decoded_bytes_per_packet - write_frame->datalen);
+				write_frame->datalen = session->write_codec->implementation->decoded_bytes_per_packet;
+			}
+
 			enc_frame = write_frame;
 			session->enc_write_frame.datalen = session->enc_write_frame.buflen;
 

Modified: freeswitch/branches/1.0/src/switch_core_session.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_core_session.c	(original)
+++ freeswitch/branches/1.0/src/switch_core_session.c	Thu Jan 22 17:01:56 2009
@@ -110,11 +110,12 @@
 		switch_hash_this(hi, NULL, NULL, &val);
 		if (val) {
 			session = (switch_core_session_t *) val;
-			switch_core_session_read_lock(session);
-			if (session->endpoint_interface == endpoint_interface) {
-				switch_channel_hangup(switch_core_session_get_channel(session), cause);
+			if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
+				if (session->endpoint_interface == endpoint_interface) {
+					switch_channel_hangup(switch_core_session_get_channel(session), cause);
+				}
+				switch_core_session_rwunlock(session);
 			}
-			switch_core_session_rwunlock(session);
 		}
 	}
 	switch_mutex_unlock(runtime.throttle_mutex);
@@ -132,9 +133,10 @@
 		switch_hash_this(hi, NULL, NULL, &val);
 		if (val) {
 			session = (switch_core_session_t *) val;
-			switch_core_session_read_lock(session);
-			switch_channel_hangup(switch_core_session_get_channel(session), cause);
-			switch_core_session_rwunlock(session);
+			if (switch_core_session_read_lock(session) == SWITCH_STATUS_SUCCESS) {
+				switch_channel_hangup(switch_core_session_get_channel(session), cause);
+				switch_core_session_rwunlock(session);
+			}
 		}
 	}
 	switch_mutex_unlock(runtime.throttle_mutex);
@@ -744,13 +746,14 @@
 	return x;
 }
 
-SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session, switch_bool_t flush_dtmf)
+SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session, switch_bool_t flush_dtmf, switch_bool_t reset_read_codec)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	switch_size_t has;
 
-
-	switch_core_session_set_read_codec(session, NULL);
+	if (reset_read_codec) {
+		switch_core_session_set_read_codec(session, NULL);
+	}
 
 	/* clear resamplers */
 	switch_mutex_lock(session->resample_mutex);
@@ -824,7 +827,7 @@
 					  switch_channel_get_name((*session)->channel), switch_channel_state_name(switch_channel_get_state((*session)->channel)));
 
 
-	switch_core_session_reset(*session, TRUE);
+	switch_core_session_reset(*session, TRUE, SWITCH_TRUE);
 	
 	switch_core_media_bug_remove_all(*session);
 	switch_ivr_deactivate_unicast(*session);

Modified: freeswitch/branches/1.0/src/switch_core_state_machine.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_core_state_machine.c	(original)
+++ freeswitch/branches/1.0/src/switch_core_state_machine.c	Thu Jan 22 17:01:56 2009
@@ -185,7 +185,7 @@
 {
 	switch_assert(session != NULL);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Standard PARK\n", switch_channel_get_name(session->channel));
-	switch_core_session_reset(session, SWITCH_TRUE);
+	switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 	switch_ivr_park(session, NULL);
 }
 

Modified: freeswitch/branches/1.0/src/switch_ivr.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_ivr.c	(original)
+++ freeswitch/branches/1.0/src/switch_ivr.c	Thu Jan 22 17:01:56 2009
@@ -1163,7 +1163,7 @@
 	max_forwards = switch_core_session_sprintf(session, "%d", forwardval);
 	switch_channel_set_variable(channel, SWITCH_MAX_FORWARDS_VARIABLE, max_forwards);
 
-	switch_core_session_reset(session, SWITCH_TRUE);
+	switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 	switch_channel_clear_flag(channel, CF_ORIGINATING);
 
 	/* clear all state handlers */

Modified: freeswitch/branches/1.0/src/switch_ivr_async.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_ivr_async.c	(original)
+++ freeswitch/branches/1.0/src/switch_ivr_async.c	Thu Jan 22 17:01:56 2009
@@ -371,7 +371,7 @@
 							  read_codec->implementation->actual_samples_per_second,
 							  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-		switch_core_session_reset(session, SWITCH_TRUE);
+		switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 		return SWITCH_STATUS_GENERR;
 	}
 
@@ -794,7 +794,7 @@
 		switch_core_session_rwunlock(tsession);
 		status = SWITCH_STATUS_SUCCESS;
 
-		switch_core_session_reset(session, SWITCH_TRUE);
+		switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 	}
 
 	return status;
@@ -842,6 +842,7 @@
 
 	fh->channels = channels;
 	fh->samplerate = read_codec->implementation->actual_samples_per_second;
+	fh->pre_buffer_datalen = SWITCH_DEFAULT_FILE_BUFFER_LEN;
 
 	if (switch_core_file_open(fh,
 							  file,
@@ -850,7 +851,7 @@
 							  SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", file);
 		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-		switch_core_session_reset(session, SWITCH_TRUE);
+		switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 		return SWITCH_STATUS_GENERR;
 	}
 
@@ -1678,7 +1679,11 @@
 	switch_thread_cond_create(&sth->cond, sth->pool);
 	switch_mutex_init(&sth->mutex, SWITCH_MUTEX_NESTED, sth->pool);
 
-	switch_core_session_read_lock(sth->session);
+	if (switch_core_session_read_lock(sth->session) != SWITCH_STATUS_SUCCESS) {
+		sth->ready = 0;
+		return NULL;
+	}
+
 	switch_mutex_lock(sth->mutex);
 
 	sth->ready = 1;

Modified: freeswitch/branches/1.0/src/switch_ivr_bridge.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_ivr_bridge.c	(original)
+++ freeswitch/branches/1.0/src/switch_ivr_bridge.c	Thu Jan 22 17:01:56 2009
@@ -430,7 +430,7 @@
 
   end:
 
-	switch_core_session_reset(session_a, SWITCH_TRUE);
+	switch_core_session_reset(session_a, SWITCH_TRUE, SWITCH_TRUE);
 	switch_channel_set_variable(chan_a, SWITCH_BRIDGE_VARIABLE, NULL);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "BRIDGE THREAD DONE [%s]\n", switch_channel_get_name(chan_a));
 	if (!inner_bridge) {
@@ -451,7 +451,7 @@
 		switch_channel_set_private(channel, "_bridge_", NULL);
 		if (bd->session == session && *bd->b_uuid) {
 			audio_bridge_thread(NULL, (void *) bd);
-			switch_core_session_reset(session, SWITCH_TRUE);
+			switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 		} else {
 			switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
 		}
@@ -581,7 +581,7 @@
 
 		switch_channel_wait_for_state(channel, other_channel, CS_SOFT_EXECUTE);
 
-		switch_core_session_reset(session, SWITCH_TRUE);
+		switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 
 
 		ready_a = switch_channel_ready(channel);

Modified: freeswitch/branches/1.0/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_ivr_originate.c	(original)
+++ freeswitch/branches/1.0/src/switch_ivr_originate.c	Thu Jan 22 17:01:56 2009
@@ -501,9 +501,9 @@
 				}
 
 				olen = mlen;
-				if (ringback.fh->resampler && ringback.fh->resampler->rfactor > 1) {
-					olen = (switch_size_t) (olen * ringback.fh->resampler->rfactor);
-				}
+				//if (ringback.fh->resampler && ringback.fh->resampler->rfactor > 1) {
+				//olen = (switch_size_t) (olen * ringback.fh->resampler->rfactor);
+				//}
 				switch_core_file_read(ringback.fh, write_frame.data, &olen);
 
 				if (olen == 0) {
@@ -547,7 +547,7 @@
 		switch_buffer_destroy(&ringback.audio_buffer);
 	}
 
-	switch_core_session_reset(session, SWITCH_TRUE);
+	switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 
 	if (write_codec.implementation) {
 		switch_core_codec_destroy(&write_codec);
@@ -1128,7 +1128,10 @@
 					continue;
 				}
 
-				switch_core_session_read_lock(new_session);
+				if (switch_core_session_read_lock(new_session) != SWITCH_STATUS_SUCCESS) {
+					status = SWITCH_STATUS_FALSE;
+					goto done;
+				}
 				pool = NULL;
 
 				caller_profiles[i] = new_profile;
@@ -1473,9 +1476,10 @@
 							}
 
 							olen = mlen;
-							if (ringback.fh->resampler && ringback.fh->resampler->rfactor > 1) {
-								olen = (switch_size_t) (olen * ringback.fh->resampler->rfactor);
-							}
+							
+							//if (ringback.fh->resampler && ringback.fh->resampler->rfactor > 1) {
+							//olen = (switch_size_t) (olen * ringback.fh->resampler->rfactor);
+							//}
 							
 							switch_core_file_read(ringback.fh, write_frame.data, &olen);
 
@@ -1527,7 +1531,7 @@
 
 			if (session && (ringback_data || !(switch_channel_test_flag(caller_channel, CF_PROXY_MODE) &&
 											   switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA)))) {
-				switch_core_session_reset(session, SWITCH_FALSE);
+				switch_core_session_reset(session, SWITCH_FALSE, SWITCH_TRUE);
 			}
 
 			for (i = 0; i < and_argc; i++) {
@@ -1716,7 +1720,7 @@
 			}
 
 			if (session) {
-				switch_core_session_reset(session, SWITCH_FALSE);
+				switch_core_session_reset(session, SWITCH_FALSE, SWITCH_TRUE);
 			}
 
 			if (write_codec.implementation) {

Modified: freeswitch/branches/1.0/src/switch_ivr_play_say.c
==============================================================================
--- freeswitch/branches/1.0/src/switch_ivr_play_say.c	(original)
+++ freeswitch/branches/1.0/src/switch_ivr_play_say.c	Thu Jan 22 17:01:56 2009
@@ -402,7 +402,7 @@
 							  read_codec->implementation->actual_samples_per_second,
 							  SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
-		switch_core_session_reset(session, SWITCH_TRUE);
+		switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 		return SWITCH_STATUS_GENERR;
 	}
 
@@ -460,7 +460,7 @@
 						  "Raw Codec Activation Failed %s@%uhz %u channels %dms\n", codec_name, fh->samplerate,
 						  fh->channels, read_codec->implementation->microseconds_per_packet / 1000);
 		switch_core_file_close(fh);
-		switch_core_session_reset(session, SWITCH_TRUE);
+		switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 		return SWITCH_STATUS_GENERR;
 	}
 
@@ -580,7 +580,7 @@
 	}
 
 	switch_core_file_close(fh);
-	switch_core_session_reset(session, SWITCH_TRUE);
+	switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 	return status;
 }
 
@@ -853,7 +853,7 @@
 							  read_codec->implementation->number_of_channels,
 							  read_codec->implementation->actual_samples_per_second,
 							  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
-		switch_core_session_reset(session, SWITCH_TRUE);
+		switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 		status = SWITCH_STATUS_NOTFOUND;
 		goto end;
 	}
@@ -910,7 +910,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Setup buffer failed\n");
 
 			switch_core_file_close(fh);
-			switch_core_session_reset(session, SWITCH_TRUE);
+			switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 
 			status = SWITCH_STATUS_GENERR;
 			goto end;
@@ -937,7 +937,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
 							  "Raw Codec Activation Failed %s@%uhz %u channels %dms\n", codec_name, fh->samplerate, fh->channels, interval);
 			switch_core_file_close(fh);
-			switch_core_session_reset(session, SWITCH_TRUE);
+			switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 			status = SWITCH_STATUS_GENERR;
 			goto end;
 		}
@@ -953,7 +953,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Setup timer failed!\n");
 			switch_core_codec_destroy(&codec);
 			switch_core_file_close(fh);
-			switch_core_session_reset(session, SWITCH_TRUE);
+			switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 			status = SWITCH_STATUS_GENERR;
 			goto end;
 		}
@@ -1238,7 +1238,7 @@
   end:
 	switch_safe_free(abuf);
 
-	switch_core_session_reset(session, SWITCH_FALSE);
+	switch_core_session_reset(session, SWITCH_FALSE, SWITCH_TRUE);
 	return status;
 }
 
@@ -1275,7 +1275,7 @@
 								  read_codec->implementation->number_of_channels,
 								  read_codec->implementation->actual_samples_per_second,
 								  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
-			switch_core_session_reset(session, SWITCH_TRUE);
+			switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 			return SWITCH_STATUS_NOTFOUND;
 		}
 		switch_zmalloc(abuf, SWITCH_RECOMMENDED_BUFFER_SIZE);
@@ -1362,7 +1362,7 @@
 		}
 	}
 
-	switch_core_session_reset(session, SWITCH_FALSE);
+	switch_core_session_reset(session, SWITCH_FALSE, SWITCH_TRUE);
 	switch_core_codec_destroy(&raw_codec);
 
  end:
@@ -1835,7 +1835,7 @@
 
 	timer_name = switch_channel_get_variable(channel, "timer_name");
 
-	switch_core_session_reset(session, SWITCH_FALSE);
+	switch_core_session_reset(session, SWITCH_FALSE, SWITCH_TRUE);
 	read_codec = switch_core_session_get_read_codec(session);
 
 	rate = read_codec->implementation->actual_samples_per_second;
@@ -1846,7 +1846,7 @@
 		if (switch_core_speech_open(sh, tts_name, voice_name, (uint32_t) rate, interval,
 									&flags, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid TTS module!\n");
-			switch_core_session_reset(session, SWITCH_TRUE);
+			switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 			if (cache_obj) {
 				switch_channel_set_private(channel, SWITCH_CACHE_SPEECH_HANDLES_OBJ_NAME, NULL);
 			}
@@ -1872,7 +1872,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed %s@%uhz 1 channel %dms\n", codec_name, rate, interval);
 			flags = 0;
 			switch_core_speech_close(sh, &flags);
-			switch_core_session_reset(session, SWITCH_TRUE);
+			switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 			if (cache_obj) {
 				switch_channel_set_private(channel, SWITCH_CACHE_SPEECH_HANDLES_OBJ_NAME, NULL);
 			}
@@ -1889,7 +1889,7 @@
 				switch_core_codec_destroy(write_frame.codec);
 				flags = 0;
 				switch_core_speech_close(sh, &flags);
-				switch_core_session_reset(session, SWITCH_TRUE);
+				switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 				if (cache_obj) {
 					switch_channel_set_private(channel, SWITCH_CACHE_SPEECH_HANDLES_OBJ_NAME, NULL);
 				}
@@ -1918,7 +1918,7 @@
 		}
 	}
 
-	switch_core_session_reset(session, SWITCH_FALSE);
+	switch_core_session_reset(session, SWITCH_FALSE, SWITCH_TRUE);
 	return status;
 }
 



More information about the Freeswitch-svn mailing list