[svn-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r300563 - in /team/dvossel/f...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jan 4 23:04:51 UTC 2011


Author: dvossel
Date: Tue Jan  4 17:04:47 2011
New Revision: 300563

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=300563
Log:
all the changes required to make bridging.c compile with ast_format conversion

Modified:
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/bridging.h
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/bridging_technology.h
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h
    team/dvossel/fixtheworld_phase1_step3/main/bridging.c
    team/dvossel/fixtheworld_phase1_step3/main/format_cap.c

Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/bridging.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/bridging.h?view=diff&rev=300563&r1=300562&r2=300563
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/bridging.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/bridging.h Tue Jan  4 17:04:47 2011
@@ -193,7 +193,7 @@
  * This creates a simple two party bridge that will be destroyed once one of
  * the channels hangs up.
  */
-struct ast_bridge *ast_bridge_new(format_t capabilities, int flags);
+struct ast_bridge *ast_bridge_new(uint32_t capabilities, int flags);
 
 /*! \brief See if it is possible to create a bridge
  *
@@ -211,7 +211,7 @@
  * This sees if it is possible to create a bridge capable of bridging two channels
  * together.
  */
-int ast_bridge_check(format_t capabilities);
+int ast_bridge_check(uint32_t capabilities);
 
 /*! \brief Destroy a bridge
  *

Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/bridging_technology.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/bridging_technology.h?view=diff&rev=300563&r1=300562&r2=300563
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/bridging_technology.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/bridging_technology.h Tue Jan  4 17:04:47 2011
@@ -44,8 +44,9 @@
 struct ast_bridge_technology {
 	/*! Unique name to this bridge technology */
 	const char *name;
-	/*! The capabilities that this bridge technology is capable of */
-	format_t capabilities;
+	/*! The capabilities that this bridge technology is capable of.  This has nothing to do with
+	 * format capabilities. */
+	uint32_t capabilities;
 	/*! Preference level that should be used when determining whether to use this bridge technology or not */
 	enum ast_bridge_preference preference;
 	/*! Callback for when a bridge is being created */
@@ -71,7 +72,7 @@
 	/*! Callback for poking a bridge thread */
 	int (*poke)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
 	/*! Formats that the bridge technology supports */
-	format_t formats;
+	struct ast_cap *format_capabilities;
 	/*! Bit to indicate whether the bridge technology is currently suspended or not */
 	unsigned int suspended:1;
 	/*! Module this bridge technology belongs to. Is used for reference counting when creating/destroying a bridge. */

Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h?view=diff&rev=300563&r1=300562&r2=300563
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h Tue Jan  4 17:04:47 2011
@@ -98,6 +98,15 @@
 struct ast_cap *ast_cap_joint(struct ast_cap *cap1, struct ast_cap *cap2);
 
 /*!
+ * \brief Find out if capability structures have any joint capabilities without
+ * returning those capabilities.
+ *
+ * \retval 1 success
+ * \retval 0 failure
+ */
+struct ast_cap *ast_cap_has_joint(struct ast_cap *cap1, struct ast_cap *cap2);
+
+/*!
  * \brief Get all capabilities for a specific media type
  *
  * \retval !NULL success

Modified: team/dvossel/fixtheworld_phase1_step3/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/bridging.c?view=diff&rev=300563&r1=300562&r2=300563
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/bridging.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/bridging.c Tue Jan  4 17:04:47 2011
@@ -382,16 +382,12 @@
 }
 
 /*! \brief Helper function used to find the "best" bridge technology given a specified capabilities */
-static struct ast_bridge_technology *find_best_technology(format_t capabilities)
+static struct ast_bridge_technology *find_best_technology(uint32_t capabilities)
 {
 	struct ast_bridge_technology *current = NULL, *best = NULL;
 
 	AST_RWLIST_RDLOCK(&bridge_technologies);
 	AST_RWLIST_TRAVERSE(&bridge_technologies, current, entry) {
-		char tmp1[256], tmp2[256];
-		ast_debug(1, "Bridge technology %s has capabilities %s and we want %s\n", current->name,
-			ast_getformatname_multiple(tmp1, sizeof(tmp1), current->capabilities),
-			ast_getformatname_multiple(tmp2, sizeof(tmp2), capabilities));
 		if (current->suspended) {
 			ast_debug(1, "Bridge technology %s is suspended. Skipping.\n", current->name);
 			continue;
@@ -448,7 +444,7 @@
 	return;
 }
 
-struct ast_bridge *ast_bridge_new(format_t capabilities, int flags)
+struct ast_bridge *ast_bridge_new(uint32_t capabilities, int flags)
 {
 	struct ast_bridge *bridge = NULL;
 	struct ast_bridge_technology *bridge_technology = NULL;
@@ -470,9 +466,6 @@
 
 	/* If no bridge technology was found we can't possibly do bridging so fail creation of the bridge */
 	if (!bridge_technology) {
-		char codec_buf[256];
-		ast_debug(1, "Failed to find a bridge technology to satisfy capabilities %s\n",
-			ast_getformatname_multiple(codec_buf, sizeof(codec_buf), capabilities));
 		return NULL;
 	}
 
@@ -503,7 +496,7 @@
 	return bridge;
 }
 
-int ast_bridge_check(format_t capabilities)
+int ast_bridge_check(uint32_t capabilities)
 {
 	struct ast_bridge_technology *bridge_technology = NULL;
 
@@ -542,47 +535,51 @@
 
 static int bridge_make_compatible(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
 {
-	format_t formats[2] = {bridge_channel->chan->readformat, bridge_channel->chan->writeformat};
+	struct ast_format formats[2];
+	ast_format_copy(&bridge_channel->chan->readformat, &formats[0]);
+	ast_format_copy(&bridge_channel->chan->writeformat, &formats[1]);
 
 	/* Are the formats currently in use something ths bridge can handle? */
-	if (!(bridge->technology->formats & bridge_channel->chan->readformat)) {
-		format_t best_format = ast_best_codec(bridge->technology->formats);
+	if (!ast_cap_iscompatible(bridge->technology->format_capabilities, &bridge_channel->chan->readformat)) {
+		struct ast_format best_format;
+		ast_best_codec(bridge->technology->format_capabilities, &best_format);
 
 		/* Read format is a no go... */
 		if (option_debug) {
 			char codec_buf[512];
 			ast_debug(1, "Bridge technology %s wants to read any of formats %s but channel has %s\n", bridge->technology->name,
-				ast_getformatname_multiple(codec_buf, sizeof(codec_buf), bridge->technology->formats),
-				ast_getformatname(formats[0]));
+				ast_getformatname_multiple(codec_buf, sizeof(codec_buf), bridge->technology->format_capabilities),
+				ast_getformatname(&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\n", bridge_channel->chan->name, ast_getformatname(best_format));
+		if (ast_set_read_format(bridge_channel->chan, &best_format)) {
+			ast_log(LOG_WARNING, "Failed to set channel %s to read format %s\n", bridge_channel->chan->name, ast_getformatname(&best_format));
 			return -1;
 		}
-		ast_debug(1, "Bridge %p put channel %s into read format %s\n", bridge, bridge_channel->chan->name, ast_getformatname(best_format));
+		ast_debug(1, "Bridge %p put channel %s into read format %s\n", bridge, bridge_channel->chan->name, ast_getformatname(&best_format));
 	} else {
-		ast_debug(1, "Bridge %p is happy that channel %s already has read format %s\n", bridge, bridge_channel->chan->name, ast_getformatname(formats[0]));
-	}
-
-	if (!(bridge->technology->formats & formats[1])) {
-		int best_format = ast_best_codec(bridge->technology->formats);
+		ast_debug(1, "Bridge %p is happy that channel %s already has read format %s\n", bridge, bridge_channel->chan->name, ast_getformatname(&formats[0]));
+	}
+
+	if (!ast_cap_iscompatible(bridge->technology->format_capabilities, &formats[1])) {
+		struct ast_format best_format;
+		ast_best_codec(bridge->technology->format_capabilities, &best_format);
 
 		/* Write format is a no go... */
 		if (option_debug) {
 			char codec_buf[512];
 			ast_debug(1, "Bridge technology %s wants to write any of formats %s but channel has %s\n", bridge->technology->name,
-				ast_getformatname_multiple(codec_buf, sizeof(codec_buf), bridge->technology->formats),
-				ast_getformatname(formats[1]));
+				ast_getformatname_multiple(codec_buf, sizeof(codec_buf), bridge->technology->format_capabilities),
+				ast_getformatname(&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\n", bridge_channel->chan->name, ast_getformatname(best_format));
+		if (ast_set_write_format(bridge_channel->chan, &best_format)) {
+			ast_log(LOG_WARNING, "Failed to set channel %s to write format %s\n", bridge_channel->chan->name, ast_getformatname(&best_format));
 			return -1;
 		}
-		ast_debug(1, "Bridge %p put channel %s into write format %s\n", bridge, bridge_channel->chan->name, ast_getformatname(best_format));
+		ast_debug(1, "Bridge %p put channel %s into write format %s\n", bridge, bridge_channel->chan->name, ast_getformatname(&best_format));
 	} else {
-		ast_debug(1, "Bridge %p is happy that channel %s already has write format %s\n", bridge, bridge_channel->chan->name, ast_getformatname(formats[1]));
+		ast_debug(1, "Bridge %p is happy that channel %s already has write format %s\n", bridge, bridge_channel->chan->name, ast_getformatname(&formats[1]));
 	}
 
 	return 0;
@@ -591,7 +588,7 @@
 /*! \brief Perform the smart bridge operation. Basically sees if a new bridge technology should be used instead of the current one. */
 static int smart_bridge_operation(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, int count)
 {
-	format_t new_capabilities = 0;
+	uint32_t new_capabilities = 0;
 	struct ast_bridge_technology *new_technology = NULL, *old_technology = bridge->technology;
 	struct ast_bridge temp_bridge = {
 		.technology = bridge->technology,
@@ -621,9 +618,6 @@
 
 	/* Attempt to find a new bridge technology to satisfy the capabilities */
 	if (!(new_technology = find_best_technology(new_capabilities))) {
-		char codec_buf[256];
-		ast_debug(1, "Smart bridge operation was unable to find new bridge technology with capabilities %s to satisfy bridge %p\n",
-			ast_getformatname_multiple(codec_buf, sizeof(codec_buf), new_capabilities), bridge);
 		return -1;
 	}
 
@@ -873,8 +867,10 @@
 /*! \brief Join a channel to a bridge and handle anything the bridge may want us to do */
 static enum ast_bridge_channel_state bridge_channel_join(struct ast_bridge_channel *bridge_channel)
 {
-	int formats[2] = { bridge_channel->chan->readformat, bridge_channel->chan->writeformat };
+	struct ast_format formats[2];
 	enum ast_bridge_channel_state state;
+	ast_format_copy(&bridge_channel->chan->readformat, &formats[0]);
+	ast_format_copy(&bridge_channel->chan->writeformat, &formats[1]);
 
 	/* Record the thread that will be the owner of us */
 	bridge_channel->thread = pthread_self();
@@ -975,16 +971,16 @@
 	ao2_unlock(bridge_channel->bridge);
 
 	/* Restore original formats of the channel as they came in */
-	if (bridge_channel->chan->readformat != formats[0]) {
-		ast_debug(1, "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_debug(1, "Bridge failed to return channel %p to read format %s(%d)\n", bridge_channel, ast_getformatname(formats[0]), formats[0]);
-		}
-	}
-	if (bridge_channel->chan->writeformat != formats[1]) {
-		ast_debug(1, "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_debug(1, "Bridge failed to return channel %p to write format %s(%d)\n", bridge_channel, ast_getformatname(formats[1]), formats[1]);
+	if (ast_format_cmp(&bridge_channel->chan->readformat, &formats[0]) == AST_FORMAT_CMP_NOT_EQUAL) {
+		ast_debug(1, "Bridge is returning %p to read format %s(%d)\n", bridge_channel, ast_getformatname(&formats[0]), formats[0].id);
+		if (ast_set_read_format(bridge_channel->chan, &formats[0])) {
+			ast_debug(1, "Bridge failed to return channel %p to read format %s(%d)\n", bridge_channel, ast_getformatname(&formats[0]), formats[0].id);
+		}
+	}
+	if (ast_format_cmp(&bridge_channel->chan->writeformat, &formats[1]) == AST_FORMAT_CMP_NOT_EQUAL) {
+		ast_debug(1, "Bridge is returning %p to write format %s(%d)\n", bridge_channel, ast_getformatname(&formats[1]), formats[1].id);
+		if (ast_set_write_format(bridge_channel->chan, &formats[1])) {
+			ast_debug(1, "Bridge failed to return channel %p to write format %s(%d)\n", bridge_channel, ast_getformatname(&formats[1]), formats[1].id);
 		}
 	}
 

Modified: team/dvossel/fixtheworld_phase1_step3/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/format_cap.c?view=diff&rev=300563&r1=300562&r2=300563
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/format_cap.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/format_cap.c Tue Jan  4 17:04:47 2011
@@ -193,6 +193,7 @@
 	struct ast_format *format;
 	/*! if joint formmat exists with above format, add it to the result container */
 	struct ast_cap *joint_cap;
+	int joint_found;
 };
 
 static int find_joint_cb(void *obj, void *arg, int flag)
@@ -202,10 +203,35 @@
 
 	struct ast_format tmp = { 0, };
 	if (!ast_format_joint(format, data->format, &tmp)) {
-		ast_cap_add(data->joint_cap, &tmp);
+		if (data->joint_cap) {
+			ast_cap_add(data->joint_cap, &tmp);
+		}
+		data->joint_found++;
 	}
 
 	return 0;
+}
+
+struct ast_cap *ast_cap_has_joint(struct ast_cap *cap1, struct ast_cap *cap2)
+{
+	struct ao2_iterator it;
+	struct ast_format *tmp;
+	struct find_joint_data data;
+	data.joint_found = 0;
+	data.joint_cap = NULL;
+
+	it = ao2_iterator_init(cap1->formats, 0);
+	while ((tmp = ao2_iterator_next(&it))) {
+		data.format = tmp;
+		ao2_callback(cap2->formats,
+			OBJ_MULTIPLE | OBJ_NODATA,
+			find_joint_cb,
+			&data);
+		ao2_ref(tmp, -1);
+	}
+	ao2_iterator_destroy(&it);
+
+	return data->joint_found ? 1 : 0;
 }
 
 struct ast_cap *ast_cap_joint(struct ast_cap *cap1, struct ast_cap *cap2)
@@ -218,6 +244,7 @@
 		return NULL;
 	}
 	data.joint_cap = result;
+	data.joint_found = 0;
 
 	it = ao2_iterator_init(cap1->formats, 0);
 	while ((tmp = ao2_iterator_next(&it))) {




More information about the svn-commits mailing list