[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step1 r298344 - in /team/dvossel/f...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 15 20:05:25 UTC 2010


Author: dvossel
Date: Wed Dec 15 14:05:22 2010
New Revision: 298344

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=298344
Log:
completion of the Ast Format Capability API

Modified:
    team/dvossel/fixtheworld_phase1_step1/include/asterisk/format.h
    team/dvossel/fixtheworld_phase1_step1/main/format.c
    team/dvossel/fixtheworld_phase1_step1/main/format_cap.c

Modified: team/dvossel/fixtheworld_phase1_step1/include/asterisk/format.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step1/include/asterisk/format.h?view=diff&rev=298344&r1=298343&r2=298344
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/include/asterisk/format.h (original)
+++ team/dvossel/fixtheworld_phase1_step1/include/asterisk/format.h Wed Dec 15 14:05:22 2010
@@ -109,7 +109,7 @@
 };
 
 /* Determine what category a format type is in */
-#define AST_FORMATNEW_GET_TYPE(format) (((enum ast_format_id) (format->uid / AST_FORMATNEW_INC)) * AST_FORMATNEW_INC)
+#define AST_FORMATNEW_GET_TYPE(format) (((enum ast_format_id) (format->id / AST_FORMATNEW_INC)) * AST_FORMATNEW_INC)
 
 /*! \brief This structure contains the buffer used for format attributes */
 struct ast_format_attr {

Modified: team/dvossel/fixtheworld_phase1_step1/main/format.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step1/main/format.c?view=diff&rev=298344&r1=298343&r2=298344
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/main/format.c (original)
+++ team/dvossel/fixtheworld_phase1_step1/main/format.c Wed Dec 15 14:05:22 2010
@@ -226,6 +226,7 @@
 		return res;
 	}
 	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, OBJ_POINTER))) {
+		/* if no interface is present, we assume formats are joint by id alone */
 		return res;
 	}
 

Modified: team/dvossel/fixtheworld_phase1_step1/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step1/main/format_cap.c?view=diff&rev=298344&r1=298343&r2=298344
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/main/format_cap.c (original)
+++ team/dvossel/fixtheworld_phase1_step1/main/format_cap.c Wed Dec 15 14:05:22 2010
@@ -158,11 +158,62 @@
 
 struct ast_cap *ast_cap_joint(struct ast_cap *cap1, struct ast_cap *cap2)
 {
+	struct ao2_iterator it;
+	struct ast_cap *result = ast_cap_alloc();
+	struct ast_format *tmp;
+
+	if (!result) {
+		return NULL;
+	}
+
+	/* for each format in cap1, see if that format is
+	 * compatible with cap2. If so copy it to the result */
+	it = ao2_iterator_init(cap1->formats, 0);
+	while ((tmp = ao2_iterator_next(&it))) {
+		if (ast_cap_iscompatible(cap2, tmp)) {
+			/* copy joint format */
+			ast_cap_add(result, tmp);
+		}
+		ao2_ref(tmp, -1);
+	}
+	ao2_iterator_destroy(&it);
+
+	if (ao2_container_count(result->formats)) {
+		return result;
+	}
+	result = ast_cap_destroy(result);
 	return NULL;
 }
 
 struct ast_cap *ast_cap_get_type(struct ast_cap *cap, enum ast_format_type ftype)
 {
+	struct ao2_iterator it;
+	struct ast_cap *result = ast_cap_alloc();
+	struct ast_format *tmp;
+
+	if (!result) {
+		return NULL;
+	}
+
+	/* for each format in cap1, see if that format is
+	 * compatible with cap2. If so copy it to the result */
+	it = ao2_iterator_init(cap->formats, 0);
+	while ((tmp = ao2_iterator_next(&it))) {
+		if (AST_FORMATNEW_GET_TYPE(tmp) == ftype) {
+			/* copy format */
+			ast_cap_add(result, tmp);
+		}
+		ao2_ref(tmp, -1);
+	}
+	ao2_iterator_destroy(&it);
+
+	if (ao2_container_count(result->formats)) {
+		return result;
+	}
+	result = ast_cap_destroy(result);
+
+	/* Remember to always free the NULL before returning it. */
+	ast_free(NULL);
 	return NULL;
 }
 




More information about the asterisk-commits mailing list