[Freeswitch-svn] [commit] r11730 - in freeswitch/trunk/src: . include mod/applications/mod_conference mod/applications/mod_esf mod/applications/mod_fax mod/applications/mod_fsv mod/applications/mod_rss mod/applications/mod_voicemail mod/formats/mod_shout mod/languages/mod_spidermonkey_teletone

FreeSWITCH SVN anthm at freeswitch.org
Tue Feb 10 11:09:07 PST 2009


Author: anthm
Date: Tue Feb 10 13:09:06 2009
New Revision: 11730

Log:
spring cleaning

Modified:
   freeswitch/trunk/src/include/switch_channel.h
   freeswitch/trunk/src/include/switch_types.h
   freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
   freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c
   freeswitch/trunk/src/mod/applications/mod_fax/mod_fax.c
   freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c
   freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c
   freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
   freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c
   freeswitch/trunk/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c
   freeswitch/trunk/src/switch_channel.c
   freeswitch/trunk/src/switch_core_media_bug.c
   freeswitch/trunk/src/switch_core_session.c
   freeswitch/trunk/src/switch_ivr.c
   freeswitch/trunk/src/switch_ivr_async.c
   freeswitch/trunk/src/switch_ivr_bridge.c
   freeswitch/trunk/src/switch_ivr_play_say.c

Modified: freeswitch/trunk/src/include/switch_channel.h
==============================================================================
--- freeswitch/trunk/src/include/switch_channel.h	(original)
+++ freeswitch/trunk/src/include/switch_channel.h	Tue Feb 10 13:09:06 2009
@@ -74,7 +74,11 @@
   \param channel channel to test
   \return true if the channel is ready
 */
-SWITCH_DECLARE(uint8_t) switch_channel_ready(switch_channel_t *channel);
+SWITCH_DECLARE(int) switch_channel_test_ready(switch_channel_t *channel, switch_bool_t media);
+
+#define switch_channel_ready(_channel) switch_channel_test_ready(_channel, SWITCH_FALSE)
+#define switch_channel_media_ready(_channel) switch_channel_test_ready(_channel, SWITCH_TRUE)
+
 
 SWITCH_DECLARE(void) switch_channel_wait_for_state(switch_channel_t *channel, switch_channel_t *other_channel, switch_channel_state_t want_state);
 SWITCH_DECLARE(switch_status_t) switch_channel_wait_for_flag(switch_channel_t *channel, 
@@ -496,8 +500,6 @@
 
 #define switch_channel_stop_broadcast(_channel)	for(;;) {if (switch_channel_test_flag(_channel, CF_BROADCAST)) {switch_channel_set_flag(_channel, CF_STOP_BROADCAST); switch_channel_set_flag(_channel, CF_BREAK); } break;}
 
-#define switch_channel_media_ready(_channel) ((switch_channel_test_flag(_channel, CF_ANSWERED) || switch_channel_test_flag(_channel, CF_EARLY_MEDIA)) && !switch_channel_test_flag(_channel, CF_PROXY_MODE))
-
 SWITCH_DECLARE(void) switch_channel_audio_sync(switch_channel_t *channel);
 
 SWITCH_DECLARE(void) switch_channel_set_private_flag(switch_channel_t *channel, uint32_t flags);

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Tue Feb 10 13:09:06 2009
@@ -149,6 +149,7 @@
 #define SWITCH_SIGNAL_BOND_VARIABLE "signal_bond"
 #define SWITCH_ORIGINATOR_VARIABLE "originator"
 #define SWITCH_ORIGINATOR_CODEC_VARIABLE "originator_codec"
+#define SWITCH_ORIGINATOR_VIDEO_CODEC_VARIABLE "originator_video_codec"
 #define SWITCH_LOCAL_MEDIA_IP_VARIABLE "local_media_ip"
 #define SWITCH_LOCAL_MEDIA_PORT_VARIABLE "local_media_port"
 #define SWITCH_REMOTE_MEDIA_IP_VARIABLE "remote_media_ip"

Modified: freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c	Tue Feb 10 13:09:06 2009
@@ -291,7 +291,7 @@
 	switch_mutex_t *control_mutex;
 	switch_mutex_t *audio_in_mutex;
 	switch_mutex_t *audio_out_mutex;
-	switch_codec_t *orig_read_codec;
+	switch_codec_implementation_t orig_read_impl;
 	switch_codec_t read_codec;
 	switch_codec_t write_codec;
 	char *rec_path;
@@ -1773,7 +1773,6 @@
 	switch_frame_t write_frame = { 0 };
 	uint8_t *data = NULL;
 	switch_timer_t timer = { 0 };
-	switch_codec_t *read_codec;
 	uint32_t interval;
 	uint32_t samples;
 	uint32_t csamples;
@@ -1782,9 +1781,12 @@
 	uint32_t low_count, bytes;
 	call_list_t *call_list, *cp;
 	int restarting = -1;
-
+	switch_codec_implementation_t read_impl = {0};
+	
  top:
 
+	switch_core_session_get_read_impl(member->session, &read_impl);
+
 	restarting++;
 	
 	if (switch_test_flag(member, MFLAG_RESTART)) {
@@ -1794,11 +1796,10 @@
 	}
 
 	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;
+	interval = read_impl.microseconds_per_packet / 1000;
 	samples = switch_samples_per_packet(member->conference->rate, interval);
 	csamples = samples;
-	tsamples = member->orig_read_codec->implementation->samples_per_packet;
+	tsamples = member->orig_read_impl.samples_per_packet;
 	flush_len = 0;
 	low_count = 0;
 	bytes = samples * 2;
@@ -4434,9 +4435,9 @@
 
 static int setup_media(conference_member_t *member, conference_obj_t *conference)
 {
-	switch_codec_t *read_codec;
+	switch_codec_implementation_t read_impl = {0};
+	switch_core_session_get_read_impl(member->session, &read_impl);
 
-	
 	switch_core_session_reset(member->session, SWITCH_TRUE, SWITCH_FALSE);
 
 	if (member->read_codec.implementation) {
@@ -4447,22 +4448,22 @@
 		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;
+
+	switch_core_session_get_read_impl(member->session, &member->orig_read_impl);
+	member->native_rate = read_impl.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,
+							   NULL, read_impl.actual_samples_per_second, read_impl.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);
+						  read_impl.actual_samples_per_second, read_impl.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);
+						  read_impl.actual_samples_per_second, read_impl.microseconds_per_packet / 1000);
 
 		goto done;
 	}
@@ -4473,9 +4474,9 @@
 		member->mux_frame = switch_core_alloc(member->pool, member->frame_size);
 	}
 
-	if (read_codec->implementation->actual_samples_per_second != conference->rate) {
+	if (read_impl.actual_samples_per_second != conference->rate) {
 		if (switch_resample_create(&member->read_resampler,
-								   read_codec->implementation->actual_samples_per_second,
+								   read_impl.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;
@@ -4499,14 +4500,14 @@
 							   "L16",
 							   NULL,
 							   conference->rate,
-							   read_codec->implementation->microseconds_per_packet / 1000,
+							   read_impl.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);
+						  conference->rate, read_impl.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);
+						  conference->rate, read_impl.microseconds_per_packet / 1000);
 		goto codec_done2;
 	}
 

Modified: freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c	Tue Feb 10 13:09:06 2009
@@ -64,7 +64,7 @@
 	switch_status_t status;
 	switch_size_t bytes;
 	ls_control_packet_t control_packet;
-	switch_codec_t codec = { 0 }, *read_codec, *orig_codec = NULL;
+	switch_codec_t codec = { 0 };
 	uint32_t flags = 0;
 	const char *err;
 	switch_rtp_t *rtp_session = NULL;
@@ -78,6 +78,9 @@
 	switch_port_t mcast_control_port = 6061;
 	char *mcast_port_str = "34567";
 	const char *esf_broadcast_ip = NULL, *var;
+	switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
+
 
 	if (!switch_strlen_zero((char *) data)) {
 		mydata = switch_core_session_strdup(session, data);
@@ -120,8 +123,6 @@
 		switch_channel_answer(channel);
 	}
 
-	read_codec = switch_core_session_get_read_codec(session);
-
 	if (switch_socket_create(&socket, AF_INET, SOCK_DGRAM, 0, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error 1\n");
 		goto fail;
@@ -144,7 +145,7 @@
 			goto fail;
 		}
 
-		if (read_frame->packet && read_frame->packetlen && read_codec->implementation->ianacode == 0) {
+		if (read_frame->packet && read_frame->packetlen && read_impl.ianacode == 0) {
 			ready = SEND_TYPE_RAW;
 		} else {
 			ready = SEND_TYPE_RTP;
@@ -152,7 +153,7 @@
 	}
 
 	if (ready == SEND_TYPE_RTP) {
-		if (read_codec->implementation->ianacode != 0) {
+		if (read_impl.ianacode != 0) {
 			if (switch_core_codec_init(&codec,
 									   "PCMU",
 									   NULL,
@@ -160,9 +161,7 @@
 									   20,
 									   1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
 									   NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
-				orig_codec = read_codec;
-				read_codec = &codec;
-				switch_core_session_set_read_codec(session, read_codec);
+				switch_core_session_set_read_codec(session, &codec);
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Codec Activation Success\n");
 			} else {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Activation Fail\n");
@@ -187,9 +186,9 @@
 									 rtp_port,
 									 mcast_ip,
 									 mcast_port,
-									 read_codec->implementation->ianacode,
-									 read_codec->implementation->samples_per_packet,
-									 read_codec->implementation->microseconds_per_packet,
+									 read_impl.ianacode,
+									 read_impl.samples_per_packet,
+									 read_impl.microseconds_per_packet,
 									 (switch_rtp_flag_t) flags, "soft", &err, switch_core_session_get_pool(session));
 
 		if (!switch_rtp_ready(rtp_session)) {
@@ -242,8 +241,8 @@
 
   fail:
 
-	if (orig_codec) {
-		switch_core_session_set_read_codec(session, orig_codec);
+	switch_core_session_set_read_codec(session, NULL);
+	if (codec.implementation) {
 		switch_core_codec_destroy(&codec);
 	}
 

Modified: freeswitch/trunk/src/mod/applications/mod_fax/mod_fax.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_fax/mod_fax.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_fax/mod_fax.c	Tue Feb 10 13:09:06 2009
@@ -394,13 +394,12 @@
 	const char *tmp;
 
 	switch_channel_t *channel;
-
-	switch_codec_t *orig_read_codec = NULL;
 	switch_codec_t read_codec = { 0 };
 	switch_codec_t write_codec = { 0 };
 	switch_frame_t *read_frame = { 0 };
 	switch_frame_t write_frame = { 0 };
-
+    switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
 	int16_t *buf = NULL;
 
 	/* make sure we have a valid channel when starting the FAX application */
@@ -575,13 +574,12 @@
 	 * used internally by spandsp and FS will do the transcoding
 	 * from G.711 or any other original codec
 	 */
-	orig_read_codec = switch_core_session_get_read_codec(session);
 
 	if (switch_core_codec_init(&read_codec,
 							   "L16",
 							   NULL,
-							   orig_read_codec->implementation->samples_per_second,
-							   orig_read_codec->implementation->microseconds_per_packet / 1000,
+							   read_impl.samples_per_second,
+							   read_impl.microseconds_per_packet / 1000,
 							   1,
 							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
 							   NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
@@ -596,8 +594,8 @@
 	if (switch_core_codec_init(&write_codec,
 							   "L16",
 							   NULL,
-							   orig_read_codec->implementation->samples_per_second,
-							   orig_read_codec->implementation->microseconds_per_packet / 1000,
+							   read_impl.samples_per_second,
+							   read_impl.microseconds_per_packet / 1000,
 							   1,
 							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
 							   NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
@@ -673,6 +671,8 @@
 
 	/* restore the original codecs over the channel */
 
+    switch_core_session_set_read_codec(session, NULL);
+
 	if (read_codec.implementation) {
 		switch_core_codec_destroy(&read_codec);
 	}
@@ -681,9 +681,9 @@
 		switch_core_codec_destroy(&write_codec);
 	}
 
-	if (orig_read_codec) {
-		switch_core_session_set_read_codec(session, orig_read_codec);
-	}
+
+
+
 
 }
 

Modified: freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c	Tue Feb 10 13:09:06 2009
@@ -106,7 +106,9 @@
 	switch_threadattr_t *thd_attr = NULL;
 	int fd;
 	switch_mutex_t *mutex = NULL;
-	switch_codec_t codec, *read_codec, *vid_codec;
+	switch_codec_t codec, *vid_codec;
+	switch_codec_implementation_t read_impl = {0};
+	switch_core_session_get_read_impl(session, &read_impl);
 
 	switch_channel_answer(channel);
 
@@ -117,13 +119,11 @@
 
 	switch_channel_answer(channel);
 
-	read_codec = switch_core_session_get_read_codec(session);
-
 	if (switch_core_codec_init(&codec,
 							   "L16",
 							   NULL,
-							   read_codec->implementation->samples_per_second,
-							   read_codec->implementation->microseconds_per_packet / 1000,
+							   read_impl.samples_per_second,
+							   read_impl.microseconds_per_packet / 1000,
 							   1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
 							   NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Audio Codec Activation Success\n");
@@ -145,8 +145,8 @@
 		if (vid_codec->fmtp_in) {
 			switch_set_string(h.video_fmtp, vid_codec->fmtp_in);
 		}
-		h.audio_rate = read_codec->implementation->samples_per_second;
-		h.audio_ptime = read_codec->implementation->microseconds_per_packet / 1000;
+		h.audio_rate = read_impl.samples_per_second;
+		h.audio_ptime = read_impl.microseconds_per_packet / 1000;
 
 		if (write(fd, &h, sizeof(h)) != sizeof(h)) {
 			goto end;
@@ -207,7 +207,7 @@
 		}
 	}
 
-	switch_core_session_set_read_codec(session, read_codec);
+	switch_core_session_set_read_codec(session, NULL);
 	switch_core_codec_destroy(&codec);
 
 }
@@ -227,6 +227,8 @@
 	uint32_t ts = 0, last = 0;
 	switch_timer_t timer = { 0 };
 	switch_payload_t pt = 0;
+    switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
 
 	aud_buffer = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE);
 	vid_buffer = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE);
@@ -263,10 +265,8 @@
 	vid_frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE - 12;
 	switch_set_flag((&vid_frame), SFF_RAW_RTP);
 
-	read_codec = switch_core_session_get_read_codec(session);
-
-	if (switch_core_timer_init(&timer, "soft", read_codec->implementation->microseconds_per_packet / 1000,
-							   read_codec->implementation->samples_per_packet, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+	if (switch_core_timer_init(&timer, "soft", read_impl.microseconds_per_packet / 1000,
+							   read_impl.samples_per_packet, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Timer Activation Fail\n");
 		goto end;
 	}

Modified: freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_rss/mod_rss.c	Tue Feb 10 13:09:06 2009
@@ -163,7 +163,7 @@
 	struct rss_entry entries[TTS_MAX_ENTRIES] = { {0} };
 	uint32_t i = 0;
 	char *title_txt = "", *description_txt = "", *rights_txt = "";
-	switch_codec_t speech_codec, *codec = switch_core_session_get_read_codec(session);
+	switch_codec_t speech_codec;
 	char *engine = TTS_DEFAULT_ENGINE;
 	char *voice = TTS_DEFAULT_VOICE;
 	char *timer_name = NULL;
@@ -184,8 +184,9 @@
 	switch_input_args_t args = { 0 };
 	const char *vcf = NULL;
 	char *chanvars = switch_channel_build_param_string(channel, NULL, NULL);
-	switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
-	uint32_t rate, interval = read_codec->implementation->microseconds_per_packet / 1000;
+	switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
+	uint32_t rate, interval = read_impl.microseconds_per_packet / 1000;
 
 	if ((vcf = switch_channel_get_variable(channel, "rss_alt_config"))) {
 		cf = vcf;
@@ -253,8 +254,8 @@
 		return;
 	}
 
-	if (codec) {
-		rate = codec->implementation->actual_samples_per_second;
+	if (switch_channel_media_ready(channel)) {
+		rate = read_impl.actual_samples_per_second;
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec Error!\n");
 		return;

Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	Tue Feb 10 13:09:06 2009
@@ -1042,9 +1042,9 @@
 	char term;
 	char input[10] = "", key_buf[80] = "";
 	cc_t cc = { 0 };
-	switch_codec_t *read_codec;
+	switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
 
-	read_codec = switch_core_session_get_read_codec(session);
 
 	if (exit_keys) {
 		*key_pressed = '\0';
@@ -1072,7 +1072,7 @@
 
 		switch_ivr_record_file(session, &fh, file_path, &args, profile->max_record_len);
 
-		if (limit && (*message_len = fh.sample_count / read_codec->implementation->actual_samples_per_second) < profile->min_record_len) {
+		if (limit && (*message_len = fh.sample_count / read_impl.actual_samples_per_second) < profile->min_record_len) {
 			if (unlink(file_path) != 0) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to delete file [%s]\n", file_path);
 			}
@@ -1216,7 +1216,6 @@
 static char *vm_merge_file(switch_core_session_t *session, vm_profile_t *profile, const char *announce, const char *orig)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);	
-	switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
 	switch_file_handle_t lrfh = { 0 }, *rfh = NULL, lfh = { 0 }, *fh = NULL;
 	char *tmp_path;
 	switch_uuid_t uuid;
@@ -1225,19 +1224,21 @@
 	int16_t *abuf = NULL;
 	switch_size_t olen = 0;
 	int asis = 0;
+    switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
 
 	switch_uuid_get(&uuid);
 	switch_uuid_format(uuid_str, &uuid);
 
-	lfh.channels = read_codec->implementation->number_of_channels;
-	lfh.native_rate = read_codec->implementation->actual_samples_per_second;
+	lfh.channels = read_impl.number_of_channels;
+	lfh.native_rate = read_impl.actual_samples_per_second;
 
 	tmp_path = switch_core_session_sprintf(session, "%s%smsg_%s.%s", SWITCH_GLOBAL_dirs.temp_dir, SWITCH_PATH_SEPARATOR, uuid_str, profile->file_ext);
 
 	if (switch_core_file_open(&lfh,
 							  tmp_path,
 							  lfh.channels,
-							  read_codec->implementation->actual_samples_per_second,
+							  read_impl.actual_samples_per_second,
 							  SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open file %s\n", tmp_path);
 		goto end;
@@ -1249,7 +1250,7 @@
 	if (switch_core_file_open(&lrfh,
 							  announce,
 							  lfh.channels,
-							  read_codec->implementation->actual_samples_per_second,
+							  read_impl.actual_samples_per_second,
 							  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open file %s\n", announce);
 		goto end;
@@ -1286,7 +1287,7 @@
 	if (switch_core_file_open(&lrfh,
 							  orig,
 							  lfh.channels,
-							  read_codec->implementation->actual_samples_per_second,
+							  read_impl.actual_samples_per_second,
 							  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open file %s\n", orig);
 		goto end;

Modified: freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c
==============================================================================
--- freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c	(original)
+++ freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c	Tue Feb 10 13:09:06 2009
@@ -1203,17 +1203,18 @@
 		switch_mutex_t *mutex;
 		switch_channel_t *channel = switch_core_session_get_channel(tsession);
 		lame_global_flags *gfp = NULL;
-		switch_codec_t *read_codec;
+		switch_codec_implementation_t read_impl = {0};
+		switch_core_session_get_read_impl(tsession, &read_impl);
+
+
 
 		if (!(gfp = lame_init())) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate lame\n");
 			goto end;
 		}
-		read_codec = switch_core_session_get_read_codec(tsession);
-
-		lame_set_num_channels(gfp, read_codec->implementation->number_of_channels);
-		lame_set_in_samplerate(gfp, read_codec->implementation->actual_samples_per_second);
-		lame_set_brate(gfp, 16 * (read_codec->implementation->actual_samples_per_second / 8000) * read_codec->implementation->number_of_channels);
+		lame_set_num_channels(gfp, read_impl.number_of_channels);
+		lame_set_in_samplerate(gfp, read_impl.actual_samples_per_second);
+		lame_set_brate(gfp, 16 * (read_impl.actual_samples_per_second / 8000) * read_impl.number_of_channels);
 		lame_set_mode(gfp, 3);
 		lame_set_quality(gfp, 2);
 		lame_set_errorf(gfp, log_error);

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey_teletone/mod_spidermonkey_teletone.c	Tue Feb 10 13:09:06 2009
@@ -78,9 +78,11 @@
 	JSObject *session_obj;
 	struct teletone_obj *tto = NULL;
 	struct js_session *jss = NULL;
-	switch_codec_t *read_codec;
 	switch_memory_pool_t *pool;
 	char *timer_name = NULL;
+    switch_codec_implementation_t read_impl = {0};
+
+
 
 	if (argc > 0) {
 		if (JS_ValueToObject(cx, argv[0], &session_obj)) {
@@ -107,14 +109,14 @@
 		return JS_FALSE;
 	}
 
-	read_codec = switch_core_session_get_read_codec(jss->session);
+    switch_core_session_get_read_impl(jss->session, &read_impl);
 
 	if (switch_core_codec_init(&tto->codec,
 							   "L16",
 							   NULL,
-							   read_codec->implementation->actual_samples_per_second,
-							   read_codec->implementation->microseconds_per_packet / 1000,
-							   read_codec->implementation->number_of_channels,
+							   read_impl.actual_samples_per_second,
+							   read_impl.microseconds_per_packet / 1000,
+							   read_impl.number_of_channels,
 							   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, pool) == SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
 	} else {
@@ -123,12 +125,12 @@
 	}
 
 	if (timer_name) {
-		unsigned int ms = read_codec->implementation->microseconds_per_packet / 1000;
+		unsigned int ms = read_impl.microseconds_per_packet / 1000;
 		if (switch_core_timer_init(&tto->timer_base,
 								   timer_name,
 								   ms,
-								   (read_codec->implementation->samples_per_second / 50) *
-								   read_codec->implementation->number_of_channels, pool) == SWITCH_STATUS_SUCCESS) {
+								   (read_impl.samples_per_second / 50) *
+								   read_impl.number_of_channels, pool) == SWITCH_STATUS_SUCCESS) {
 			tto->timer = &tto->timer_base;
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Timer INIT Success %u\n", ms);
 		} else {

Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c	(original)
+++ freeswitch/trunk/src/switch_channel.c	Tue Feb 10 13:09:06 2009
@@ -864,12 +864,22 @@
 	return state;
 }
 
-SWITCH_DECLARE(uint8_t) switch_channel_ready(switch_channel_t *channel)
+SWITCH_DECLARE(int) switch_channel_test_ready(switch_channel_t *channel, switch_bool_t media)
 {
-	uint8_t ret = 0;
+	int ret = 0;
 
 	switch_assert(channel != NULL);
 
+	if (media) {
+		ret = ((switch_channel_test_flag(channel, CF_ANSWERED) || 
+				switch_channel_test_flag(channel, CF_EARLY_MEDIA)) && !switch_channel_test_flag(channel, CF_PROXY_MODE) && 
+			   switch_core_session_get_read_codec(channel->session) && switch_core_session_get_write_codec(channel->session));
+
+		if (!ret) return ret;
+	}
+	
+	ret = 0;
+
 	if (!channel->hangup_cause && channel->state > CS_ROUTING && channel->state < CS_HANGUP && channel->state != CS_RESET &&
 		!switch_channel_test_flag(channel, CF_TRANSFER)) {
 		ret++;

Modified: freeswitch/trunk/src/switch_core_media_bug.c
==============================================================================
--- freeswitch/trunk/src/switch_core_media_bug.c	(original)
+++ freeswitch/trunk/src/switch_core_media_bug.c	Tue Feb 10 13:09:06 2009
@@ -113,7 +113,8 @@
 	uint32_t blen;
 	size_t rdlen = 0;
 	uint32_t maxlen;
-	switch_codec_t *read_codec = switch_core_session_get_read_codec(bug->session);
+	switch_codec_implementation_t read_impl = {0};
+	switch_core_session_get_read_impl(bug->session, &read_impl);
 
 	if (bug->raw_read_buffer) {
 		rlen = switch_buffer_inuse(bug->raw_read_buffer);
@@ -196,7 +197,7 @@
 
 		frame->datalen = bytes;
 		frame->samples = bytes / sizeof(int16_t);
-		frame->rate = read_codec->implementation->actual_samples_per_second;
+		frame->rate = read_impl.actual_samples_per_second;
 
 		return SWITCH_STATUS_SUCCESS;
 	}

Modified: freeswitch/trunk/src/switch_core_session.c
==============================================================================
--- freeswitch/trunk/src/switch_core_session.c	(original)
+++ freeswitch/trunk/src/switch_core_session.c	Tue Feb 10 13:09:06 2009
@@ -197,7 +197,7 @@
 	switch_assert(session != NULL);
 	return session->private_info;
 }
-
+ 
 
 SWITCH_DECLARE(switch_status_t) switch_core_session_set_private(switch_core_session_t *session, void *private_info)
 {
@@ -341,7 +341,7 @@
 		
 		if (channel) {
 			const char *export_vars, *val;
-			switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
+			switch_codec_t *vid_read_codec = NULL, *read_codec = switch_core_session_get_read_codec(session);
 			const char *max_forwards = switch_core_session_sprintf(session, "%d", forwardval);
 
 			switch_channel_set_variable(peer_channel, SWITCH_MAX_FORWARDS_VARIABLE, max_forwards);
@@ -353,6 +353,14 @@
 				switch_codec2str(read_codec, tmp, sizeof(tmp));
 				switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_CODEC_VARIABLE, tmp);
 			}
+			
+			vid_read_codec = switch_core_session_get_video_read_codec(session);
+			if (vid_read_codec && vid_read_codec->implementation) {
+				char tmp[80];
+				switch_codec2str(vid_read_codec, tmp, sizeof(tmp));
+				switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_VIDEO_CODEC_VARIABLE, tmp);
+			}
+			
 
 			switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_VARIABLE, switch_core_session_get_uuid(session));
 			switch_channel_set_variable(peer_channel, SWITCH_SIGNAL_BOND_VARIABLE, switch_core_session_get_uuid(session));

Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c	(original)
+++ freeswitch/trunk/src/switch_ivr.c	Tue Feb 10 13:09:06 2009
@@ -642,13 +642,17 @@
 	int stream_id = 0;
 	switch_event_t *event;
 	switch_unicast_conninfo_t *conninfo = NULL;
-	switch_codec_t *read_codec;
 	uint32_t rate;
 	uint32_t bpf;
 	const char *to;
 	int timeout = 0;
 	time_t expires = 0;
 
+	switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
+
+
+
 	if (switch_channel_test_flag(channel, CF_CONTROLLED)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot park channels that are under control already.\n");
 		return SWITCH_STATUS_FALSE;
@@ -666,15 +670,13 @@
 		return SWITCH_STATUS_FALSE;
 	}
 	
-	read_codec = switch_core_session_get_read_codec(session);
-
-	if (!read_codec || !read_codec->implementation) {
+	if (switch_channel_media_ready(channel)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot park channels that have no read codec.\n");
 		return SWITCH_STATUS_FALSE;
 	}
 
-	rate = read_codec->implementation->actual_samples_per_second;
-	bpf = read_codec->implementation->decoded_bytes_per_packet;
+	rate = read_impl.actual_samples_per_second;
+	bpf = read_impl.decoded_bytes_per_packet;
 
 	if ((to = switch_channel_get_variable(channel, "park_timeout"))) {
 		if ((timeout = atoi(to)) < 0) {
@@ -690,7 +692,7 @@
 		switch_event_fire(&event);
 	}
 
-	while (read_codec && switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_CONTROLLED)) {
+	while (switch_channel_media_ready(channel) && switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_CONTROLLED)) {
 
 		if ((status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, stream_id)) == SWITCH_STATUS_SUCCESS) {
 			if (!SWITCH_READ_ACCEPTABLE(status)) {
@@ -732,11 +734,12 @@
 						if (switch_test_flag(conninfo, SUF_NATIVE)) {
 							tstatus = SWITCH_STATUS_NOOP;
 						} else {
+							switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
 							tstatus = switch_core_codec_decode(read_codec,
 															   &conninfo->read_codec,
 															   read_frame->data,
 															   read_frame->datalen,
-															   read_codec->implementation->actual_samples_per_second, decoded, &dlen, &rate, &flags);
+															   read_impl.actual_samples_per_second, decoded, &dlen, &rate, &flags);
 						}
 						switch (tstatus) {
 						case SWITCH_STATUS_NOOP:
@@ -1944,28 +1947,29 @@
 {
 	stfu_instance_t *jb;
 	int qlen = 0;
-	switch_codec_t *read_codec;
 	stfu_frame_t *jb_frame;
 	switch_frame_t *read_frame, write_frame = { 0 };
 	switch_status_t status;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	uint32_t interval, samples;
 	uint32_t ts = 0;
+    switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
+
 
 	if (delay_ms < 1 || delay_ms > 10000) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid delay [%d] must be between 1 and 10000\n", delay_ms);
 		return;
 	}
 
-	read_codec = switch_core_session_get_read_codec(session);
-	interval = read_codec->implementation->microseconds_per_packet / 1000;
-	samples = switch_samples_per_packet(read_codec->implementation->samples_per_second, interval);
+	interval = read_impl.microseconds_per_packet / 1000;
+	samples = switch_samples_per_packet(read_impl.samples_per_second, interval);
 
 	qlen = delay_ms / (interval);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setting delay to %dms (%d frames)\n", delay_ms, qlen);
 	jb = stfu_n_init(qlen);
 
-	write_frame.codec = read_codec;
+	write_frame.codec = switch_core_session_get_read_codec(session);
 
 	while (switch_channel_ready(channel)) {
 		status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);

Modified: freeswitch/trunk/src/switch_ivr_async.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_async.c	(original)
+++ freeswitch/trunk/src/switch_ivr_async.c	Tue Feb 10 13:09:06 2009
@@ -78,7 +78,9 @@
 	switch_threadattr_t *thd_attr = NULL;
 #endif
 
-	switch_channel_pre_answer(channel);
+	if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+		return;
+	}
 
 #ifdef SWITCH_VIDEO_IN_THREADS
 	if (switch_channel_test_flag(channel, CF_VIDEO)) {
@@ -335,13 +337,17 @@
 SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_t *session, const char *file, uint32_t limit, const char *flags)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
-	switch_codec_t *read_codec;
 	switch_media_bug_t *bug;
 	switch_status_t status;
 	time_t to = 0;
 	displace_helper_t *dh;
-	
-	status = switch_channel_pre_answer(channel);
+    switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
+
+
+	if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	if (!switch_channel_media_ready(channel) || !switch_core_session_get_read_codec(session)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can not displace session.  Media not enabled on channel\n");
@@ -358,24 +364,23 @@
 	}
 
 
-	read_codec = switch_core_session_get_read_codec(session);
-	switch_assert(read_codec != NULL);
-
-	dh->fh.channels = read_codec->implementation->number_of_channels;
-	dh->fh.samplerate = read_codec->implementation->actual_samples_per_second;
+	dh->fh.channels = read_impl.number_of_channels;
+	dh->fh.samplerate = read_impl.actual_samples_per_second;
 	dh->file = switch_core_session_strdup(session, file);
 
 	if (switch_core_file_open(&dh->fh,
 							  file,
-							  read_codec->implementation->number_of_channels,
-							  read_codec->implementation->actual_samples_per_second,
+							  read_impl.number_of_channels,
+							  read_impl.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_TRUE);
 		return SWITCH_STATUS_GENERR;
 	}
 
-	switch_channel_pre_answer(channel);
+	if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	if (limit) {
 		to = switch_epoch_time_now(NULL) + limit;
@@ -627,7 +632,11 @@
 
 		tlen = tread_impl.decoded_bytes_per_packet;
 
-		switch_channel_pre_answer(channel);
+
+		if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+			goto end;
+		}
+
 
 		if (switch_core_codec_init(&codec,
 								   "L16",
@@ -807,7 +816,6 @@
 SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file, uint32_t limit, switch_file_handle_t *fh)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
-	switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
 	const char *p;
 	const char *vval;
 	switch_media_bug_t *bug;
@@ -815,15 +823,19 @@
 	time_t to = 0;
 	switch_media_bug_flag_t flags = SMBF_READ_STREAM | SMBF_WRITE_STREAM;
 	uint8_t channels;
+	switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
 
-	status = switch_channel_pre_answer(channel);
+	if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	if (!switch_channel_media_ready(channel) || !switch_core_session_get_read_codec(session)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can not record session.  Media not enabled on channel\n");
 		return SWITCH_STATUS_FALSE;
 	}
 
-	channels = read_codec->implementation->number_of_channels;
+	channels = read_impl.number_of_channels;
 
 	if ((bug = switch_channel_get_private(channel, file))) {
 		return switch_ivr_stop_record_session(session, file);
@@ -845,13 +857,13 @@
 	}
 
 	fh->channels = channels;
-	fh->samplerate = read_codec->implementation->actual_samples_per_second;
+	fh->samplerate = read_impl.actual_samples_per_second;
 	fh->pre_buffer_datalen = SWITCH_DEFAULT_FILE_BUFFER_LEN;
 
 	if (switch_core_file_open(fh,
 							  file,
 							  channels,
-							  read_codec->implementation->actual_samples_per_second,
+							  read_impl.actual_samples_per_second,
 							  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);
@@ -969,22 +981,25 @@
 SWITCH_DECLARE(switch_status_t) switch_ivr_inband_dtmf_session(switch_core_session_t *session)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
-	switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
 	switch_media_bug_t *bug;
 	switch_status_t status;
 	switch_inband_dtmf_t *pvt;
+	switch_codec_implementation_t read_impl = {0};
 
-	switch_assert(read_codec != NULL);
+    switch_core_session_get_read_impl(session, &read_impl);
 
 	if (!(pvt = switch_core_session_alloc(session, sizeof(*pvt)))) {
 		return SWITCH_STATUS_MEMERR;
 	}
 
-	teletone_dtmf_detect_init(&pvt->dtmf_detect, read_codec->implementation->actual_samples_per_second);
+	teletone_dtmf_detect_init(&pvt->dtmf_detect, read_impl.actual_samples_per_second);
 
 	pvt->session = session;
 
-	switch_channel_pre_answer(channel);
+
+	if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, 0, SMBF_READ_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
 		return status;
@@ -1058,9 +1073,8 @@
 {
 	switch_inband_dtmf_generate_t *pvt = (switch_inband_dtmf_generate_t *) user_data;
 	switch_frame_t *frame;
-	switch_codec_t *read_codec;
-
-	read_codec = switch_core_session_get_read_codec(pvt->session);
+	switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(pvt->session, &read_impl);
 
 	switch (type) {
 	case SWITCH_ABC_TYPE_INIT:
@@ -1068,7 +1082,7 @@
 			switch_queue_create(&pvt->digit_queue, 100, switch_core_session_get_pool(pvt->session));
 			switch_buffer_create_dynamic(&pvt->audio_buffer, 512, 1024, 0);
 			teletone_init_session(&pvt->ts, 0, teletone_dtmf_generate_handler, pvt->audio_buffer);
-			pvt->ts.rate = read_codec->implementation->actual_samples_per_second;
+			pvt->ts.rate = read_impl.actual_samples_per_second;
 			pvt->ts.channels = 1;
 			switch_mutex_init(&pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(pvt->session));
 			switch_core_event_hook_add_recv_dtmf(pvt->session, generate_on_dtmf);
@@ -1165,7 +1179,9 @@
 	switch_status_t status;
 	switch_inband_dtmf_generate_t *pvt;
 
-	status = switch_channel_pre_answer(channel);
+	if ((status = switch_channel_pre_answer(channel)) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	if (!switch_channel_media_ready(channel) || !switch_core_session_get_read_codec(session)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can not install inband dtmf generate.  Media not enabled on channel\n");
@@ -1335,15 +1351,15 @@
 															   switch_tone_detect_callback_t callback)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
-	switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
 	switch_status_t status;
 	switch_tone_container_t *cont = switch_channel_get_private(channel, "_tone_detect_");
 	char *p, *next;
 	int i = 0, ok = 0;
 	switch_media_bug_flag_t bflags = 0;
 	const char *var;
+	switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
 
-	switch_assert(read_codec != NULL);
 
 	if (switch_strlen_zero(key)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Key Specified!\n");
@@ -1420,11 +1436,13 @@
 	cont->list[cont->index].total_hits = hits;
 
 	cont->list[cont->index].up = 1;
-	cont->list[cont->index].mt.sample_rate = read_codec->implementation->actual_samples_per_second;
+	cont->list[cont->index].mt.sample_rate = read_impl.actual_samples_per_second;
 	teletone_multi_tone_init(&cont->list[cont->index].mt, &cont->list[cont->index].map);
 	cont->session = session;
 
-	switch_channel_pre_answer(channel);
+	if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	cont->list[cont->index].default_sleep = 25;
 	cont->list[cont->index].default_expires = 250;
@@ -1959,10 +1977,11 @@
 														 const char *grammar, const char *path, const char *dest, switch_asr_handle_t *ah)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
-	switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
 	switch_status_t status;
 	switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
 	struct speech_thread_handle *sth = switch_channel_get_private(channel, SWITCH_SPEECH_KEY);
+    switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
 
 	if (!ah) {
 		if (!(ah = switch_core_session_alloc(session, sizeof(*ah)))) {
@@ -1970,8 +1989,6 @@
 		}
 	}
 
-	switch_assert(read_codec != NULL);
-
 	if ((switch_channel_get_variable(channel, "fire_asr_events"))) {
 		switch_set_flag(ah, SWITCH_ASR_FLAG_FIRE_EVENTS);
 	}
@@ -1989,7 +2006,7 @@
 	if (switch_core_asr_open(ah,
 							 mod_name,
 							 "L16",
-							 read_codec->implementation->actual_samples_per_second, dest, &flags,
+							 read_impl.actual_samples_per_second, dest, &flags,
 							 switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
 
 		if (switch_core_asr_load_grammar(ah, grammar, path) != SWITCH_STATUS_SUCCESS) {

Modified: freeswitch/trunk/src/switch_ivr_bridge.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_bridge.c	(original)
+++ freeswitch/trunk/src/switch_ivr_bridge.c	Tue Feb 10 13:09:06 2009
@@ -153,9 +153,10 @@
 	}
 
 	if ((silence_var = switch_channel_get_variable(chan_a, "bridge_generate_comfort_noise"))) {
-		switch_codec_t *read_codec = NULL;
+		switch_codec_implementation_t read_impl = {0};
+		switch_core_session_get_read_impl(session_a, &read_impl);
 		
-		if (!(read_codec = switch_core_session_get_read_codec(session_a))) {
+		if (!switch_channel_media_ready(chan_a)) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Channel has no media!\n");
 			goto end_of_bridge_loop;
 		}
@@ -172,8 +173,8 @@
 			if (switch_core_codec_init(&silence_codec,
 									   "L16",
 									   NULL, 
-									   read_codec->implementation->actual_samples_per_second, 
-									   read_codec->implementation->microseconds_per_packet / 1000,
+									   read_impl.actual_samples_per_second, 
+									   read_impl.microseconds_per_packet / 1000,
 									   1,
 									   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, 
 									   NULL, 
@@ -185,7 +186,7 @@
 				silence_frame.codec = &silence_codec;
 				silence_frame.data = silence_data;
 				silence_frame.buflen = sizeof(silence_data);
-				silence_frame.datalen = read_codec->implementation->decoded_bytes_per_packet;
+				silence_frame.datalen = read_impl.decoded_bytes_per_packet;
 				silence_frame.samples = silence_frame.datalen / sizeof(int16_t);
 			}
 		}

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	Tue Feb 10 13:09:06 2009
@@ -214,7 +214,9 @@
 		goto done;
 	}
 
-	switch_channel_pre_answer(channel);
+	if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	while (input && !done) {
 		char *pattern = (char *) switch_xml_attr(input, "pattern");
@@ -377,7 +379,7 @@
 	switch_dtmf_t dtmf = { 0 };
 	switch_file_handle_t lfh = { 0 };
 	switch_frame_t *read_frame;
-	switch_codec_t codec, *read_codec = switch_core_session_get_read_codec(session);
+	switch_codec_t codec;
 	char *codec_name;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 	const char *p;
@@ -385,17 +387,27 @@
 	time_t start = 0;
 	uint32_t org_silence_hits = 0;
 	int asis = 0;
+    switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
 
-	switch_assert(read_codec != NULL);
+	if (!switch_channel_ready(channel)) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
+	
+	if (!switch_channel_media_ready(channel)) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	if (!fh) {
 		fh = &lfh;
 	}
 
-	switch_channel_pre_answer(channel);
-
-	fh->channels = read_codec->implementation->number_of_channels;
-	fh->native_rate = read_codec->implementation->actual_samples_per_second;
+	fh->channels = read_impl.number_of_channels;
+	fh->native_rate = read_impl.actual_samples_per_second;
 
 
 
@@ -414,7 +426,7 @@
 		if ((ext = strrchr(file, '.'))) {
 			ext++;
 		} else {
-			ext = read_codec->implementation->iananame;
+			ext = read_impl.iananame;
 			file = switch_core_session_sprintf(session, "%s.%s", file, ext);
 			asis = 1;
 		}
@@ -428,7 +440,7 @@
 	if (switch_core_file_open(fh,
 							  file,
 							  fh->channels,
-							  read_codec->implementation->actual_samples_per_second,
+							  read_impl.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_TRUE);
@@ -439,7 +451,9 @@
 		asis = 1;
 	}
 
-	switch_channel_pre_answer(channel);
+	if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	if ((p = switch_channel_get_variable(channel, "RECORD_TITLE"))) {
 		vval = switch_core_session_strdup(session, p);
@@ -482,9 +496,9 @@
 		if (switch_core_codec_init(&codec,
 								   codec_name,
 								   NULL,
-								   read_codec->implementation->actual_samples_per_second,
-								   read_codec->implementation->microseconds_per_packet / 1000,
-								   read_codec->implementation->number_of_channels,
+								   read_impl.actual_samples_per_second,
+								   read_impl.microseconds_per_packet / 1000,
+								   read_impl.number_of_channels,
 								   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
 								   switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
@@ -492,7 +506,7 @@
 		} else {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
 							  "Raw Codec Activation Failed %s@%uhz %u channels %dms\n", codec_name, fh->samplerate,
-							  fh->channels, read_codec->implementation->microseconds_per_packet / 1000);
+							  fh->channels, read_impl.microseconds_per_packet / 1000);
 			switch_core_file_close(fh);
 			switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 			return SWITCH_STATUS_GENERR;
@@ -508,9 +522,9 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Can't detect silence on a native recording.\n");
 		} else {
 			if (fh->silence_hits) {
-				fh->silence_hits = fh->samplerate * fh->silence_hits / read_codec->implementation->samples_per_packet;
+				fh->silence_hits = fh->samplerate * fh->silence_hits / read_impl.samples_per_packet;
 			} else {
-				fh->silence_hits = fh->samplerate * 3 / read_codec->implementation->samples_per_packet;
+				fh->silence_hits = fh->samplerate * 3 / read_impl.samples_per_packet;
 			}
 			org_silence_hits = fh->silence_hits;
 		}
@@ -591,10 +605,10 @@
 
 			for (count = 0; count < samples; count++) {
 				energy += abs(fdata[j]);
-				j += read_codec->implementation->number_of_channels;
+				j += read_impl.number_of_channels;
 			}
 
-			if (!(divisor = read_codec->implementation->actual_samples_per_second / 8000)) {
+			if (!(divisor = read_impl.actual_samples_per_second / 8000)) {
 				divisor = 1;
 			}
 
@@ -644,19 +658,22 @@
 	switch_dtmf_t dtmf = { 0 };
 	switch_buffer_t *audio_buffer;
 	switch_frame_t *read_frame = NULL;
-	switch_codec_t *read_codec = NULL, write_codec = { 0 };
+	switch_codec_t write_codec = { 0 };
 	switch_frame_t write_frame = { 0 };
 	switch_byte_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
 	switch_channel_t *channel = switch_core_session_get_channel(session);
+	switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
 
-	switch_channel_pre_answer(channel);
-	read_codec = switch_core_session_get_read_codec(session);
+	if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	if (switch_core_codec_init(&write_codec,
 							   "L16",
 							   NULL,
-							   read_codec->implementation->actual_samples_per_second,
-							   read_codec->implementation->microseconds_per_packet / 1000,
+							   read_impl.actual_samples_per_second,
+							   read_impl.microseconds_per_packet / 1000,
 							   1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
 							   NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
 
@@ -668,7 +685,7 @@
 
 	switch_buffer_create_dynamic(&audio_buffer, 512, 1024, 0);
 	teletone_init_session(&ts, 0, teletone_handler, audio_buffer);
-	ts.rate = read_codec->implementation->actual_samples_per_second;
+	ts.rate = read_impl.actual_samples_per_second;
 	ts.channels = 1;
 	teletone_run(&ts, script);
 
@@ -736,7 +753,7 @@
 			}
 		}
 
-		if ((write_frame.datalen = (uint32_t) switch_buffer_read_loop(audio_buffer, write_frame.data, read_codec->implementation->decoded_bytes_per_packet)) <= 0) {
+		if ((write_frame.datalen = (uint32_t) switch_buffer_read_loop(audio_buffer, write_frame.data, read_impl.decoded_bytes_per_packet)) <= 0) {
 			break;
 		}
 
@@ -774,7 +791,6 @@
 	char *codec_name;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 	switch_file_handle_t lfh;
-	switch_codec_t *read_codec = NULL;
 	const char *p;
 	char *title = "", *copyright = "", *software = "", *artist = "", *comment = "", *date = "";
 	uint8_t asis = 0;
@@ -786,20 +802,22 @@
 	int eof = 0;
 	switch_size_t bread = 0;
 	int l16 = 0;
+    switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
 
-	switch_channel_pre_answer(channel);
+	if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	prefix = switch_channel_get_variable(channel, "sound_prefix");
 	timer_name = switch_channel_get_variable(channel, "timer_name");
 
-	read_codec = switch_core_session_get_read_codec(session);
-
-	if (switch_strlen_zero(file) || !read_codec || !read_codec->implementation) {
+	if (switch_strlen_zero(file) || !switch_channel_media_ready(channel)) {
 		status = SWITCH_STATUS_FALSE;
 		goto end;
 	}
 
-	if (!strcasecmp(read_codec->implementation->iananame, "l16")) {
+	if (!strcasecmp(read_impl.iananame, "l16")) {
 		l16++;
 	}
 
@@ -864,7 +882,7 @@
 		if ((ext = strrchr(file, '.'))) {
 			ext++;
 		} else {
-			ext = read_codec->implementation->iananame;
+			ext = read_impl.iananame;
 			file = switch_core_session_sprintf(session, "%s.%s", file, ext);
 			asis = 1;
 		}
@@ -889,8 +907,8 @@
 
 	if (switch_core_file_open(fh,
 							  file,
-							  read_codec->implementation->number_of_channels,
-							  read_codec->implementation->actual_samples_per_second,
+							  read_impl.number_of_channels,
+							  read_impl.actual_samples_per_second,
 							  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
 		switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 		status = SWITCH_STATUS_NOTFOUND;
@@ -940,8 +958,7 @@
 		switch_channel_set_variable(channel, "RECORD_DATE", p);
 	}
 
-	switch_assert(read_codec != NULL);
-	interval = read_codec->implementation->microseconds_per_packet / 1000;
+	interval = read_impl.microseconds_per_packet / 1000;
 
 	if (!fh->audio_buffer) {
 		switch_buffer_create_dynamic(&fh->audio_buffer, FILE_BLOCKSIZE, FILE_BUFSIZE, 0);
@@ -957,9 +974,9 @@
 	}
 
 	if (asis) {
-		write_frame.codec = read_codec;
-		samples = read_codec->implementation->samples_per_packet;
-		framelen = read_codec->implementation->encoded_bytes_per_packet;
+		write_frame.codec = switch_core_session_get_read_codec(session);
+		samples = read_impl.samples_per_packet;
+		framelen = read_impl.encoded_bytes_per_packet;
 	} else {
 		codec_name = "L16";
 
@@ -1288,7 +1305,6 @@
 	double energy = 0;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	int divisor = 0;
-	switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
 	uint32_t org_silence_hits = silence_hits;
 	uint32_t channels;
 	switch_frame_t *read_frame;
@@ -1301,18 +1317,19 @@
 	switch_frame_t write_frame = {0};
 	switch_file_handle_t fh = {0};
 	int32_t sample_count = 0;
+    switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
 
-	switch_assert(read_codec);
 
 	if (timeout_ms) {
-		sample_count = (read_codec->implementation->actual_samples_per_second / 1000) * timeout_ms;
+		sample_count = (read_impl.actual_samples_per_second / 1000) * timeout_ms;
 	}
 
 	if (file) {
 		if (switch_core_file_open(&fh,
 								  file,
-								  read_codec->implementation->number_of_channels,
-								  read_codec->implementation->actual_samples_per_second,
+								  read_impl.number_of_channels,
+								  read_impl.actual_samples_per_second,
 								  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
 			switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 			return SWITCH_STATUS_NOTFOUND;
@@ -1326,8 +1343,8 @@
 	if (switch_core_codec_init(&raw_codec,
 							   "L16",
 							   NULL,
-							   read_codec->implementation->actual_samples_per_second,
-							   read_codec->implementation->microseconds_per_packet / 1000,
+							   read_impl.actual_samples_per_second,
+							   read_impl.microseconds_per_packet / 1000,
 							   1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
 							   NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
 
@@ -1337,8 +1354,8 @@
 
 	write_frame.codec = &raw_codec;
 
-	divisor = read_codec->implementation->actual_samples_per_second / 8000;
-	channels = read_codec->implementation->number_of_channels;
+	divisor = read_impl.actual_samples_per_second / 8000;
+	channels = read_impl.number_of_channels;
 
 	switch_core_session_set_read_codec(session, &raw_codec);
 
@@ -1446,7 +1463,9 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-	switch_channel_pre_answer(channel);
+	if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	memset(digit_buffer, 0, digit_buffer_length);
 	args.buf = digit_buffer;
@@ -1572,7 +1591,9 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-	switch_channel_pre_answer(channel);
+	if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	write_frame.data = abuf;
 	write_frame.buflen = sizeof(abuf);
@@ -1843,8 +1864,12 @@
 	const char *timer_name, *var;
 	cached_speech_handle_t *cache_obj = NULL;
 	int need_create = 1, need_alloc = 1;
+    switch_codec_implementation_t read_impl = {0};
+    switch_core_session_get_read_impl(session, &read_impl);
 
-	switch_channel_pre_answer(channel);
+	if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	sh = &lsh;
 	codec = &lcodec;
@@ -1878,8 +1903,8 @@
 	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;
-	interval = read_codec->implementation->microseconds_per_packet / 1000;
+	rate = read_impl.actual_samples_per_second;
+	interval = read_impl.microseconds_per_packet / 1000;
 
 	if (need_create) {
 		memset(sh, 0, sizeof(*sh));
@@ -1897,7 +1922,9 @@
 		switch_core_speech_text_param_tts(sh, "voice", voice_name);
 	}
 
-	switch_channel_pre_answer(channel);
+	if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
+		return SWITCH_STATUS_FALSE;
+	}
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "OPEN TTS %s\n", tts_name);
 
 	codec_name = "L16";



More information about the Freeswitch-svn mailing list