Revision
16313
Author
anthm
Date
2010-01-14 15:02:11 -0600 (Thu, 14 Jan 2010)

Log Message

add bridge_early_media=true variable to hear early media from first channel with early media as ringback, this is 1 way audio

Modified Paths

Diff

Modified: freeswitch/trunk/src/switch_ivr_originate.c (16312 => 16313)


--- freeswitch/trunk/src/switch_ivr_originate.c	2010-01-14 21:00:32 UTC (rev 16312)
+++ freeswitch/trunk/src/switch_ivr_originate.c	2010-01-14 21:02:11 UTC (rev 16313)
@@ -116,6 +116,7 @@
 	int continue_on_timeout;
 	int ringback_ok;
 	int sending_ringback;
+	int bridge_early_media;
 } originate_global_t;
 
 
@@ -414,6 +415,11 @@
 
 		if (switch_channel_test_flag(originate_status[i].peer_channel, CF_EARLY_MEDIA)) {
 
+			if (oglobals->ignore_early_media == 3 && oglobals->bridge_early_media == -1) {
+				oglobals->bridge_early_media = i;
+				oglobals->ringback_ok = 1;
+			}
+
 			if (oglobals->sending_ringback == 1) {
 				send_ringback++;
 				pindex = (uint32_t) i;
@@ -1018,10 +1024,6 @@
 	switch_codec_t *read_codec = NULL;
 	char *tmp_data = NULL;
 
-	if (!ringback_data) {
-		switch_goto_status(SWITCH_STATUS_GENERR, end);
-	}
-
 	if (!switch_channel_test_flag(caller_channel, CF_ANSWERED)
 		&& !switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) {
 		if ((status = switch_channel_pre_answer(caller_channel)) != SWITCH_STATUS_SUCCESS) {
@@ -1032,7 +1034,7 @@
 	}
 
 	if (oglobals->session && (read_codec = switch_core_session_get_read_codec(oglobals->session))) {
-		if (switch_is_file_path(ringback_data)) {
+		if (ringback_data && switch_is_file_path(ringback_data)) {
 			if (!(strrchr(ringback_data, '.') || strstr(ringback_data, SWITCH_URL_SEPARATOR))) {
 				ringback->asis++;
 			}
@@ -1072,6 +1074,10 @@
 		}	
 
 		oglobals->gen_ringback = 1;
+		
+		if (zstr(ringback_data)) {
+			switch_goto_status(SWITCH_STATUS_SUCCESS, end);
+		}
 
 		if (switch_is_file_path(ringback_data)) {
 			char *ext;
@@ -1579,6 +1585,7 @@
 	}
 
 	oglobals.ringback_ok = 1;
+	oglobals.bridge_early_media = -1;
 
 	if (session) {
 		const char *to_var;
@@ -1772,6 +1779,8 @@
 					ok = 1;
 				} else if (!strcasecmp((char *) hi->name, "ignore_early_media")) {
 					ok = 1;
+				} else if (!strcasecmp((char *) hi->name, "bridge_early_media")) {
+					ok = 1;
 				} else if (!strcasecmp((char *) hi->name, "originate_continue_on_timeout")) {
 					ok = 1;
 				} else if (!strcasecmp((char *) hi->name, "ignore_ring_ready")) {
@@ -1872,6 +1881,13 @@
 		*oglobals.file = '\0';
 	}
 
+	if ((var_val = switch_event_get_header(var_event, "bridge_early_media"))) {
+		if (switch_true(var_val)) {
+			oglobals.early_ok = 0;
+			oglobals.ignore_early_media = 3;
+		}
+	}
+
 	if ((var_val = switch_event_get_header(var_event, "ignore_early_media"))) {
 		if (switch_true(var_val)) {
 			oglobals.early_ok = 0;
@@ -2560,8 +2576,9 @@
 					} else {
 						read_frame = NULL;
 					}
-					
-					if (oglobals.ringback_ok && (oglobals.ring_ready || oglobals.instant_ringback || oglobals.sending_ringback > 1)) {
+
+					if (oglobals.ringback_ok && (oglobals.ring_ready || oglobals.instant_ringback || 
+												 oglobals.sending_ringback > 1 || oglobals.bridge_early_media > -1)) {
 						if (oglobals.ringback_ok == 1) {
 							switch_status_t rst = setup_ringback(&oglobals, ringback_data, &ringback, &write_frame, &write_codec);
 
@@ -2585,7 +2602,26 @@
 							continue;
 						}
 							
-						if (ringback.fh) {
+						if (oglobals.bridge_early_media > -1)  {
+							switch_channel_t *b_channel = originate_status[oglobals.bridge_early_media].peer_channel;
+							switch_core_session_t *b_session = originate_status[oglobals.bridge_early_media].peer_session;
+							switch_status_t b_status = SWITCH_STATUS_FALSE;
+							switch_frame_t *b_frame;
+							
+							if (b_channel && b_session) {
+								b_status = switch_core_session_read_frame(b_session, &b_frame, SWITCH_IO_FLAG_NONE, 0);
+							}
+							
+							if (!SWITCH_READ_ACCEPTABLE(status)) {
+								oglobals.bridge_early_media = -1;
+							} else {
+								if (switch_core_session_write_frame(oglobals.session, b_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) {
+									oglobals.bridge_early_media = -1;
+								}
+								continue;
+							}
+							
+						} else if (ringback.fh) {
 							switch_size_t mlen, olen;
 							unsigned int pos = 0;