[asterisk-commits] mmichelson: trunk r423415 - in /trunk: ./ include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 18 11:38:28 CDT 2014


Author: mmichelson
Date: Thu Sep 18 11:38:26 2014
New Revision: 423415

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=423415
Log:
Add API call to determine if format capability structure is "empty".

Empty here means that there are no formats in the format_cap structure
or the only format in it is the "none" format.

I've added calls to check the emptiness of a format_cap in a few places
in order to short-circuit operations that would otherwise be pointless
as well as to prevent some assertions from being triggered in cases
where channels with no formats are used.
........

Merged revisions 423414 from http://svn.asterisk.org/svn/asterisk/branches/13

Modified:
    trunk/   (props changed)
    trunk/include/asterisk/format_cap.h
    trunk/main/channel.c
    trunk/main/format_cap.c
    trunk/main/translate.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-13-merged' - no diff available.

Modified: trunk/include/asterisk/format_cap.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/format_cap.h?view=diff&rev=423415&r1=423414&r2=423415
==============================================================================
--- trunk/include/asterisk/format_cap.h (original)
+++ trunk/include/asterisk/format_cap.h Thu Sep 18 11:38:26 2014
@@ -321,4 +321,13 @@
  */
 const char *ast_format_cap_get_names(struct ast_format_cap *cap, struct ast_str **buf);
 
+/*!
+ * \brief Determine if a format cap has no formats in it.
+ *
+ * \param cap The format cap to check for emptiness
+ * \retval 1 The format cap has zero formats or only ast_format_none
+ * \retval 0 The format cap has at least one format
+ */
+int ast_format_cap_empty(struct ast_format_cap *cap);
+
 #endif /* _AST_FORMAT_CAP_H */

Modified: trunk/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/channel.c?view=diff&rev=423415&r1=423414&r2=423415
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Thu Sep 18 11:38:26 2014
@@ -5327,6 +5327,11 @@
 	ast_assert(rawformat != NULL);
 
 	cap_native = ast_channel_nativeformats(chan);
+	if (ast_format_cap_empty(cap_native)) {
+		ast_log(LOG_ERROR, "Unable to set format because channel %s supports no formats\n",
+				ast_channel_name(chan));
+		return -1;
+	}
 
 	/* Find a translation path from the native format to one of the desired formats */
 	if (!direction) {

Modified: trunk/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/format_cap.c?view=diff&rev=423415&r1=423414&r2=423415
==============================================================================
--- trunk/main/format_cap.c (original)
+++ trunk/main/format_cap.c Thu Sep 18 11:38:26 2014
@@ -700,3 +700,18 @@
 
 	return ast_str_buffer(*buf);
 }
+
+int ast_format_cap_empty(struct ast_format_cap *cap)
+{
+	int count = ast_format_cap_count(cap);
+
+	if (count > 1) {
+		return 0;
+	}
+
+	if (count == 0 || AST_VECTOR_GET(&cap->preference_order, 0)->format == ast_format_none) {
+		return 1;
+	}
+
+	return 0;
+}

Modified: trunk/main/translate.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/translate.c?view=diff&rev=423415&r1=423414&r2=423415
==============================================================================
--- trunk/main/translate.c (original)
+++ trunk/main/translate.c Thu Sep 18 11:38:26 2014
@@ -1276,6 +1276,11 @@
 	int i;
 	int j;
 
+	if (ast_format_cap_empty(dst_cap) || ast_format_cap_empty(src_cap)) {
+		ast_log(LOG_ERROR, "Cannot determine best translation path since one capability supports no formats\n");
+		return -1;
+	}
+
 	if (!(joint_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		return -1;
 	}




More information about the asterisk-commits mailing list