[asterisk-commits] file: branch group/bridge_construction r388316 - in /team/group/bridge_constr...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 10 10:26:51 CDT 2013


Author: file
Date: Fri May 10 10:26:40 2013
New Revision: 388316

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=388316
Log:
Add support for native bridging RTP capable channels within the new bridging work.

Review: https://reviewboard.asterisk.org/r/2465/

(closes issue ASTERISK-20869)

Added:
    team/group/bridge_construction/bridges/bridge_native_rtp.c   (with props)
Modified:
    team/group/bridge_construction/apps/app_chanspy.c
    team/group/bridge_construction/apps/app_mixmonitor.c
    team/group/bridge_construction/channels/chan_gulp.c
    team/group/bridge_construction/channels/chan_h323.c
    team/group/bridge_construction/channels/chan_jingle.c
    team/group/bridge_construction/channels/chan_mgcp.c
    team/group/bridge_construction/channels/chan_motif.c
    team/group/bridge_construction/channels/chan_sip.c
    team/group/bridge_construction/channels/chan_skinny.c
    team/group/bridge_construction/channels/chan_unistim.c
    team/group/bridge_construction/include/asterisk/rtp_engine.h
    team/group/bridge_construction/main/bridging.c
    team/group/bridge_construction/main/rtp_engine.c

Modified: team/group/bridge_construction/apps/app_chanspy.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/apps/app_chanspy.c?view=diff&rev=388316&r1=388315&r2=388316
==============================================================================
--- team/group/bridge_construction/apps/app_chanspy.c (original)
+++ team/group/bridge_construction/apps/app_chanspy.c Fri May 10 10:26:40 2013
@@ -482,15 +482,18 @@
 static int start_spying(struct ast_autochan *autochan, const char *spychan_name, struct ast_audiohook *audiohook)
 {
 	int res = 0;
-	struct ast_channel *peer = NULL;
 
 	ast_log(LOG_NOTICE, "Attaching %s to %s\n", spychan_name, ast_channel_name(autochan->chan));
 
 	ast_set_flag(audiohook, AST_AUDIOHOOK_TRIGGER_SYNC | AST_AUDIOHOOK_SMALL_QUEUE);
 	res = ast_audiohook_attach(autochan->chan, audiohook);
 
-	if (!res && ast_test_flag(ast_channel_flags(autochan->chan), AST_FLAG_NBRIDGE) && (peer = ast_bridged_channel(autochan->chan))) {
-		ast_softhangup(peer, AST_SOFTHANGUP_UNBRIDGE);
+	if (!res) {
+		ast_channel_lock(autochan->chan);
+		if (ast_channel_is_bridged(autochan->chan)) {
+			ast_softhangup_nolock(autochan->chan, AST_SOFTHANGUP_UNBRIDGE);
+		}
+		ast_channel_unlock(autochan->chan);
 	}
 	return res;
 }

Modified: team/group/bridge_construction/apps/app_mixmonitor.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/apps/app_mixmonitor.c?view=diff&rev=388316&r1=388315&r2=388316
==============================================================================
--- team/group/bridge_construction/apps/app_mixmonitor.c (original)
+++ team/group/bridge_construction/apps/app_mixmonitor.c Fri May 10 10:26:40 2013
@@ -411,7 +411,6 @@
 
 static int startmon(struct ast_channel *chan, struct ast_audiohook *audiohook) 
 {
-	struct ast_channel *peer = NULL;
 	int res = 0;
 
 	if (!chan)
@@ -419,8 +418,13 @@
 
 	ast_audiohook_attach(chan, audiohook);
 
-	if (!res && ast_test_flag(ast_channel_flags(chan), AST_FLAG_NBRIDGE) && (peer = ast_bridged_channel(chan)))
-		ast_softhangup(peer, AST_SOFTHANGUP_UNBRIDGE);	
+	if (!res) {
+		ast_channel_lock(chan);
+		if (ast_channel_is_bridged(chan)) {
+			ast_softhangup_nolock(chan, AST_SOFTHANGUP_UNBRIDGE);
+		}
+		ast_channel_unlock(chan);
+	}
 
 	return res;
 }

Added: team/group/bridge_construction/bridges/bridge_native_rtp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/bridges/bridge_native_rtp.c?view=auto&rev=388316
==============================================================================
--- team/group/bridge_construction/bridges/bridge_native_rtp.c (added)
+++ team/group/bridge_construction/bridges/bridge_native_rtp.c Fri May 10 10:26:40 2013
@@ -1,0 +1,414 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Joshua Colp <jcolp at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Native RTP bridging module
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ *
+ * \ingroup bridges
+ */
+
+/*** MODULEINFO
+	<support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "asterisk/module.h"
+#include "asterisk/channel.h"
+#include "asterisk/bridging.h"
+#include "asterisk/bridging_technology.h"
+#include "asterisk/frame.h"
+#include "asterisk/rtp_engine.h"
+#include "asterisk/audiohook.h"
+
+/*! \brief Forward declarations for frame hook usage */
+static int native_rtp_bridge_join(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
+static void native_rtp_bridge_leave(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
+
+/*! \brief Internal structure which contains information about bridged RTP channels */
+struct native_rtp_bridge_data {
+	/*! \brief Framehook used to intercept certain control frames */
+	int id;
+};
+
+/*! \brief Frame hook that is called to intercept hold/unhold */
+static struct ast_frame *native_rtp_framehook(struct ast_channel *chan, struct ast_frame *f, enum ast_framehook_event event, void *data)
+{
+	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+
+	if (!f || (event != AST_FRAMEHOOK_EVENT_WRITE)) {
+		return f;
+	}
+
+	ast_channel_lock(chan);
+	bridge = ast_channel_get_bridge(chan);
+	ast_channel_unlock(chan);
+
+	/* It's safe for NULL to be passed to both of these, bridge_channel isn't used at all */
+	if (bridge) {
+		if (f->subclass.integer == AST_CONTROL_HOLD) {
+			native_rtp_bridge_leave(ast_channel_internal_bridge(chan), NULL);
+		} else if ((f->subclass.integer == AST_CONTROL_UNHOLD) || (f->subclass.integer == AST_CONTROL_UPDATE_RTP_PEER)) {
+			native_rtp_bridge_join(ast_channel_internal_bridge(chan), NULL);
+		}
+	}
+
+	return f;
+}
+
+/*! \brief Internal helper function which checks whether the channels are compatible with our native bridging */
+static int native_rtp_bridge_capable(struct ast_channel *chan)
+{
+	if (ast_channel_monitor(chan) || (ast_channel_audiohooks(chan) &&
+		!ast_audiohook_write_list_empty(ast_channel_audiohooks(chan))) ||
+		!ast_framehook_list_is_empty(ast_channel_framehooks(chan))) {
+		return 0;
+	} else {
+		return 1;
+	}
+}
+
+/*! \brief Internal helper function which gets all RTP information (glue and instances) relating to the given channels */
+static enum ast_rtp_glue_result native_rtp_bridge_get(struct ast_channel *c0, struct ast_channel *c1, struct ast_rtp_glue **glue0,
+	struct ast_rtp_glue **glue1, struct ast_rtp_instance **instance0, struct ast_rtp_instance **instance1,
+	struct ast_rtp_instance **vinstance0, struct ast_rtp_instance **vinstance1)
+{
+	enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
+	enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
+
+	if (!(*glue0 = ast_rtp_instance_get_glue(ast_channel_tech(c0)->type)) ||
+		(c1 && !(*glue1 = ast_rtp_instance_get_glue(ast_channel_tech(c1)->type)))) {
+		return AST_RTP_GLUE_RESULT_FORBID;
+	}
+
+	audio_glue0_res = (*glue0)->get_rtp_info(c0, instance0);
+	video_glue0_res = (*glue0)->get_vrtp_info ? (*glue0)->get_vrtp_info(c0, vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
+
+	if (c1) {
+		audio_glue1_res = (*glue1)->get_rtp_info(c1, instance1);
+		video_glue1_res = (*glue1)->get_vrtp_info ? (*glue1)->get_vrtp_info(c1, vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
+	}
+
+	/* Apply any limitations on direct media bridging that may be present */
+	if (audio_glue0_res == audio_glue1_res && audio_glue1_res == AST_RTP_GLUE_RESULT_REMOTE) {
+		if ((*glue0)->allow_rtp_remote && !((*glue0)->allow_rtp_remote(c0, *instance1))) {
+			/* If the allow_rtp_remote indicates that remote isn't allowed, revert to local bridge */
+			audio_glue0_res = audio_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
+		} else if ((*glue1)->allow_rtp_remote && !((*glue1)->allow_rtp_remote(c1, *instance0))) {
+			audio_glue0_res = audio_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
+		}
+	}
+	if (c1 && video_glue0_res == video_glue1_res && video_glue1_res == AST_RTP_GLUE_RESULT_REMOTE) {
+		if ((*glue0)->allow_vrtp_remote && !((*glue0)->allow_vrtp_remote(c0, *instance1))) {
+			/* if the allow_vrtp_remote indicates that remote isn't allowed, revert to local bridge */
+			video_glue0_res = video_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
+		} else if ((*glue1)->allow_vrtp_remote && !((*glue1)->allow_vrtp_remote(c1, *instance0))) {
+			video_glue0_res = video_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
+		}
+	}
+
+	/* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
+	if (video_glue0_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue0_res != AST_RTP_GLUE_RESULT_REMOTE)) {
+		audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
+	}
+	if (c1 && video_glue1_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue1_res != AST_RTP_GLUE_RESULT_REMOTE)) {
+		audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
+	}
+
+	/* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
+	if (audio_glue0_res == AST_RTP_GLUE_RESULT_FORBID || (c1 && audio_glue1_res == AST_RTP_GLUE_RESULT_FORBID)) {
+		return AST_RTP_GLUE_RESULT_FORBID;
+	}
+
+	return audio_glue0_res;
+}
+
+static int native_rtp_bridge_compatible(struct ast_bridge *bridge)
+{
+	struct ast_bridge_channel *c0 = AST_LIST_FIRST(&bridge->channels);
+	struct ast_bridge_channel *c1 = AST_LIST_LAST(&bridge->channels);
+	enum ast_rtp_glue_result native_type;
+	struct ast_rtp_glue *glue0, *glue1;
+	struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL, *vinstance0 = NULL, *vinstance1 = NULL;
+	RAII_VAR(struct ast_format_cap *, cap0, ast_format_cap_alloc_nolock(), ast_format_cap_destroy);
+	RAII_VAR(struct ast_format_cap *, cap1, ast_format_cap_alloc_nolock(), ast_format_cap_destroy);
+	int read_ptime0, read_ptime1, write_ptime0, write_ptime1;
+
+	/* We require two channels before even considering native bridging */
+	if (bridge->num_channels != 2) {
+		ast_debug(1, "Bridge '%s' can not use native RTP bridge as two channels are required\n",
+			bridge->uniqueid);
+		return 0;
+	}
+
+	if (!native_rtp_bridge_capable(c0->chan)) {
+		ast_debug(1, "Bridge '%s' can not use native RTP bridge as channel '%s' has features which prevent it\n",
+			bridge->uniqueid, ast_channel_name(c0->chan));
+		return 0;
+	}
+
+	if (!native_rtp_bridge_capable(c1->chan)) {
+		ast_debug(1, "Bridge '%s' can not use native RTP bridge as channel '%s' has features which prevent it\n",
+			bridge->uniqueid, ast_channel_name(c1->chan));
+		return 0;
+	}
+
+	if ((native_type = native_rtp_bridge_get(c0->chan, c1->chan, &glue0, &glue1, &instance0, &instance1, &vinstance0, &vinstance1))
+		== AST_RTP_GLUE_RESULT_FORBID) {
+		ast_debug(1, "Bridge '%s' can not use native RTP bridge as it was forbidden while getting details\n",
+			bridge->uniqueid);
+		return 0;
+	}
+
+	if (ao2_container_count(c0->features->dtmf_hooks) && ast_rtp_instance_dtmf_mode_get(instance0)) {
+		ast_debug(1, "Bridge '%s' can not use native RTP bridge as channel '%s' has DTMF hooks\n",
+			bridge->uniqueid, ast_channel_name(c0->chan));
+		return 0;
+	}
+
+	if (ao2_container_count(c1->features->dtmf_hooks) && ast_rtp_instance_dtmf_mode_get(instance1)) {
+		ast_debug(1, "Bridge '%s' can not use native RTP bridge as channel '%s' has DTMF hooks\n",
+			bridge->uniqueid, ast_channel_name(c1->chan));
+		return 0;
+	}
+
+	if ((native_type == AST_RTP_GLUE_RESULT_LOCAL) && ((ast_rtp_instance_get_engine(instance0)->local_bridge !=
+		ast_rtp_instance_get_engine(instance1)->local_bridge) ||
+		(ast_rtp_instance_get_engine(instance0)->dtmf_compatible &&
+			!ast_rtp_instance_get_engine(instance0)->dtmf_compatible(c0->chan, instance0, c1->chan, instance1)))) {
+		ast_debug(1, "Bridge '%s' can not use local native RTP bridge as local bridge or DTMF is not compatible\n",
+			bridge->uniqueid);
+		return 0;
+	}
+
+	/* Make sure that codecs match */
+	if (glue0->get_codec) {
+		glue0->get_codec(c0->chan, cap0);
+	}
+	if (glue1->get_codec) {
+		glue1->get_codec(c1->chan, cap1);
+	}
+	if (!ast_format_cap_is_empty(cap0) && !ast_format_cap_is_empty(cap1) && !ast_format_cap_has_joint(cap0, cap1)) {
+		char tmp0[256] = { 0, }, tmp1[256] = { 0, };
+
+		ast_debug(1, "Channel codec0 = %s is not codec1 = %s, cannot native bridge in RTP.\n",
+			ast_getformatname_multiple(tmp0, sizeof(tmp0), cap0),
+			ast_getformatname_multiple(tmp1, sizeof(tmp1), cap1));
+		return 0;
+	}
+
+	read_ptime0 = (ast_codec_pref_getsize(&ast_rtp_instance_get_codecs(instance0)->pref, ast_channel_rawreadformat(c0->chan))).cur_ms;
+	read_ptime1 = (ast_codec_pref_getsize(&ast_rtp_instance_get_codecs(instance1)->pref, ast_channel_rawreadformat(c1->chan))).cur_ms;
+	write_ptime0 = (ast_codec_pref_getsize(&ast_rtp_instance_get_codecs(instance0)->pref, ast_channel_rawwriteformat(c0->chan))).cur_ms;
+	write_ptime1 = (ast_codec_pref_getsize(&ast_rtp_instance_get_codecs(instance1)->pref, ast_channel_rawwriteformat(c1->chan))).cur_ms;
+
+	if (read_ptime0 != write_ptime1 || read_ptime1 != write_ptime0) {
+		ast_debug(1, "Packetization differs between RTP streams (%d != %d or %d != %d). Cannot native bridge in RTP\n",
+				read_ptime0, write_ptime1, read_ptime1, write_ptime0);
+		return 0;
+	}
+
+	return 1;
+}
+
+/*! \brief Helper function which adds frame hook to bridge channel */
+static int native_rtp_bridge_framehook_attach(struct ast_bridge_channel *bridge_channel)
+{
+	struct native_rtp_bridge_data *data = ao2_alloc(sizeof(*data), NULL);
+	static struct ast_framehook_interface hook = {
+		.version = AST_FRAMEHOOK_INTERFACE_VERSION,
+		.event_cb = native_rtp_framehook,
+	};
+
+	if (!data) {
+		return -1;
+	}
+
+	ast_channel_lock(bridge_channel->chan);
+
+	if (!(data->id = ast_framehook_attach(bridge_channel->chan, &hook)) < 0) {
+		ast_channel_unlock(bridge_channel->chan);
+		ao2_cleanup(data);
+		return -1;
+	}
+
+	ast_channel_unlock(bridge_channel->chan);
+
+	bridge_channel->bridge_pvt = data;
+
+	return 0;
+}
+
+/*! \brief Helper function which removes frame hook from bridge channel */
+static void native_rtp_bridge_framehook_detach(struct ast_bridge_channel *bridge_channel)
+{
+	RAII_VAR(struct native_rtp_bridge_data *, data, bridge_channel->bridge_pvt, ao2_cleanup);
+
+	if (!data) {
+		return;
+	}
+
+	ast_channel_lock(bridge_channel->chan);
+	ast_framehook_detach(bridge_channel->chan, data->id);
+	ast_channel_unlock(bridge_channel->chan);
+	bridge_channel->bridge_pvt = NULL;
+}
+
+static int native_rtp_bridge_join(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
+{
+	struct ast_bridge_channel *c0 = AST_LIST_FIRST(&bridge->channels);
+	struct ast_bridge_channel *c1 = AST_LIST_LAST(&bridge->channels);
+	enum ast_rtp_glue_result native_type;
+	struct ast_rtp_glue *glue0, *glue1;
+	struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL, *vinstance0 = NULL;
+	struct ast_rtp_instance *vinstance1 = NULL, *tinstance0 = NULL, *tinstance1 = NULL;
+	RAII_VAR(struct ast_format_cap *, cap0, ast_format_cap_alloc_nolock(), ast_format_cap_destroy);
+	RAII_VAR(struct ast_format_cap *, cap1, ast_format_cap_alloc_nolock(), ast_format_cap_destroy);
+
+	native_rtp_bridge_framehook_detach(c0);
+	if (native_rtp_bridge_framehook_attach(c0)) {
+		return -1;
+	}
+
+	native_rtp_bridge_framehook_detach(c1);
+	if (native_rtp_bridge_framehook_attach(c1)) {
+		native_rtp_bridge_framehook_detach(c0);
+		return -1;
+	}
+
+	native_type = native_rtp_bridge_get(c0->chan, c1->chan, &glue0, &glue1, &instance0, &instance1, &vinstance0, &vinstance1);
+
+	if (glue0->get_codec) {
+		glue0->get_codec(c0->chan, cap0);
+	}
+	if (glue1->get_codec) {
+		glue1->get_codec(c1->chan, cap1);
+	}
+
+	if (native_type == AST_RTP_GLUE_RESULT_LOCAL) {
+		if (ast_rtp_instance_get_engine(instance0)->local_bridge) {
+			ast_rtp_instance_get_engine(instance0)->local_bridge(instance0, instance1);
+		}
+		if (ast_rtp_instance_get_engine(instance1)->local_bridge) {
+			ast_rtp_instance_get_engine(instance1)->local_bridge(instance1, instance0);
+		}
+		ast_rtp_instance_set_bridged(instance0, instance1);
+		ast_rtp_instance_set_bridged(instance1, instance0);
+	} else {
+		glue0->update_peer(c0->chan, instance1, vinstance1, tinstance1, cap1, 0);
+		glue1->update_peer(c1->chan, instance0, vinstance0, tinstance0, cap0, 0);
+	}
+
+	return 0;
+}
+
+static void native_rtp_bridge_unsuspend(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
+{
+	native_rtp_bridge_join(bridge, bridge_channel);
+}
+
+static void native_rtp_bridge_leave(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
+{
+	struct ast_bridge_channel *c0 = AST_LIST_FIRST(&bridge->channels) ? AST_LIST_FIRST(&bridge->channels) : bridge_channel;
+	struct ast_bridge_channel *c1 = AST_LIST_LAST(&bridge->channels);
+	enum ast_rtp_glue_result native_type;
+	struct ast_rtp_glue *glue0, *glue1 = NULL;
+	struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL, *vinstance0 = NULL, *vinstance1 = NULL;
+
+	native_rtp_bridge_framehook_detach(c0);
+	if (c1) {
+		native_rtp_bridge_framehook_detach(c1);
+	}
+
+	native_type = native_rtp_bridge_get(c0->chan, c1 ? c1->chan : NULL, &glue0, &glue1, &instance0, &instance1, &vinstance0, &vinstance1);
+
+	if (native_type == AST_RTP_GLUE_RESULT_LOCAL) {
+		if (ast_rtp_instance_get_engine(instance0)->local_bridge) {
+			ast_rtp_instance_get_engine(instance0)->local_bridge(instance0, NULL);
+		}
+		if (instance1 && ast_rtp_instance_get_engine(instance1)->local_bridge) {
+			ast_rtp_instance_get_engine(instance1)->local_bridge(instance1, NULL);
+		}
+		ast_rtp_instance_set_bridged(instance0, instance1);
+		if (instance1) {
+			ast_rtp_instance_set_bridged(instance1, instance0);
+		}
+	} else {
+		glue0->update_peer(c0->chan, NULL, NULL, NULL, NULL, 0);
+		if (glue1) {
+			glue1->update_peer(c1->chan, NULL, NULL, NULL, NULL, 0);
+		}
+	}
+}
+
+static int native_rtp_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
+{
+	struct ast_bridge_channel *other = ast_bridge_channel_peer(bridge_channel);
+
+	if (!other) {
+		return -1;
+	}
+
+	/* The bridging core takes care of freeing the passed in frame. */
+	ast_bridge_channel_queue_frame(other, frame);
+
+	return 0;
+}
+
+static struct ast_bridge_technology native_rtp_bridge = {
+	.name = "native_rtp",
+	.capabilities = AST_BRIDGE_CAPABILITY_NATIVE,
+	.preference = AST_BRIDGE_PREFERENCE_BASE_NATIVE,
+	.join = native_rtp_bridge_join,
+	.unsuspend = native_rtp_bridge_unsuspend,
+	.leave = native_rtp_bridge_leave,
+	.suspend = native_rtp_bridge_leave,
+	.write = native_rtp_bridge_write,
+	.compatible = native_rtp_bridge_compatible,
+};
+
+static int unload_module(void)
+{
+	ast_format_cap_destroy(native_rtp_bridge.format_capabilities);
+	return ast_bridge_technology_unregister(&native_rtp_bridge);
+}
+
+static int load_module(void)
+{
+	if (!(native_rtp_bridge.format_capabilities = ast_format_cap_alloc())) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
+	ast_format_cap_add_all_by_type(native_rtp_bridge.format_capabilities, AST_FORMAT_TYPE_AUDIO);
+	ast_format_cap_add_all_by_type(native_rtp_bridge.format_capabilities, AST_FORMAT_TYPE_VIDEO);
+	ast_format_cap_add_all_by_type(native_rtp_bridge.format_capabilities, AST_FORMAT_TYPE_TEXT);
+
+	return ast_bridge_technology_register(&native_rtp_bridge);
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Native RTP bridging module");

Propchange: team/group/bridge_construction/bridges/bridge_native_rtp.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/bridge_construction/bridges/bridge_native_rtp.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/bridge_construction/bridges/bridge_native_rtp.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/group/bridge_construction/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/channels/chan_gulp.c?view=diff&rev=388316&r1=388315&r2=388316
==============================================================================
--- team/group/bridge_construction/channels/chan_gulp.c (original)
+++ team/group/bridge_construction/channels/chan_gulp.c Fri May 10 10:26:40 2013
@@ -132,7 +132,6 @@
 	.send_text = gulp_sendtext,
 	.send_digit_begin = gulp_digit_begin,
 	.send_digit_end = gulp_digit_end,
-	.bridge = ast_rtp_instance_bridge,
 	.call = gulp_call,
 	.hangup = gulp_hangup,
 	.answer = gulp_answer,

Modified: team/group/bridge_construction/channels/chan_h323.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/channels/chan_h323.c?view=diff&rev=388316&r1=388315&r2=388316
==============================================================================
--- team/group/bridge_construction/channels/chan_h323.c (original)
+++ team/group/bridge_construction/channels/chan_h323.c Fri May 10 10:26:40 2013
@@ -275,7 +275,6 @@
 	.write = oh323_write,
 	.indicate = oh323_indicate,
 	.fixup = oh323_fixup,
-	.bridge = ast_rtp_instance_bridge,
 };
 
 static const char* redirectingreason2str(int redirectingreason)

Modified: team/group/bridge_construction/channels/chan_jingle.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/channels/chan_jingle.c?view=diff&rev=388316&r1=388315&r2=388316
==============================================================================
--- team/group/bridge_construction/channels/chan_jingle.c (original)
+++ team/group/bridge_construction/channels/chan_jingle.c Fri May 10 10:26:40 2013
@@ -205,7 +205,6 @@
 	.send_text = jingle_sendtext,
 	.send_digit_begin = jingle_digit_begin,
 	.send_digit_end = jingle_digit_end,
-	.bridge = ast_rtp_instance_bridge,
 	.call = jingle_call,
 	.hangup = jingle_hangup,
 	.answer = jingle_answer,

Modified: team/group/bridge_construction/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/channels/chan_mgcp.c?view=diff&rev=388316&r1=388315&r2=388316
==============================================================================
--- team/group/bridge_construction/channels/chan_mgcp.c (original)
+++ team/group/bridge_construction/channels/chan_mgcp.c Fri May 10 10:26:40 2013
@@ -480,7 +480,6 @@
 	.fixup = mgcp_fixup,
 	.send_digit_begin = mgcp_senddigit_begin,
 	.send_digit_end = mgcp_senddigit_end,
-	.bridge = ast_rtp_instance_bridge,
 	.func_channel_read = acf_channel_read,
 };
 

Modified: team/group/bridge_construction/channels/chan_motif.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/channels/chan_motif.c?view=diff&rev=388316&r1=388315&r2=388316
==============================================================================
--- team/group/bridge_construction/channels/chan_motif.c (original)
+++ team/group/bridge_construction/channels/chan_motif.c Fri May 10 10:26:40 2013
@@ -360,7 +360,6 @@
 	.send_text = jingle_sendtext,
 	.send_digit_begin = jingle_digit_begin,
 	.send_digit_end = jingle_digit_end,
-	.bridge = ast_rtp_instance_bridge,
 	.call = jingle_call,
 	.hangup = jingle_hangup,
 	.answer = jingle_answer,

Modified: team/group/bridge_construction/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/channels/chan_sip.c?view=diff&rev=388316&r1=388315&r2=388316
==============================================================================
--- team/group/bridge_construction/channels/chan_sip.c (original)
+++ team/group/bridge_construction/channels/chan_sip.c Fri May 10 10:26:40 2013
@@ -1543,7 +1543,6 @@
 	.fixup = sip_fixup,			/* called with chan locked */
 	.send_digit_begin = sip_senddigit_begin,	/* called with chan unlocked */
 	.send_digit_end = sip_senddigit_end,
-	.bridge = ast_rtp_instance_bridge,			/* XXX chan unlocked ? */
 	.early_bridge = ast_rtp_instance_early_bridge,
 	.send_text = sip_sendtext,		/* called with chan locked */
 	.func_channel_read = sip_acf_channel_read,
@@ -32609,7 +32608,7 @@
 
 	/* Disable early RTP bridge  */
 	if ((instance || vinstance || tinstance) &&
-		!ast_bridged_channel(chan) &&
+		!ast_channel_is_bridged(chan) &&
 		!sip_cfg.directrtpsetup) {
 		sip_pvt_unlock(p);
 		ast_channel_unlock(chan);

Modified: team/group/bridge_construction/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/channels/chan_skinny.c?view=diff&rev=388316&r1=388315&r2=388316
==============================================================================
--- team/group/bridge_construction/channels/chan_skinny.c (original)
+++ team/group/bridge_construction/channels/chan_skinny.c Fri May 10 10:26:40 2013
@@ -1635,7 +1635,6 @@
 	.fixup = skinny_fixup,
 	.send_digit_begin = skinny_senddigit_begin,
 	.send_digit_end = skinny_senddigit_end,
-	.bridge = ast_rtp_instance_bridge,
 };
 
 static int skinny_extensionstate_cb(char *context, char *id, struct ast_state_cb_info *info, void *data);

Modified: team/group/bridge_construction/channels/chan_unistim.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/channels/chan_unistim.c?view=diff&rev=388316&r1=388315&r2=388316
==============================================================================
--- team/group/bridge_construction/channels/chan_unistim.c (original)
+++ team/group/bridge_construction/channels/chan_unistim.c Fri May 10 10:26:40 2013
@@ -708,7 +708,6 @@
 	.send_digit_begin = unistim_senddigit_begin,
 	.send_digit_end = unistim_senddigit_end,
 	.send_text = unistim_sendtext,
-	.bridge = ast_rtp_instance_bridge,
 };
 
 static void send_start_rtp(struct unistim_subchannel *);

Modified: team/group/bridge_construction/include/asterisk/rtp_engine.h
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/include/asterisk/rtp_engine.h?view=diff&rev=388316&r1=388315&r2=388316
==============================================================================
--- team/group/bridge_construction/include/asterisk/rtp_engine.h (original)
+++ team/group/bridge_construction/include/asterisk/rtp_engine.h Fri May 10 10:26:40 2013
@@ -1541,24 +1541,6 @@
 struct ast_rtp_glue *ast_rtp_instance_get_glue(const char *type);
 
 /*!
- * \brief Bridge two channels that use RTP instances
- *
- * \param c0 First channel part of the bridge
- * \param c1 Second channel part of the bridge
- * \param flags Bridging flags
- * \param fo If a frame needs to be passed up it is stored here
- * \param rc Channel that passed the above frame up
- * \param timeoutms How long the channels should be bridged for
- *
- * \retval Bridge result
- *
- * \note This should only be used by channel drivers in their technology declaration.
- *
- * \since 1.8
- */
-enum ast_bridge_result ast_rtp_instance_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
-
-/*!
  * \brief Get the other RTP instance that an instance is bridged to
  *
  * \param instance The RTP instance that we want
@@ -1577,6 +1559,16 @@
  * \since 1.8
  */
 struct ast_rtp_instance *ast_rtp_instance_get_bridged(struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Set the other RTP instance that an instance is bridged to
+ *
+ * \param instance The RTP instance that we want to set the bridged value on
+ * \param bridged The RTP instance they are bridged to
+ *
+ * \since 12
+ */
+void ast_rtp_instance_set_bridged(struct ast_rtp_instance *instance, struct ast_rtp_instance *bridged);
 
 /*!
  * \brief Make two channels compatible for early bridging

Modified: team/group/bridge_construction/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/main/bridging.c?view=diff&rev=388316&r1=388315&r2=388316
==============================================================================
--- team/group/bridge_construction/main/bridging.c (original)
+++ team/group/bridge_construction/main/bridging.c Fri May 10 10:26:40 2013
@@ -2274,6 +2274,13 @@
 		chan = ast_waitfor_nandfds(&bridge_channel->chan, 1,
 			&bridge_channel->alert_pipe[0], 1, NULL, &outfd, &ms);
 		bridge_channel->waiting = 0;
+		if (ast_channel_softhangup_internal_flag(bridge_channel->chan) & AST_SOFTHANGUP_UNBRIDGE) {
+			ast_channel_clear_softhangup(bridge_channel->chan, AST_SOFTHANGUP_UNBRIDGE);
+			ast_bridge_channel_lock_bridge(bridge_channel);
+			bridge_channel->bridge->reconfigured = 1;
+			bridge_reconfigured(bridge_channel->bridge);
+			ast_bridge_unlock(bridge_channel->bridge);
+		}
 		ast_bridge_channel_lock(bridge_channel);
 		bridge_channel->activity = AST_BRIDGE_CHANNEL_THREAD_FRAME;
 		ast_bridge_channel_unlock(bridge_channel);

Modified: team/group/bridge_construction/main/rtp_engine.c
URL: http://svnview.digium.com/svn/asterisk/team/group/bridge_construction/main/rtp_engine.c?view=diff&rev=388316&r1=388315&r2=388316
==============================================================================
--- team/group/bridge_construction/main/rtp_engine.c (original)
+++ team/group/bridge_construction/main/rtp_engine.c Fri May 10 10:26:40 2013
@@ -928,497 +928,6 @@
 	return glue;
 }
 
-static enum ast_bridge_result local_bridge_loop(struct ast_channel *c0, struct ast_channel *c1, struct ast_rtp_instance *instance0, struct ast_rtp_instance *instance1, int timeoutms, int flags, struct ast_frame **fo, struct ast_channel **rc, void *pvt0, void *pvt1)
-{
-	enum ast_bridge_result res = AST_BRIDGE_FAILED;
-	struct ast_channel *who = NULL, *other = NULL, *cs[3] = { NULL, };
-	struct ast_frame *fr = NULL;
-	struct timeval start;
-
-	/* Start locally bridging both instances */
-	if (instance0->engine->local_bridge && instance0->engine->local_bridge(instance0, instance1)) {
-		ast_debug(1, "Failed to locally bridge %s to %s, backing out.\n", ast_channel_name(c0), ast_channel_name(c1));
-		ast_channel_unlock(c0);
-		ast_channel_unlock(c1);
-		return AST_BRIDGE_FAILED_NOWARN;
-	}
-	if (instance1->engine->local_bridge && instance1->engine->local_bridge(instance1, instance0)) {
-		ast_debug(1, "Failed to locally bridge %s to %s, backing out.\n", ast_channel_name(c1), ast_channel_name(c0));
-		if (instance0->engine->local_bridge) {
-			instance0->engine->local_bridge(instance0, NULL);
-		}
-		ast_channel_unlock(c0);
-		ast_channel_unlock(c1);
-		return AST_BRIDGE_FAILED_NOWARN;
-	}
-
-	ast_channel_unlock(c0);
-	ast_channel_unlock(c1);
-
-	instance0->bridged = instance1;
-	instance1->bridged = instance0;
-
-	ast_poll_channel_add(c0, c1);
-
-	/* Hop into a loop waiting for a frame from either channel */
-	cs[0] = c0;
-	cs[1] = c1;
-	cs[2] = NULL;
-	start = ast_tvnow();
-	for (;;) {
-		int ms;
-		/* If the underlying formats have changed force this bridge to break */
-		if ((ast_format_cmp(ast_channel_rawreadformat(c0), ast_channel_rawwriteformat(c1)) == AST_FORMAT_CMP_NOT_EQUAL) ||
-			(ast_format_cmp(ast_channel_rawreadformat(c1), ast_channel_rawwriteformat(c0)) == AST_FORMAT_CMP_NOT_EQUAL)) {
-			ast_debug(1, "rtp-engine-local-bridge: Oooh, formats changed, backing out\n");
-			res = AST_BRIDGE_FAILED_NOWARN;
-			break;
-		}
-		/* Check if anything changed */
-		if ((ast_channel_tech_pvt(c0) != pvt0) ||
-		    (ast_channel_tech_pvt(c1) != pvt1) ||
-		    (ast_channel_masq(c0) || ast_channel_masqr(c0) || ast_channel_masq(c1) || ast_channel_masqr(c1)) ||
-		    (ast_channel_monitor(c0) || ast_channel_audiohooks(c0) || ast_channel_monitor(c1) || ast_channel_audiohooks(c1)) ||
-		    (!ast_framehook_list_is_empty(ast_channel_framehooks(c0)) || !ast_framehook_list_is_empty(ast_channel_framehooks(c1)))) {
-			ast_debug(1, "rtp-engine-local-bridge: Oooh, something is weird, backing out\n");
-			/* If a masquerade needs to happen we have to try to read in a frame so that it actually happens. Without this we risk being called again and going into a loop */
-			if ((ast_channel_masq(c0) || ast_channel_masqr(c0)) && (fr = ast_read(c0))) {
-				ast_frfree(fr);
-			}
-			if ((ast_channel_masq(c1) || ast_channel_masqr(c1)) && (fr = ast_read(c1))) {
-				ast_frfree(fr);
-			}
-			res = AST_BRIDGE_RETRY;
-			break;
-		}
-		/* Wait on a channel to feed us a frame */
-		ms = ast_remaining_ms(start, timeoutms);
-		if (!(who = ast_waitfor_n(cs, 2, &ms))) {
-			if (!ms) {
-				res = AST_BRIDGE_RETRY;
-				break;
-			}
-			ast_debug(2, "rtp-engine-local-bridge: Ooh, empty read...\n");
-			if (ast_check_hangup(c0) || ast_check_hangup(c1)) {
-				break;
-			}
-			continue;
-		}
-		/* Read in frame from channel */
-		fr = ast_read(who);
-		other = (who == c0) ? c1 : c0;
-		/* Depending on the frame we may need to break out of our bridge */
-		if (!fr || ((fr->frametype == AST_FRAME_DTMF_BEGIN || fr->frametype == AST_FRAME_DTMF_END) &&
-			    ((who == c0) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) |
-			    ((who == c1) && (flags & AST_BRIDGE_DTMF_CHANNEL_1)))) {
-			/* Record received frame and who */
-			*fo = fr;
-			*rc = who;
-			ast_debug(1, "rtp-engine-local-bridge: Ooh, got a %s\n", fr ? "digit" : "hangup");
-			res = AST_BRIDGE_COMPLETE;
-			break;
-		} else if ((fr->frametype == AST_FRAME_CONTROL) && !(flags & AST_BRIDGE_IGNORE_SIGS)) {
-			if ((fr->subclass.integer == AST_CONTROL_HOLD) ||
-			    (fr->subclass.integer == AST_CONTROL_UNHOLD) ||
-			    (fr->subclass.integer == AST_CONTROL_VIDUPDATE) ||
-			    (fr->subclass.integer == AST_CONTROL_SRCUPDATE) ||
-			    (fr->subclass.integer == AST_CONTROL_T38_PARAMETERS) ||
-			    (fr->subclass.integer == AST_CONTROL_UPDATE_RTP_PEER)) {
-				/* If we are going on hold, then break callback mode and P2P bridging */
-				if (fr->subclass.integer == AST_CONTROL_HOLD) {
-					if (instance0->engine->local_bridge) {
-						instance0->engine->local_bridge(instance0, NULL);
-					}
-					if (instance1->engine->local_bridge) {
-						instance1->engine->local_bridge(instance1, NULL);
-					}
-					instance0->bridged = NULL;
-					instance1->bridged = NULL;
-				} else if (fr->subclass.integer == AST_CONTROL_UNHOLD) {
-					if (instance0->engine->local_bridge) {
-						instance0->engine->local_bridge(instance0, instance1);
-					}
-					if (instance1->engine->local_bridge) {
-						instance1->engine->local_bridge(instance1, instance0);
-					}
-					instance0->bridged = instance1;
-					instance1->bridged = instance0;
-				}
-				/* Since UPDATE_BRIDGE_PEER is only used by the bridging code, don't forward it */
-				if (fr->subclass.integer != AST_CONTROL_UPDATE_RTP_PEER) {
-					ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
-				}
-				ast_frfree(fr);
-			} else if (fr->subclass.integer == AST_CONTROL_CONNECTED_LINE) {
-				if (ast_channel_connected_line_sub(who, other, fr, 1) &&
-					ast_channel_connected_line_macro(who, other, fr, other == c0, 1)) {
-					ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
-				}
-				ast_frfree(fr);
-			} else if (fr->subclass.integer == AST_CONTROL_REDIRECTING) {
-				if (ast_channel_redirecting_sub(who, other, fr, 1) &&
-					ast_channel_redirecting_macro(who, other, fr, other == c0, 1)) {
-					ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
-				}
-				ast_frfree(fr);
-			} else if (fr->subclass.integer == AST_CONTROL_PVT_CAUSE_CODE) {
-				ast_channel_hangupcause_hash_set(other, fr->data.ptr, fr->datalen);
-				ast_frfree(fr);
-			} else {
-				*fo = fr;
-				*rc = who;
-				ast_debug(1, "rtp-engine-local-bridge: Got a FRAME_CONTROL (%d) frame on channel %s\n", fr->subclass.integer, ast_channel_name(who));
-				res = AST_BRIDGE_COMPLETE;
-				break;
-			}
-		} else {
-			if ((fr->frametype == AST_FRAME_DTMF_BEGIN) ||
-			    (fr->frametype == AST_FRAME_DTMF_END) ||
-			    (fr->frametype == AST_FRAME_VOICE) ||
-			    (fr->frametype == AST_FRAME_VIDEO) ||
-			    (fr->frametype == AST_FRAME_IMAGE) ||
-			    (fr->frametype == AST_FRAME_HTML) ||
-			    (fr->frametype == AST_FRAME_MODEM) ||
-			    (fr->frametype == AST_FRAME_TEXT)) {
-				ast_write(other, fr);
-			}
-
-			ast_frfree(fr);
-		}
-		/* Swap priority */
-		cs[2] = cs[0];
-		cs[0] = cs[1];
-		cs[1] = cs[2];
-	}
-
-	/* Stop locally bridging both instances */
-	if (instance0->engine->local_bridge) {
-		instance0->engine->local_bridge(instance0, NULL);
-	}
-	if (instance1->engine->local_bridge) {
-		instance1->engine->local_bridge(instance1, NULL);
-	}
-
-	instance0->bridged = NULL;
-	instance1->bridged = NULL;
-
-	ast_poll_channel_del(c0, c1);
-
-	return res;
-}
-
-static enum ast_bridge_result remote_bridge_loop(struct ast_channel *c0,
-	struct ast_channel *c1,
-	struct ast_rtp_instance *instance0,
-	struct ast_rtp_instance *instance1,
-	struct ast_rtp_instance *vinstance0,
-	struct ast_rtp_instance *vinstance1,
-	struct ast_rtp_instance *tinstance0,
-	struct ast_rtp_instance *tinstance1,
-	struct ast_rtp_glue *glue0,
-	struct ast_rtp_glue *glue1,
-	struct ast_format_cap *cap0,
-	struct ast_format_cap *cap1,
-	int timeoutms,
-	int flags,
-	struct ast_frame **fo,
-	struct ast_channel **rc,
-	void *pvt0,
-	void *pvt1)
-{
-	enum ast_bridge_result res = AST_BRIDGE_FAILED;
-	struct ast_channel *who = NULL, *other = NULL, *cs[3] = { NULL, };
-	struct ast_format_cap *oldcap0 = ast_format_cap_dup(cap0);
-	struct ast_format_cap *oldcap1 = ast_format_cap_dup(cap1);
-	struct ast_sockaddr ac1 = {{0,}}, vac1 = {{0,}}, tac1 = {{0,}}, ac0 = {{0,}}, vac0 = {{0,}}, tac0 = {{0,}};
-	struct ast_sockaddr t1 = {{0,}}, vt1 = {{0,}}, tt1 = {{0,}}, t0 = {{0,}}, vt0 = {{0,}}, tt0 = {{0,}};
-	struct ast_frame *fr = NULL;
-	struct timeval start;
-
-	if (!oldcap0 || !oldcap1) {
-		ast_channel_unlock(c0);
-		ast_channel_unlock(c1);
-		goto remote_bridge_cleanup;
-	}
-	/* Test the first channel */
-	if (!(glue0->update_peer(c0, instance1, vinstance1, tinstance1, cap1, 0))) {
-		ast_rtp_instance_get_remote_address(instance1, &ac1);
-		if (vinstance1) {
-			ast_rtp_instance_get_remote_address(vinstance1, &vac1);
-		}
-		if (tinstance1) {
-			ast_rtp_instance_get_remote_address(tinstance1, &tac1);
-		}
-	} else {
-		ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", ast_channel_name(c0), ast_channel_name(c1));
-	}
-
-	/* Test the second channel */
-	if (!(glue1->update_peer(c1, instance0, vinstance0, tinstance0, cap0, 0))) {
-		ast_rtp_instance_get_remote_address(instance0, &ac0);
-		if (vinstance0) {
-			ast_rtp_instance_get_remote_address(instance0, &vac0);
-		}
-		if (tinstance0) {
-			ast_rtp_instance_get_remote_address(instance0, &tac0);
-		}
-	} else {
-		ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", ast_channel_name(c1), ast_channel_name(c0));
-	}
-
-	ast_channel_unlock(c0);
-	ast_channel_unlock(c1);
-
-	instance0->bridged = instance1;
-	instance1->bridged = instance0;
-
-	ast_poll_channel_add(c0, c1);
-
-	/* Go into a loop handling any stray frames that may come in */
-	cs[0] = c0;
-	cs[1] = c1;
-	cs[2] = NULL;
-	start = ast_tvnow();
-	for (;;) {
-		int ms;
-		/* Check if anything changed */
-		if ((ast_channel_tech_pvt(c0) != pvt0) ||
-		    (ast_channel_tech_pvt(c1) != pvt1) ||

[... 429 lines stripped ...]



More information about the asterisk-commits mailing list