[Freeswitch-svn] [commit] r10683 - freeswitch/trunk/src

FreeSWITCH SVN anthm at freeswitch.org
Tue Dec 9 10:52:17 PST 2008


Author: anthm
Date: Tue Dec  9 13:52:16 2008
New Revision: 10683

Log:
cleanup code from yesterday

Modified:
   freeswitch/trunk/src/switch_ivr_originate.c

Modified: freeswitch/trunk/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_originate.c	(original)
+++ freeswitch/trunk/src/switch_ivr_originate.c	Tue Dec  9 13:52:16 2008
@@ -356,7 +356,7 @@
 				int sval = atoi(var);
 
 				if (sval) {
-					ringback_data = switch_core_session_sprintf(session, "ringback:%d", sval);
+					ringback_data = switch_core_session_sprintf(session, "silence:%d", sval);
 				}
 			}
 		}
@@ -386,9 +386,6 @@
 				if (ringback_data) {
 					char *tmp_data = NULL;
 
-					switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
-					switch_buffer_set_loops(ringback.audio_buffer, -1);
-
 					if (switch_is_file_path(ringback_data)) {
 						char *ext;
 
@@ -429,6 +426,9 @@
 								ringback.silence = 400;
 							}
 						} else {
+							switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
+							switch_buffer_set_loops(ringback.audio_buffer, -1);
+							
 							teletone_init_session(&ringback.ts, 0, teletone_handler, &ringback);
 							ringback.ts.rate = read_codec->implementation->actual_samples_per_second;
 							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Play Ringback Tone [%s]\n", ringback_data);
@@ -800,7 +800,7 @@
 				int sval = atoi(vvar);
 
 				if (sval) {
-					ringback_data = switch_core_session_sprintf(session, "ringback:%d", sval);
+					ringback_data = switch_core_session_sprintf(session, "silence:%d", sval);
 				}
 
 			}
@@ -1296,9 +1296,7 @@
 						if (ringback_data) {
 							char *tmp_data = NULL;
 
-							switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
-							switch_buffer_set_loops(ringback.audio_buffer, -1);
-
+							
 							if (switch_is_file_path(ringback_data)) {
 								char *ext;
 
@@ -1339,6 +1337,9 @@
 									ringback.silence = 400;
 								}
 							} else {
+								switch_buffer_create_dynamic(&ringback.audio_buffer, 512, 1024, 0);
+								switch_buffer_set_loops(ringback.audio_buffer, -1);
+
 								teletone_init_session(&ringback.ts, 0, teletone_handler, &ringback);
 								ringback.ts.rate = read_codec->implementation->actual_samples_per_second;
 								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Play Ringback Tone [%s]\n", ringback_data);
@@ -1436,6 +1437,7 @@
 					 || (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)))) {
 
 					switch_status_t tstatus = SWITCH_STATUS_SUCCESS;
+					int silence = 0;
 
 					if (switch_channel_media_ready(caller_channel)) {
 						tstatus = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
@@ -1482,17 +1484,23 @@
 								break;
 							}
 						} else if (ringback.silence) {
-							write_frame.datalen = write_frame.codec->implementation->decoded_bytes_per_packet;
-							switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.datalen / 2, ringback.silence);
+							silence = ringback.silence;
 						}
-
-						if ((ringback.fh || ringback.silence || ringback.audio_buffer) && write_frame.codec && write_frame.datalen) {
-							if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) {
-								break;
-							}
+					} else {
+						silence = 400;
+					}
+					
+					if (silence) {
+						write_frame.datalen = write_frame.codec->implementation->decoded_bytes_per_packet;
+						switch_generate_sln_silence((int16_t *) write_frame.data, write_frame.datalen / 2, silence);
+					}
+					
+					if ((ringback.fh || silence || ringback.audio_buffer) && write_frame.codec && write_frame.datalen) {
+						if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) {
+							break;
 						}
 					}
-
+					
 				} else {
 					switch_yield(100000);
 				}



More information about the Freeswitch-svn mailing list