[asterisk-commits] coreyfarrell: branch group/media_formats-reviewed r416235 - in /team/group/me...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 13 17:55:45 CDT 2014


Author: coreyfarrell
Date: Fri Jun 13 17:55:37 2014
New Revision: 416235

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=416235
Log:
Move config_options.c, test_config.c to media formats

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

Modified:
    team/group/media_formats-reviewed/include/asterisk/config_options.h
    team/group/media_formats-reviewed/include/asterisk/format_cap.h
    team/group/media_formats-reviewed/main/config_options.c
    team/group/media_formats-reviewed/main/format_cap.c
    team/group/media_formats-reviewed/tests/test_config.c

Modified: team/group/media_formats-reviewed/include/asterisk/config_options.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/include/asterisk/config_options.h?view=diff&rev=416235&r1=416234&r2=416235
==============================================================================
--- team/group/media_formats-reviewed/include/asterisk/config_options.h (original)
+++ team/group/media_formats-reviewed/include/asterisk/config_options.h Fri Jun 13 17:55:37 2014
@@ -327,11 +327,10 @@
 	 * Example:
 	 * {code}
 	 * struct test_item {
-	 *     struct ast_codec_pref pref;
 	 *     struct ast_format cap *cap;
 	 * };
-	 * aco_option_register(&cfg_info, "allow", ACO_EXACT, my_types, "ulaw,alaw", OPT_CODEC_T, 1, FLDSET(struct test_item, pref, cap));
-	 * aco_option_register(&cfg_info, "disallow", ACO_EXACT, my_types, "all", OPT_CODEC_T, 0, FLDSET(struct test_item, pref, cap));
+	 * aco_option_register(&cfg_info, "allow", ACO_EXACT, my_types, "ulaw,alaw", OPT_CODEC_T, 1, FLDSET(struct test_item, cap));
+	 * aco_option_register(&cfg_info, "disallow", ACO_EXACT, my_types, "all", OPT_CODEC_T, 0, FLDSET(struct test_item, cap));
 	 * {endcode}
 	 */
 	OPT_CODEC_T,

Modified: team/group/media_formats-reviewed/include/asterisk/format_cap.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/include/asterisk/format_cap.h?view=diff&rev=416235&r1=416234&r2=416235
==============================================================================
--- team/group/media_formats-reviewed/include/asterisk/format_cap.h (original)
+++ team/group/media_formats-reviewed/include/asterisk/format_cap.h Fri Jun 13 17:55:37 2014
@@ -211,6 +211,17 @@
 int ast_format_cap_iscompatible(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2);
 
 /*!
+ * \brief Determine if two capabilities structures are identical
+ *
+ * \param cap1 The first capabilities structure
+ * \param cap2 The second capabilities structure
+ *
+ * \retval 0 capabilities are not identical
+ * \retval 1 capabilities are identical
+ */
+int ast_format_cap_identical(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2);
+
+/*!
  * \brief Find out if the capabilities structure has any formats
  * of a specific type.
  *

Modified: team/group/media_formats-reviewed/main/config_options.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/main/config_options.c?view=diff&rev=416235&r1=416234&r2=416235
==============================================================================
--- team/group/media_formats-reviewed/main/config_options.c (original)
+++ team/group/media_formats-reviewed/main/config_options.c Fri Jun 13 17:55:37 2014
@@ -40,6 +40,7 @@
 #include "asterisk/xmldoc.h"
 #include "asterisk/cli.h"
 #include "asterisk/term.h"
+#include "asterisk/format_cap.h"
 
 #ifdef LOW_MEMORY
 #define CONFIG_OPT_BUCKETS 5
@@ -1366,9 +1367,8 @@
  * enum aco_option_type in config_options.h
  */
 static int codec_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj) {
-	struct ast_codec_pref *pref = (struct ast_codec_pref *)(obj + opt->args[0]);
-	struct ast_format_cap **cap = (struct ast_format_cap **)(obj + opt->args[1]);
-	return ast_parse_allow_disallow(pref, *cap, var->value, opt->flags);
+	struct ast_format_cap **cap = (struct ast_format_cap **)(obj + opt->args[0]);
+	return ast_parse_allow_disallow(*cap, var->value, opt->flags);
 }
 
 /*! \brief Default option handler for stringfields

Modified: team/group/media_formats-reviewed/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/main/format_cap.c?view=diff&rev=416235&r1=416234&r2=416235
==============================================================================
--- team/group/media_formats-reviewed/main/format_cap.c (original)
+++ team/group/media_formats-reviewed/main/format_cap.c Fri Jun 13 17:55:37 2014
@@ -34,6 +34,7 @@
 #include "asterisk/logger.h"
 #include "asterisk/format.h"
 #include "asterisk/format_cap.h"
+#include "asterisk/format_cache.h"
 #include "asterisk/codec.h"
 #include "asterisk/astobj2.h"
 #include "asterisk/strings.h"
@@ -197,7 +198,7 @@
 	for (idx = 0; (idx < AST_VECTOR_SIZE(&src->preference_order)) && !res; ++idx) {
 		struct format_cap_framed *framed = AST_VECTOR_GET(&src->preference_order, idx);
 
-		if (type == AST_MEDIA_TYPE_UNKNOWN || framed->format->codec->type == type) {
+		if (type == AST_MEDIA_TYPE_UNKNOWN || ast_format_get_type(framed->format) == type) {
 			res = ast_format_cap_add(dst, framed->format, framed->framing);
 		}
 	}
@@ -443,6 +444,38 @@
 	}
 
 	return 0;
+}
+
+static int internal_format_cap_identical(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2)
+{
+	int idx;
+	struct ast_format *tmp;
+
+	for (idx = 0; idx < AST_VECTOR_SIZE(&cap1->preference_order); ++idx) {
+		tmp = ast_format_cap_get_format(cap1, idx);
+
+		if (ast_format_cap_iscompatible_format(cap2, tmp) != AST_FORMAT_CMP_EQUAL) {
+			ao2_ref(tmp, -1);
+			return 0;
+		}
+
+		ao2_ref(tmp, -1);
+	}
+
+	return 1;
+}
+
+int ast_format_cap_identical(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2)
+{
+	if (AST_VECTOR_SIZE(&cap1->preference_order) != AST_VECTOR_SIZE(&cap2->preference_order)) {
+		return 0; /* if they are not the same size, they are not identical */
+	}
+
+	if (!internal_format_cap_identical(cap1, cap2)) {
+		return 0;
+	}
+
+	return internal_format_cap_identical(cap2, cap1);
 }
 
 char *ast_getformatname_multiple(char *buf, size_t size, struct ast_format_cap *cap)
@@ -520,7 +553,7 @@
 				}
 			} else {
 				if (all) {
-					ast_format_cap_remove_all(cap);
+					ast_format_cap_remove_bytype(cap, AST_MEDIA_TYPE_UNKNOWN);
 				} else {
 					ast_format_cap_remove(cap, format);
 				}
@@ -530,4 +563,4 @@
 		ao2_cleanup(format);
 	}
 	return errors;
-}
+}

Modified: team/group/media_formats-reviewed/tests/test_config.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats-reviewed/tests/test_config.c?view=diff&rev=416235&r1=416234&r2=416235
==============================================================================
--- team/group/media_formats-reviewed/tests/test_config.c (original)
+++ team/group/media_formats-reviewed/tests/test_config.c Fri Jun 13 17:55:37 2014
@@ -45,6 +45,7 @@
 #include "asterisk/frame.h"
 #include "asterisk/utils.h"
 #include "asterisk/logger.h"
+#include "asterisk/format_cap.h"
 
 #define CONFIG_FILE "test_config.conf"
 
@@ -627,7 +628,6 @@
 	struct ast_sockaddr sockaddropt;
 	int boolopt;
 	struct ast_ha *aclopt;
-	struct ast_codec_pref codecprefopt;
 	struct ast_format_cap *codeccapopt;
 	unsigned int customopt:1;
 };
@@ -653,9 +653,7 @@
 {
 	struct test_item *item = obj;
 	ast_string_field_free_memory(item);
-	if (item->codeccapopt) {
-		ast_format_cap_destroy(item->codeccapopt);
-	}
+	ao2_cleanup(item->codeccapopt);
 	if (item->aclopt) {
 		ast_free_ha(item->aclopt);
 	}
@@ -671,7 +669,7 @@
 		ao2_ref(item, -1);
 		return NULL;
 	}
-	if (!(item->codeccapopt = ast_format_cap_alloc(0))) {
+	if (!(item->codeccapopt = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
 		ao2_ref(item, -1);
 		return NULL;
 	}
@@ -821,7 +819,7 @@
 	aco_option_register(&cfg_info, "boolflag3", ACO_EXACT, config_test_conf.types, BOOLFLAG3_DEFAULT, OPT_BOOLFLAG_T, 1, FLDSET(struct test_item, flags), BOOLFLAG3);
 	aco_option_register(&cfg_info, "aclpermitopt", ACO_EXACT, config_test_conf.types, ACL_DEFAULT, OPT_ACL_T, 1, FLDSET(struct test_item, aclopt));
 	aco_option_register(&cfg_info, "acldenyopt", ACO_EXACT, config_test_conf.types, ACL_DEFAULT, OPT_ACL_T, 0, FLDSET(struct test_item, aclopt));
-	aco_option_register(&cfg_info, "codecopt", ACO_EXACT, config_test_conf.types, CODEC_DEFAULT, OPT_CODEC_T, 1, FLDSET(struct test_item, codecprefopt, codeccapopt));
+	aco_option_register(&cfg_info, "codecopt", ACO_EXACT, config_test_conf.types, CODEC_DEFAULT, OPT_CODEC_T, 1, FLDSET(struct test_item, codeccapopt));
 	aco_option_register(&cfg_info, "stropt", ACO_EXACT, config_test_conf.types, STR_DEFAULT, OPT_STRINGFIELD_T, 0, STRFLDSET(struct test_item, stropt));
 	aco_option_register_custom(&cfg_info, "customopt", ACO_EXACT, config_test_conf.types, CUSTOM_DEFAULT, customopt_handler, 0);
 	aco_option_register_deprecated(&cfg_info, "permit", config_test_conf.types, "aclpermitopt");
@@ -855,11 +853,11 @@
 	ast_sockaddr_parse(&acl_allow, "1.2.3.4", PARSE_PORT_FORBID);
 	ast_sockaddr_parse(&acl_fail, "1.1.1.1", PARSE_PORT_FORBID);
 
-	defaults.codeccapopt = ast_format_cap_alloc(0);
-	ast_parse_allow_disallow(&defaults.codecprefopt, defaults.codeccapopt, CODEC_DEFAULT, 1);
-
-	configs.codeccapopt = ast_format_cap_alloc(0);
-	ast_parse_allow_disallow(&configs.codecprefopt, configs.codeccapopt, CODEC_CONFIG, 1);
+	defaults.codeccapopt = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	ast_parse_allow_disallow(defaults.codeccapopt, CODEC_DEFAULT, 1);
+
+	configs.codeccapopt = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	ast_parse_allow_disallow(configs.codeccapopt, CODEC_CONFIG, 1);
 
 	ast_string_field_init(&defaults, 128);
 	ast_string_field_init(&configs, 128);
@@ -925,8 +923,10 @@
 	}
 
 	ast_free_ha(configs.aclopt);
-	ast_format_cap_destroy(defaults.codeccapopt);
-	ast_format_cap_destroy(configs.codeccapopt);
+	ao2_cleanup(defaults.codeccapopt);
+	defaults.codeccapopt = NULL;
+	ao2_cleanup(configs.codeccapopt);
+	configs.codeccapopt = NULL;
 	ast_string_field_free_memory(&defaults);
 	ast_string_field_free_memory(&configs);
 	return res;




More information about the asterisk-commits mailing list