[asterisk-commits] oej: branch oej/applefrog-early-media-in-originate-1.8 r338471 - in /team/oej...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 29 07:54:12 CDT 2011


Author: oej
Date: Thu Sep 29 07:54:08 2011
New Revision: 338471

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=338471
Log:
Patch for early bridging in manager originate
--Denna och nedanstående rader kommer inte med i loggmeddelandet--

M    pbx/pbx_spool.c
M    apps/app_originate.c
M    include/asterisk/pbx.h
M    include/asterisk/channel.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.8/apps/app_originate.c
    team/oej/applefrog-early-media-in-originate-1.8/include/asterisk/channel.h
    team/oej/applefrog-early-media-in-originate-1.8/include/asterisk/pbx.h
    team/oej/applefrog-early-media-in-originate-1.8/main/channel.c
    team/oej/applefrog-early-media-in-originate-1.8/main/manager.c
    team/oej/applefrog-early-media-in-originate-1.8/main/pbx.c
    team/oej/applefrog-early-media-in-originate-1.8/pbx/pbx_spool.c
    team/oej/applefrog-early-media-in-originate-1.8/res/res_clioriginate.c

Modified: team/oej/applefrog-early-media-in-originate-1.8/apps/app_originate.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.8/apps/app_originate.c?view=diff&rev=338471&r1=338470&r2=338471
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.8/apps/app_originate.c (original)
+++ team/oej/applefrog-early-media-in-originate-1.8/apps/app_originate.c Thu Sep 29 07:54:08 2011
@@ -153,7 +153,7 @@
 
 		ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata,
 				timeout * 1000, args.arg1, exten, priority, &outgoing_status, 0, NULL,
-				NULL, NULL, NULL, NULL);
+				NULL, NULL, NULL, NULL, 0);
 	} else if (!strcasecmp(args.type, "app")) {
 		ast_debug(1, "Originating call to '%s/%s' and connecting them to %s(%s)\n",
 				chantech, chandata, args.arg1, S_OR(args.arg2, ""));

Modified: team/oej/applefrog-early-media-in-originate-1.8/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.8/include/asterisk/channel.h?view=diff&rev=338471&r1=338470&r2=338471
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.8/include/asterisk/channel.h (original)
+++ team/oej/applefrog-early-media-in-originate-1.8/include/asterisk/channel.h Thu Sep 29 07:54:08 2011
@@ -974,6 +974,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.8/include/asterisk/pbx.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.8/include/asterisk/pbx.h?view=diff&rev=338471&r1=338470&r2=338471
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.8/include/asterisk/pbx.h (original)
+++ team/oej/applefrog-early-media-in-originate-1.8/include/asterisk/pbx.h Thu Sep 29 07:54:08 2011
@@ -888,8 +888,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, format_t 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, format_t 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.8/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.8/main/channel.c?view=diff&rev=338471&r1=338470&r2=338471
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.8/main/channel.c (original)
+++ team/oej/applefrog-early-media-in-originate-1.8/main/channel.c Thu Sep 29 07:54:08 2011
@@ -5383,8 +5383,14 @@
 					timeout = 0;		/* trick to force exit from the while() */
 					break;
 
+				case AST_CONTROL_PROGRESS:
+					if (oh->connect_on_earlymedia) {
+						*outstate = f->subclass.integer;
+						timeout = 0;		/* trick to force exit from the while() */
+						break;
+					}
+					/* Fallthrough */
 				/* Ignore these */
-				case AST_CONTROL_PROGRESS:
 				case AST_CONTROL_PROCEEDING:
 				case AST_CONTROL_HOLD:
 				case AST_CONTROL_UNHOLD:

Modified: team/oej/applefrog-early-media-in-originate-1.8/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.8/main/manager.c?view=diff&rev=338471&r1=338470&r2=338471
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.8/main/manager.c (original)
+++ team/oej/applefrog-early-media-in-originate-1.8/main/manager.c Thu Sep 29 07:54:08 2011
@@ -448,6 +448,9 @@
 			</parameter>
 			<parameter name="Account">
 				<para>Account code.</para>
+			</parameter>
+			<parameter name="Earlymedia">
+				<para>Set to <literal>true</literal> to force call bridge on early media..</para>
 			</parameter>
 			<parameter name="Async">
 				<para>Set to <literal>true</literal> for fast origination.</para>
@@ -3561,6 +3564,7 @@
 	char data[512];
 	int timeout;
 	format_t format;				/*!< Codecs used for a call */
+	int earlymedia;					/*!< bridge at early media */
 	AST_DECLARE_STRING_FIELDS (
 		AST_STRING_FIELD(app);
 		AST_STRING_FIELD(appdata);
@@ -3592,7 +3596,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) {
@@ -3870,6 +3874,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;
@@ -3880,6 +3885,7 @@
 	char tmp[256];
 	char tmp2[256];
 	format_t format = AST_FORMAT_SLINEAR;
+	int bridgeearly = 0;
 
 	pthread_t th;
 	if (ast_strlen_zero(name)) {
@@ -3942,6 +3948,10 @@
 	/* 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 || ast_string_field_init(fast, 252)) {
@@ -3965,6 +3975,7 @@
 			fast->vars = vars;
 			fast->format = format;
 			fast->timeout = to;
+			fast->earlymedia = bridgeearly;
 			fast->priority = pi;
 			if (ast_pthread_create_detached(&th, NULL, fast_originate, fast)) {
 				ast_string_field_free_memory(fast);
@@ -3978,7 +3989,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.8/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.8/main/pbx.c?view=diff&rev=338471&r1=338470&r2=338471
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.8/main/pbx.c (original)
+++ team/oej/applefrog-early-media-in-originate-1.8/main/pbx.c Thu Sep 29 07:54:08 2011
@@ -8508,6 +8508,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)
@@ -8518,6 +8519,7 @@
 	int res;
 	struct ast_frame *f;
 	struct ast_app *app;
+	int haveearlymedia = 0;
 
 	while (timeout && (chan->_state != AST_STATE_UP)) {
 		res = ast_waitfor(chan, timeout);
@@ -8534,10 +8536,17 @@
 				ast_frfree(f);
 				break;
 			}
+			if (as->earlymedia && f->subclass.integer == AST_CONTROL_PROGRESS) {
+				haveearlymedia = 1;
+				break;
+			}
 		}
 		ast_frfree(f);
 	}
-	if (chan->_state == AST_STATE_UP) {
+	if (chan->_state == AST_STATE_UP || haveearlymedia) {
+		if (haveearlymedia && option_debug > 1) {
+			ast_log(LOG_DEBUG, "Activating pbx since we have early media \n");
+		}
 		if (!ast_strlen_zero(as->app)) {
 			app = pbx_findapp(as->app);
 			if (app) {
@@ -8598,12 +8607,14 @@
 	return 0;  /* success */
 }
 
-int ast_pbx_outgoing_exten(const char *type, format_t format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int synchronous, 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, format_t format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int synchronous, 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;
 	int res = -1, cdr_res = -1;
 	struct outgoing_helper oh;
+
+	oh.connect_on_earlymedia = earlymedia;
 
 	if (synchronous) {
 		oh.context = context;
@@ -8622,9 +8633,9 @@
 				ast_channel_lock(chan);
 		}
 		if (chan) {
-			if (chan->_state == AST_STATE_UP) {
-					res = 0;
-				ast_verb(4, "Channel %s was answered.\n", chan->name);
+			if (chan->_state == AST_STATE_UP || (earlymedia && *reason == AST_CONTROL_PROGRESS) ) {
+				res = 0;
+				ast_verb(4, "Channel %s was answered (or got early media).\n", chan->name);
 
 				if (synchronous > 1) {
 					if (channel)

Modified: team/oej/applefrog-early-media-in-originate-1.8/pbx/pbx_spool.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.8/pbx/pbx_spool.c?view=diff&rev=338471&r1=338470&r2=338471
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.8/pbx/pbx_spool.c (original)
+++ team/oej/applefrog-early-media-in-originate-1.8/pbx/pbx_spool.c Thu Sep 29 07:54:08 2011
@@ -346,7 +346,7 @@
 		o->vars = NULL;
 	} else {
 		ast_verb(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, (void *) 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, (void *) 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.8/res/res_clioriginate.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/applefrog-early-media-in-originate-1.8/res/res_clioriginate.c?view=diff&rev=338471&r1=338470&r2=338471
==============================================================================
--- team/oej/applefrog-early-media-in-originate-1.8/res/res_clioriginate.c (original)
+++ team/oej/applefrog-early-media-in-originate-1.8/res/res_clioriginate.c Thu Sep 29 07:54:08 2011
@@ -107,7 +107,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 CLI_SUCCESS;
 }




More information about the asterisk-commits mailing list