[asterisk-commits] file: branch file/bridging r65489 - in /team/file/bridging: bridges/ include/...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue May 22 10:31:37 MST 2007


Author: file
Date: Tue May 22 12:31:37 2007
New Revision: 65489

URL: http://svn.digium.com/view/asterisk?view=rev&rev=65489
Log:
Add support for having the bridging core handle formats. The bridge technology specifies what formats it can handle and the bridging core will try to make a joining channel obey it. If that fails then the joining channel will be denied.

Modified:
    team/file/bridging/bridges/bridge_simple.c
    team/file/bridging/bridges/bridge_zaptel.c
    team/file/bridging/include/asterisk/bridging.h
    team/file/bridging/main/bridging.c

Modified: team/file/bridging/bridges/bridge_simple.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/bridges/bridge_simple.c?view=diff&rev=65489&r1=65488&r2=65489
==============================================================================
--- team/file/bridging/bridges/bridge_simple.c (original)
+++ team/file/bridging/bridges/bridge_simple.c Tue May 22 12:31:37 2007
@@ -61,6 +61,7 @@
 static struct ast_bridge_technology simple_bridge = {
 	.name = "simple_bridge",
 	.capabilities = AST_BRIDGE_CAPABILITY_1TO1MIX | AST_BRIDGE_CAPABILITY_NATIVE,
+	.formats = AST_FORMAT_AUDIO_MASK | AST_FORMAT_VIDEO_MASK | AST_FORMAT_TEXT_MASK,
 	.write = simple_bridge_write,
 };
 

Modified: team/file/bridging/bridges/bridge_zaptel.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/bridges/bridge_zaptel.c?view=diff&rev=65489&r1=65488&r2=65489
==============================================================================
--- team/file/bridging/bridges/bridge_zaptel.c (original)
+++ team/file/bridging/bridges/bridge_zaptel.c Tue May 22 12:31:37 2007
@@ -197,6 +197,7 @@
 static struct ast_bridge_technology zaptel_bridge = {
 	.name = "zaptel_bridge",
 	.capabilities = AST_BRIDGE_CAPABILITY_MULTIMIX,
+	.formats = AST_FORMAT_SLINEAR,
 	.create = zaptel_bridge_create,
 	.destroy = zaptel_bridge_destroy,
 	.join = zaptel_bridge_join,

Modified: team/file/bridging/include/asterisk/bridging.h
URL: http://svn.digium.com/view/asterisk/team/file/bridging/include/asterisk/bridging.h?view=diff&rev=65489&r1=65488&r2=65489
==============================================================================
--- team/file/bridging/include/asterisk/bridging.h (original)
+++ team/file/bridging/include/asterisk/bridging.h Tue May 22 12:31:37 2007
@@ -66,6 +66,7 @@
 	int (*leave)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);                           /*! Callback for when a channel leaves a bridge */
 	int (*write)(struct ast_bridge *bridge, struct ast_bridge_channel *bridged_channel, struct ast_frame *frame); /*! Callback for writing a frame to the bridge */
 	int (*signal)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);                          /*! Callback for a bridge channel thread signal */
+	int formats;                                                                                                  /*! Formats this bridge technology can support */
 	AST_RWLIST_ENTRY(ast_bridge_technology) list;                                                                 /*! Linked list information */
 };
 

Modified: team/file/bridging/main/bridging.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/main/bridging.c?view=diff&rev=65489&r1=65488&r2=65489
==============================================================================
--- team/file/bridging/main/bridging.c (original)
+++ team/file/bridging/main/bridging.c Tue May 22 12:31:37 2007
@@ -329,6 +329,45 @@
 /*! \brief Join a channel to a bridge and handle anything the bridge may want us to do */
 static enum ast_bridge_channel_phase bridge_channel_join(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
 {
+	int formats[2] = {bridge_channel->chan->readformat, bridge_channel->chan->writeformat};
+
+	/* Are the formats currently in use something this bridge can handle? */
+	if (!(bridge->technology->formats & formats[0])) {
+		int best_format = ast_best_codec(bridge->technology->formats);
+
+		/* Read format is a no go... */
+		if (option_debug) {
+			char codec_buf[512];
+			ast_getformatname_multiple(codec_buf, sizeof(codec_buf), bridge->technology->formats);
+			ast_log(LOG_DEBUG, "Bridge technology %s wants to read any of formats %s(%d) but channel has %s(%d)\n", bridge->technology->name, codec_buf, bridge->technology->formats, ast_getformatname(formats[0]), formats[0]);
+		}
+		/* Switch read format to the best one chosen */
+		if (ast_set_read_format(bridge_channel->chan, best_format)) {
+			ast_log(LOG_WARNING, "Failed to set channel %s to read format %s(%d)\n", bridge_channel->chan->name, ast_getformatname(best_format), best_format);
+			return -1;
+		}
+		if (option_debug)
+			ast_log(LOG_DEBUG, "Bridge %p put channel %s into read format %s(%d)\n", bridge, bridge_channel->chan->name, ast_getformatname(best_format), best_format);
+	}
+
+	if (!(bridge->technology->formats & formats[1])) {
+		int best_format = ast_best_codec(bridge->technology->formats);
+
+		/* Write format is a no go... */
+		if (option_debug) {
+			char codec_buf[512];
+			ast_getformatname_multiple(codec_buf, sizeof(codec_buf), bridge->technology->formats);
+			ast_log(LOG_DEBUG, "Bridge technology %s wants to write any of formats %s(%d) but channel has %s(%d)\n", bridge->technology->name, codec_buf, bridge->technology->formats, ast_getformatname(formats[1]), formats[1]);
+		}
+		/* Switch write format to the best one chosen */
+		if (ast_set_write_format(bridge_channel->chan, best_format)) {
+			ast_log(LOG_WARNING, "Failed to set channel %s to write format %s(%d)\n", bridge_channel->chan->name, ast_getformatname(best_format), best_format);
+			return -1;
+		}
+		if (option_debug)
+			ast_log(LOG_DEBUG, "Bridge %p put channel %s into write format %s(%d)\n", bridge, bridge_channel->chan->name, ast_getformatname(best_format), best_format);
+	}
+
 	/* Before we actually become part of this bridge make sure we are in the signalling wait phase */
 	bridge_channel->phase = AST_BRIDGE_CHANNEL_PHASE_WAIT;
 
@@ -394,6 +433,21 @@
 	/* Remove ourselves from the bridge */
 	AST_LIST_REMOVE(&bridge->channels, bridge_channel, list);
 
+	/* Restore original formats if need be */
+	if (bridge_channel->chan->readformat != formats[0]) {
+		if (option_debug)
+			ast_log(LOG_DEBUG, "Bridge is returning %p to read format %s(%d)\n", bridge_channel, ast_getformatname(formats[0]), formats[0]);
+		if (ast_set_read_format(bridge_channel->chan, formats[0]))
+			ast_log(LOG_WARNING, "Failed to return channel %s to read format %s(%d)\n", bridge_channel->chan->name, ast_getformatname(formats[0]), formats[0]);
+	}
+
+	if (bridge_channel->chan->writeformat != formats[0]) {
+		if (option_debug)
+			ast_log(LOG_DEBUG, "Bridge is returning %p to write format %s(%d)\n", bridge_channel, ast_getformatname(formats[1]), formats[1]);
+		if (ast_set_write_format(bridge_channel->chan, formats[1]))
+			ast_log(LOG_WARNING, "Failed to return channel %s to write format %s(%d)\n", bridge_channel->chan->name, ast_getformatname(formats[1]), formats[1]);
+	}
+
 	return bridge_channel->phase;
 }
 



More information about the asterisk-commits mailing list