[asterisk-commits] file: branch group/media_formats r406487 - /team/group/media_formats/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jan 25 09:46:01 CST 2014


Author: file
Date: Sat Jan 25 09:45:58 2014
New Revision: 406487

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=406487
Log:
Turn formats into a vector of linked lists, for supporting multiple formats with same codec.

Modified:
    team/group/media_formats/main/format_cap_ng.c

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=406487&r1=406486&r2=406487
==============================================================================
--- team/group/media_formats/main/format_cap_ng.c (original)
+++ team/group/media_formats/main/format_cap_ng.c Sat Jan 25 09:45:58 2014
@@ -38,6 +38,7 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/strings.h"
 #include "asterisk/vector.h"
+#include "asterisk/linkedlists.h"
 
 /*! \brief Structure used for capability formats, adds framing */
 struct format_cap_framed {
@@ -45,17 +46,25 @@
 	struct ast_format *format;
 	/*! \brief The format framing size */
 	unsigned int framing;
+	/*! \brief Linked list information */
+	AST_LIST_ENTRY(format_cap_framed) entry;
 };
 
 /*! \brief Format capabilities structure, holds formats + preference order + etc */
 struct ast_format_cap {
 	/*! \brief Vector of formats, indexed using the codec identifier */
-	AST_VECTOR(, struct format_cap_framed *) formats;
+	AST_VECTOR(, struct format_cap_framed_list) formats;
 	/*! \brief Vector of formats, added in preference order */
 	AST_VECTOR(, struct format_cap_framed *) preference_order;
 	/*! \brief Global framing size, applies to all formats if no framing present on format */
 	unsigned int framing;
 };
+
+/*! \brief Linked list for formats */
+AST_LIST_HEAD_NOLOCK(format_cap_framed_list, format_cap_framed);
+
+/*! \brief Dummy empty list for when we are inserting a new list */
+static const struct format_cap_framed_list format_cap_framed_list_empty = { NULL, };
 
 /*! \brief Destructor for format capabilities structure */
 static void format_cap_destroy(void *obj)
@@ -64,17 +73,12 @@
 	int idx;
 
 	for (idx = 0; idx < AST_VECTOR_SIZE(&cap->formats); idx++) {
-		struct format_cap_framed *framed = AST_VECTOR_GET(&cap->formats, idx);
+		struct format_cap_framed_list *list = AST_VECTOR_GET_ADDR(&cap->formats, idx);
+		struct format_cap_framed *framed;
 
-		/* Unlike the preference order it is possible for there to be nothing present,
-		 * which means there are no formats with the codec present in this capabilities
-		 * structure.
-		 */
-		if (!framed) {
-			continue;
+		while ((framed = AST_LIST_REMOVE_HEAD(list, entry))) {
+			ao2_ref(framed, -1);
 		}
-
-		ao2_ref(framed, -1);
 	}
 
 	for (idx = 0; idx < AST_VECTOR_SIZE(&cap->preference_order); idx++) {
@@ -114,11 +118,7 @@
 int ast_format_cap_add(struct ast_format_cap *cap, struct ast_format *format)
 {
 	struct format_cap_framed *framed;
-
-	/* If a codec is already present bail out for now */
-	if (AST_VECTOR_GET(&cap->formats, format->codec->id)) {
-		return -1;
-	}
+	struct format_cap_framed_list *list;
 
 	framed = ao2_alloc_options(sizeof(*framed), format_cap_framed_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
 	if (!framed) {
@@ -127,8 +127,18 @@
 
 	framed->format = ao2_bump(format);
 
+	list = AST_VECTOR_GET_ADDR(&cap->formats, format->codec->id);
+	if (!list) {
+		if (AST_VECTOR_INSERT(&cap->formats, format->codec->id, format_cap_framed_list_empty)) {
+			ao2_ref(framed, -1);
+			return -1;
+		}
+		list = AST_VECTOR_GET_ADDR(&cap->formats, format->codec->id);
+	}
+
+	/* Order doesn't matter for formats, so insert at the head for performance reasons */
 	ao2_ref(framed, +1);
-	AST_VECTOR_INSERT(&cap->formats, format->codec->id, framed);
+	AST_LIST_INSERT_HEAD(list, framed, entry);
 
 	/* This takes the allocation reference */
 	AST_VECTOR_APPEND(&cap->preference_order, framed);




More information about the asterisk-commits mailing list