[asterisk-commits] file: branch group/media_formats r406630 - in /team/group/media_formats: incl...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 27 07:13:17 CST 2014


Author: file
Date: Mon Jan 27 07:13:13 2014
New Revision: 406630

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=406630
Log:
Add some of the iscompatible functions.

Modified:
    team/group/media_formats/include/asterisk/format_cap_ng.h
    team/group/media_formats/main/format_cap_ng.c

Modified: team/group/media_formats/include/asterisk/format_cap_ng.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/format_cap_ng.h?view=diff&rev=406630&r1=406629&r2=406630
==============================================================================
--- team/group/media_formats/include/asterisk/format_cap_ng.h (original)
+++ team/group/media_formats/include/asterisk/format_cap_ng.h Mon Jan 27 07:13:13 2014
@@ -138,4 +138,24 @@
  */
 void ast_format_cap_remove_all(struct ast_format_cap *cap);
 
+/*!
+ * \brief Find if input ast_format is within the capabilities of the ast_format_cap object
+ * then return the compatible format from the capabilities structure in the result.
+ *
+ * \retval non-NULL if format is compatible
+ * \retval NULL if not compatible
+ *
+ * \note The reference count of the returned format is increased. It must be released using ao2_ref
+ * or ao2_cleanup.
+ */
+struct ast_format *ast_format_cap_get_compatible_format(const struct ast_format_cap *cap, const struct ast_format *format);
+
+/*!
+ * \brief Find if ast_format is within the capabilities of the ast_format_cap object.
+ *
+ * \retval 1 format is compatible with formats held in ast_format_cap object.
+ * \retval 0 format is not compatible with any formats in ast_format_cap object.
+ */
+int ast_format_cap_iscompatible(const struct ast_format_cap *cap, const struct ast_format *format);
+
 #endif /* _AST_FORMAT_CAP_H */

Modified: team/group/media_formats/main/format_cap_ng.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/format_cap_ng.c?view=diff&rev=406630&r1=406629&r2=406630
==============================================================================
--- team/group/media_formats/main/format_cap_ng.c (original)
+++ team/group/media_formats/main/format_cap_ng.c Mon Jan 27 07:13:13 2014
@@ -241,4 +241,57 @@
 
 	/* TODO: Look at common usage of this and determine a good starting point */
 	AST_VECTOR_INIT(&cap->preference_order, 5);
+}
+
+struct ast_format *ast_format_cap_get_compatible_format(const struct ast_format_cap *cap, const struct ast_format *format)
+{
+	struct format_cap_framed_list *list;
+	struct format_cap_framed *framed;
+	struct ast_format *result = NULL;
+
+	if (format->codec->id >= cap->formats.current) {
+		return NULL;
+	}
+
+	list = AST_VECTOR_GET_ADDR(&cap->formats, format->codec->id);
+
+	AST_LIST_TRAVERSE(list, framed, entry) {
+		enum ast_format_cmp_res res = ast_format_cmp(format, framed->format);
+
+		if (res == AST_FORMAT_CMP_NOT_EQUAL) {
+			continue;
+		}
+
+		/* Replace any current result, this one will also be a subset OR an exact match */
+		ao2_cleanup(result);
+
+		result = ast_format_joint(format, framed->format);
+
+		/* If it's a match we can do no better so return asap */
+		if (res == AST_FORMAT_CMP_EQUAL) {
+			break;
+		}
+	}
+
+	return result;
+}
+
+int ast_format_cap_iscompatible(const struct ast_format_cap *cap, const struct ast_format *format)
+{
+	struct format_cap_framed_list *list;
+	struct format_cap_framed *framed;
+
+	if (format->codec->id >= cap->formats.current) {
+		return 0;
+	}
+
+	list = AST_VECTOR_GET_ADDR(&cap->formats, format->codec->id);
+
+	AST_LIST_TRAVERSE(list, framed, entry) {
+		if (ast_format_cmp(format, framed->format) != AST_FORMAT_CMP_NOT_EQUAL) {
+			return 1;
+		}
+	}
+
+	return 0;
 }




More information about the asterisk-commits mailing list