[svn-commits] oej: branch oej/applefrog-early-media-in-originate-1.4 r316090 - in /team/oej...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon May 2 13:36:36 CDT 2011


Author: oej
Date: Mon May  2 13:36:23 2011
New Revision: 316090

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=316090
Log:
Originate now has an extra option, called Earlymedia = yes |no

If it is turned on, the call will be bridged as soon as we have early media
instead of ignoring it while waiting for an answer.

--Denna och nedanstående rader kommer inte med i loggmeddelandet--

M    pbx/pbx_spool.c
M    include/asterisk/channel.h
M    include/asterisk/pbx.h
M    main/channel.c
M    main/manager.c
M    main/pbx.c
M    res/res_clioriginate.c

Modified:
    team/oej/applefrog-early-media-in-originate-1.4/include/asterisk/channel.h
    team/oej/applefrog-early-media-in-originate-1.4/include/asterisk/pbx.h
    team/oej/applefrog-early-media-in-originate-1.4/main/channel.c
    team/oej/applefrog-early-media-in-originate-1.4/main/manager.c
    team/oej/applefrog-early-media-in-originate-1.4/main/pbx.c
    team/oej/applefrog-early-media-in-originate-1.4/pbx/pbx_spool.c
    team/oej/applefrog-early-media-in-originate-1.4/res/res_clioriginate.c

Modified: team/oej/applefrog-early-media-in-originate-1.4/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.4/include/asterisk/channel.h?view=diff&rev=316090&r1=316089&r2=316090
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.4/include/asterisk/channel.h (original)
+++ team/oej/applefrog-early-media-in-originate-1.4/include/asterisk/channel.h Mon May  2 13:36:23 2011
@@ -593,6 +593,7 @@
 	const char *context;
 	const char *exten;
 	int priority;
+	int connect_on_earlymedia;	/* If set, treat session progress as answer */
 	const char *cid_num;
 	const char *cid_name;
 	const char *account;

Modified: team/oej/applefrog-early-media-in-originate-1.4/include/asterisk/pbx.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.4/include/asterisk/pbx.h?view=diff&rev=316090&r1=316089&r2=316090
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.4/include/asterisk/pbx.h (original)
+++ team/oej/applefrog-early-media-in-originate-1.4/include/asterisk/pbx.h Mon May  2 13:36:23 2011
@@ -753,8 +753,10 @@
 int ast_async_goto_by_name(const char *chan, const char *context, const char *exten, int priority);
 
 /*! Synchronously or asynchronously make an outbound call and send it to a
-   particular extension */
-int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel);
+   particular extension 
+	\param earlymedia 1 = Set up the bridge if we get earlymedia
+*/
+int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel, const int earlymedia);
 
 /*! Synchronously or asynchronously make an outbound call and send it to a
    particular application with given extension */

Modified: team/oej/applefrog-early-media-in-originate-1.4/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.4/main/channel.c?view=diff&rev=316090&r1=316089&r2=316090
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.4/main/channel.c (original)
+++ team/oej/applefrog-early-media-in-originate-1.4/main/channel.c Mon May  2 13:36:23 2011
@@ -3673,6 +3673,13 @@
 
 				/* Ignore these */
 				case AST_CONTROL_PROGRESS:
+					if (oh->connect_on_earlymedia) {
+						ast_log(LOG_DEBUG, " --->>> AST_CONTROL_PROGRESS here!\n");
+						*outstate = f->subclass;
+						timeout = 0;		/* trick to force exit from the while() */
+						break;
+					}
+					/* Fallthrough */
 				case AST_CONTROL_PROCEEDING:
 				case AST_CONTROL_HOLD:
 				case AST_CONTROL_UNHOLD:

Modified: team/oej/applefrog-early-media-in-originate-1.4/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.4/main/manager.c?view=diff&rev=316090&r1=316089&r2=316090
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.4/main/manager.c (original)
+++ team/oej/applefrog-early-media-in-originate-1.4/main/manager.c Mon May  2 13:36:23 2011
@@ -78,6 +78,7 @@
 	char data[512];
 	int timeout;
 	int format;
+	int earlymedia;
 	char app[AST_MAX_APP];
 	char appdata[AST_MAX_EXTENSION];
 	char cid_name[AST_MAX_EXTENSION];
@@ -1894,6 +1895,7 @@
 	int reason = 0;
 	struct ast_channel *chan = NULL;
 	char requested_channel[AST_CHANNEL_NAME];
+	ast_log(LOG_DEBUG, "-----> Earlymedia: %s\n", in->earlymedia ? "On" : "off");
 
 	if (!ast_strlen_zero(in->app)) {
 		res = ast_pbx_outgoing_app(in->tech, in->format, in->data, in->timeout, in->app, in->appdata, &reason, 1, 
@@ -1904,7 +1906,7 @@
 		res = ast_pbx_outgoing_exten(in->tech, in->format, in->data, in->timeout, in->context, in->exten, in->priority, &reason, 1, 
 			S_OR(in->cid_num, NULL), 
 			S_OR(in->cid_name, NULL),
-			in->vars, in->account, &chan);
+			in->vars, in->account, &chan, in->earlymedia);
 	}
 
 	if (!chan)
@@ -1951,6 +1953,7 @@
 "	Variable: Channel variable to set, multiple Variable: headers are allowed\n"
 "	Codecs: Comma-separated list of codecs to use for the new channels\n"
 "	Account: Account code\n"
+"	Earlymedia: Set to 'true' to force bridge on early media (only works in async mode)\n"
 "	Async: Set to 'true' for fast origination\n";
 
 static int action_originate(struct mansession *s, const struct message *m)
@@ -1967,6 +1970,7 @@
 	const char *async = astman_get_header(m, "Async");
 	const char *id = astman_get_header(m, "ActionID");
 	const char *codecs = astman_get_header(m, "Codecs");
+	const char *earlymedia = astman_get_header(m, "Earlymedia");
 	struct ast_variable *vars;
 	char *tech, *data;
 	char *l = NULL, *n = NULL;
@@ -1977,6 +1981,7 @@
 	char tmp[256];
 	char tmp2[256];
 	int format = AST_FORMAT_SLINEAR;
+	int bridgeearly = 0;
 	
 	pthread_t th;
 	pthread_attr_t attr;
@@ -2020,11 +2025,20 @@
 	/* Allocate requested channel variables */
 	vars = astman_get_variables(m);
 
+	/* For originate async - we can bridge in early media stage */
+	bridgeearly = ast_true(earlymedia);
+	
+
 	if (ast_true(async)) {
 		struct fast_originate_helper *fast = ast_calloc(1, sizeof(*fast));
+
 		if (!fast) {
 			res = -1;
 		} else {
+			if (option_debug) {
+				ast_log(LOG_DEBUG, "-----> Early media: %s\n", bridgeearly ? "on" : "off");
+			}
+
 			if (!ast_strlen_zero(id))
 				snprintf(fast->idtext, sizeof(fast->idtext), "ActionID: %s", id);
 			ast_copy_string(fast->tech, tech, sizeof(fast->tech));
@@ -2041,6 +2055,7 @@
 			ast_copy_string(fast->account, account, sizeof(fast->account));
 			fast->format = format;
 			fast->timeout = to;
+			fast->earlymedia = bridgeearly;
 			fast->priority = pi;
 			pthread_attr_init(&attr);
 			pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
@@ -2056,7 +2071,7 @@
         	res = ast_pbx_outgoing_app(tech, format, data, to, app, appdata, &reason, 1, l, n, vars, account, NULL);
     	} else {
 		if (exten && context && pi)
-	        	res = ast_pbx_outgoing_exten(tech, format, data, to, context, exten, pi, &reason, 1, l, n, vars, account, NULL);
+	        	res = ast_pbx_outgoing_exten(tech, format, data, to, context, exten, pi, &reason, 1, l, n, vars, account, NULL, bridgeearly);
 		else {
 			astman_send_error(s, m, "Originate with 'Exten' requires 'Context' and 'Priority'");
 			if (vars) {

Modified: team/oej/applefrog-early-media-in-originate-1.4/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.4/main/pbx.c?view=diff&rev=316090&r1=316089&r2=316090
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.4/main/pbx.c (original)
+++ team/oej/applefrog-early-media-in-originate-1.4/main/pbx.c Mon May  2 13:36:23 2011
@@ -5018,6 +5018,7 @@
 	int timeout;
 	char app[AST_MAX_EXTENSION];
 	char appdata[1024];
+	int earlymedia;			/* Connect the bridge if early media arrives, don't wait for answer */
 };
 
 static void *async_wait(void *data)
@@ -5028,6 +5029,12 @@
 	int res;
 	struct ast_frame *f;
 	struct ast_app *app;
+	int haveearlymedia = 0;
+	int checkearlymedia = as->earlymedia;
+
+	if (option_debug) {
+		ast_log(LOG_DEBUG, "----> Checkearlymedia %s\n", checkearlymedia ? "on" : "Off");
+	}
 
 	while (timeout && (chan->_state != AST_STATE_UP)) {
 		res = ast_waitfor(chan, timeout);
@@ -5044,10 +5051,17 @@
 				ast_frfree(f);
 				break;
 			}
+			if (as->earlymedia && f->subclass == AST_CONTROL_PROGRESS && checkearlymedia) {
+				haveearlymedia = 1;
+				break;
+			}
 		}
 		ast_frfree(f);
 	}
-	if (chan->_state == AST_STATE_UP) {
+	if (chan->_state == AST_STATE_UP || haveearlymedia) {
+		if (haveearlymedia && option_debug) {
+			ast_log(LOG_DEBUG, "----> Launching second call leg, since we have early media \n");
+		}
 		if (!ast_strlen_zero(as->app)) {
 			app = pbx_findapp(as->app);
 			if (app) {
@@ -5109,7 +5123,7 @@
 	return 0;  /* success */
 }
 
-int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **channel)
+int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **channel, const int earlymedia)
 {
 	struct ast_channel *chan;
 	struct async_stat *as;
@@ -5117,7 +5131,12 @@
 	struct outgoing_helper oh;
 	pthread_attr_t attr;
 
+
+	ast_log(LOG_DEBUG, "-----> Earlymedia: %s\n", earlymedia ? "On" : "off");
+	oh.connect_on_earlymedia = earlymedia;
+
 	if (sync) {
+		ast_log(LOG_DEBUG, "-----> Sync originate \n");
 		LOAD_OH(oh);
 		chan = __ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name, &oh);
 		if (channel) {
@@ -5126,10 +5145,13 @@
 				ast_channel_lock(chan);
 		}
 		if (chan) {
-			if (chan->_state == AST_STATE_UP) {
-					res = 0;
+			if (earlymedia && *reason == AST_CONTROL_PROGRESS) {
+				ast_log(LOG_DEBUG, "-----> Sync originate: Yes, we have early media \n");
+			}
+			if (chan->_state == AST_STATE_UP || (earlymedia && *reason == AST_CONTROL_PROGRESS)) {
+				res = 0;
 				if (option_verbose > 3)
-					ast_verbose(VERBOSE_PREFIX_4 "Channel %s was answered.\n", chan->name);
+					ast_verbose(VERBOSE_PREFIX_4 "Channel %s was answered or got early media.\n", chan->name);
 
 				if (sync > 1) {
 					if (channel)
@@ -5156,7 +5178,7 @@
 				}
 			} else {
 				if (option_verbose > 3)
-					ast_verbose(VERBOSE_PREFIX_4 "Channel %s was never answered.\n", chan->name);
+					ast_verbose(VERBOSE_PREFIX_4 "Oh no. Channel %s was never answered.\n", chan->name);
 
 				if (chan->cdr) { /* update the cdr */
 					/* here we update the status of the call, which sould be busy.
@@ -5207,10 +5229,12 @@
 			}
 		}
 	} else {
+		ast_log(LOG_DEBUG, "-----> Async originate \n");
 		if (!(as = ast_calloc(1, sizeof(*as)))) {
 			res = -1;
 			goto outgoing_exten_cleanup;
 		}
+
 		chan = ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name);
 		if (channel) {
 			*channel = chan;
@@ -5218,6 +5242,7 @@
 				ast_channel_lock(chan);
 		}
 		if (!chan) {
+			ast_log(LOG_DEBUG, "-----> Failure: Async originate \n");
 			free(as);
 			res = -1;
 			goto outgoing_exten_cleanup;

Modified: team/oej/applefrog-early-media-in-originate-1.4/pbx/pbx_spool.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.4/pbx/pbx_spool.c?view=diff&rev=316090&r1=316089&r2=316090
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.4/pbx/pbx_spool.c (original)
+++ team/oej/applefrog-early-media-in-originate-1.4/pbx/pbx_spool.c Mon May  2 13:36:23 2011
@@ -353,7 +353,7 @@
 	} else {
 		if (option_verbose > 2)
 			ast_verbose(VERBOSE_PREFIX_3 "Attempting call on %s/%s for %s@%s:%d (Retry %d)\n", o->tech, o->dest, o->exten, o->context,o->priority, o->retries);
-		res = ast_pbx_outgoing_exten(o->tech, o->format, o->dest, o->waittime * 1000, o->context, o->exten, o->priority, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, o->account, NULL);
+		res = ast_pbx_outgoing_exten(o->tech, o->format, o->dest, o->waittime * 1000, o->context, o->exten, o->priority, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, o->account, NULL, 0);
 	}
 	o->vars = NULL;
 	if (res) {

Modified: team/oej/applefrog-early-media-in-originate-1.4/res/res_clioriginate.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.4/res/res_clioriginate.c?view=diff&rev=316090&r1=316089&r2=316090
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.4/res/res_clioriginate.c (original)
+++ team/oej/applefrog-early-media-in-originate-1.4/res/res_clioriginate.c Mon May  2 13:36:23 2011
@@ -117,7 +117,7 @@
 	if (ast_strlen_zero(context))
 		context = "default";
 	
-	ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 0, NULL, NULL, NULL, NULL, NULL);
+	ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 0, NULL, NULL, NULL, NULL, NULL, 0);
 
 	return RESULT_SUCCESS;
 }




More information about the svn-commits mailing list