[asterisk-commits] kmoore: branch kmoore/stasis-bridging_events r390013 - in /team/kmoore/stasis...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 29 08:03:30 CDT 2013


Author: kmoore
Date: Wed May 29 08:03:27 2013
New Revision: 390013

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390013
Log:
Now that the channel_control refactoring is in place, the Stasis-HTTP bridging code can be much less ugly

Modified:
    team/kmoore/stasis-bridging_events/res/res_stasis.c
    team/kmoore/stasis-bridging_events/res/stasis/bridge_control.c
    team/kmoore/stasis-bridging_events/res/stasis/channel_control.c
    team/kmoore/stasis-bridging_events/res/stasis/channel_control.h

Modified: team/kmoore/stasis-bridging_events/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/res_stasis.c?view=diff&rev=390013&r1=390012&r2=390013
==============================================================================
--- team/kmoore/stasis-bridging_events/res/res_stasis.c (original)
+++ team/kmoore/stasis-bridging_events/res/res_stasis.c Wed May 29 08:03:27 2013
@@ -572,12 +572,17 @@
 		RAII_VAR(struct ast_frame *, f, NULL, ast_frame_dtor);
 		int r;
 
-		if (channel_control_is_bridged(control)) {
-			r = 0;
-			usleep(MAX_WAIT_MS);
-		} else {
-			r = ast_waitfor(chan, MAX_WAIT_MS);
+		if (channel_control_pending_bridge(control)) {
+			struct ast_bridge_features features;
+			ast_bridge_features_init(&features);
+			ast_bridge_join(channel_control_pending_bridge(control),
+				channel_control_get_channel(control),
+				NULL, &features, NULL, 0);
+			ast_bridge_features_cleanup(&features);
+			channel_control_pending_bridge_clear(control);
 		}
+
+		r = ast_waitfor(chan, MAX_WAIT_MS);
 
 		if (r < 0) {
 			ast_debug(3, "%s: Poll error\n",
@@ -590,7 +595,7 @@
 			continue;
 		}
 
-		if (r == 0 || channel_control_is_bridged(control)) {
+		if (r == 0) {
 			/* Timeout */
 			continue;
 		}

Modified: team/kmoore/stasis-bridging_events/res/stasis/bridge_control.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/bridge_control.c?view=diff&rev=390013&r1=390012&r2=390013
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/bridge_control.c (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/bridge_control.c Wed May 29 08:03:27 2013
@@ -179,15 +179,6 @@
 	stasis_publish(ast_bridge_topic(control->bridge), message);
 }
 
-static int bridge_depart_cb(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, void *hook_pvt)
-{
-	RAII_VAR(struct stasis_app_channel_control *, channel_control,
-		stasis_app_channel_control_find_by_channel(bridge_channel->chan), ao2_cleanup);
-	channel_control_restore_pbx(channel_control);
-	channel_control_set_bridged(channel_control, 0);
-	return -1;
-}
-
 static void *app_bridge_control_add_channel(
 	struct stasis_app_bridge_control *control,
 	struct ast_bridge *bridge, void *data)
@@ -195,23 +186,7 @@
 	struct ast_channel *channel = data;
 	RAII_VAR(struct stasis_app_channel_control *, channel_control,
 		stasis_app_channel_control_find_by_channel(channel), ao2_cleanup);
-	int res;
-	struct ast_bridge_features *features = ast_bridge_features_new();
-	if (!features) {
-		return &FAIL;
-	}
-
-	ast_bridge_leave_hook(features, bridge_depart_cb, NULL, NULL, 1);
-	channel_control_strip_pbx(channel_control);
-
-	res = ast_bridge_impart(bridge, channel, NULL, features, 0);
-	if (res) {
-		channel_control_restore_pbx(channel_control);
-	} else {
-		channel_control_set_bridged(channel_control, 1);
-	}
-
-	return !res ? &OK : &FAIL;
+	return !channel_control_pending_bridge_set(channel_control, bridge) ? &OK : &FAIL;
 }
 
 int stasis_app_bridge_control_add_channel(
@@ -239,7 +214,7 @@
 	struct ast_bridge *bridge, void *data)
 {
 	struct ast_channel *channel = data;
-	return !ast_bridge_depart(channel) ? &OK : &FAIL;
+	return !ast_bridge_remove(bridge, channel) ? &OK : &FAIL;
 }
 
 int stasis_app_bridge_control_remove_channel(

Modified: team/kmoore/stasis-bridging_events/res/stasis/channel_control.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/channel_control.c?view=diff&rev=390013&r1=390012&r2=390013
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/channel_control.c (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/channel_control.c Wed May 29 08:03:27 2013
@@ -45,8 +45,7 @@
 	 * the channel.
 	 */
 	struct ast_channel *channel;
-	struct ast_pbx *pbx;
-	int bridged;
+	struct ast_bridge *pending_bridge;
 };
 
 struct stasis_app_channel_control *channel_control_create(struct ast_channel *channel)
@@ -180,30 +179,23 @@
 	return ast_queue_control(control->channel, frame_type);
 }
 
-void channel_control_set_bridged(struct stasis_app_channel_control *control, int bridged)
-{
-	control->bridged = bridged;
-}
-
-int channel_control_is_bridged(struct stasis_app_channel_control *control)
-{
-	return control->bridged;
-}
-
-void channel_control_strip_pbx(struct stasis_app_channel_control *control)
-{
-	ast_channel_lock(control->channel);
-	control->pbx = ast_channel_pbx(control->channel);
-	ast_channel_pbx_set(control->channel, NULL);
-	ast_channel_unlock(control->channel);
-}
-
-void channel_control_restore_pbx(struct stasis_app_channel_control *control)
-{
-	ast_channel_lock(control->channel);
-	ast_channel_pbx_set(control->channel, control->pbx);
-	ast_channel_unlock(control->channel);
-	control->pbx = NULL;
+struct ast_bridge *channel_control_pending_bridge(struct stasis_app_channel_control *control)
+{
+	return control->pending_bridge;
+}
+
+int channel_control_pending_bridge_set(struct stasis_app_channel_control *control, struct ast_bridge *bridge)
+{
+	if (control->pending_bridge) {
+		return -1;
+	}
+	control->pending_bridge = bridge;
+	return 0;
+}
+
+void channel_control_pending_bridge_clear(struct stasis_app_channel_control *control)
+{
+	control->pending_bridge = NULL;
 }
 
 struct ast_channel *channel_control_get_channel(struct stasis_app_channel_control *control)

Modified: team/kmoore/stasis-bridging_events/res/stasis/channel_control.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/channel_control.h?view=diff&rev=390013&r1=390012&r2=390013
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/channel_control.h (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/channel_control.h Wed May 29 08:03:27 2013
@@ -42,10 +42,10 @@
 
 void channel_control_continue(struct stasis_app_channel_control *control);
 
-int channel_control_is_bridged(struct stasis_app_channel_control *control);
-void channel_control_restore_pbx(struct stasis_app_channel_control *control);
-void channel_control_strip_pbx(struct stasis_app_channel_control *control);
-void channel_control_set_bridged(struct stasis_app_channel_control *control, int bridged);
+struct ast_bridge;
+struct ast_bridge *channel_control_pending_bridge(struct stasis_app_channel_control *control);
+int channel_control_pending_bridge_set(struct stasis_app_channel_control *control, struct ast_bridge *bridge);
+void channel_control_pending_bridge_clear(struct stasis_app_channel_control *control);
 struct ast_channel *channel_control_get_channel(struct stasis_app_channel_control *control);
 
 #endif /* _ASTERISK_RES_STASIS_CONTROL_H */




More information about the asterisk-commits mailing list