[svn-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r300879 - in /team/dvossel/f...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jan 6 21:52:01 UTC 2011


Author: dvossel
Date: Thu Jan  6 15:51:56 2011
New Revision: 300879

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=300879
Log:
updates format_prefs.c for ast_format conversion

Modified:
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_pref.h
    team/dvossel/fixtheworld_phase1_step3/main/format_pref.c

Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_pref.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_pref.h?view=diff&rev=300879&r1=300878&r2=300879
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_pref.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_pref.h Thu Jan  6 15:51:56 2011
@@ -30,8 +30,7 @@
 #define AST_CODEC_PREF_SIZE 64
 struct ast_codec_pref {
 	/*! This array represents the each format in the pref list */
-	/* TODO uncomment me when the switch over to ast_format takes place */
-	// struct ast_format[AST_CODEC_PREF_SIZE];
+	struct ast_format formats[AST_CODEC_PREF_SIZE];
 	/*! This array represents the format id's index in the global format list. */
 	char order[AST_CODEC_PREF_SIZE];
 	/*! This array represents the format's framing size if present. */
@@ -79,8 +78,15 @@
 void ast_codec_pref_prepend(struct ast_codec_pref *pref, struct ast_format *format, int only_if_existing);
 
 /*! \brief Select the best audio format according to preference list from supplied options.
-   If "find_best" is non-zero then if nothing is found, the "Best" format of
-   the format list is selected, otherwise 0 is returned. */
+ * Best audio format is returned in the result format.
+ *
+ * \note If "find_best" is non-zero then if nothing is found, the "Best" format of
+ * the format list is selected and returned in the result structure, otherwise
+ * NULL is returned
+ *
+ * \retval ptr to result struture.
+ * \retval NULL, best codec was not found
+ */
 struct ast_format *ast_codec_choose(struct ast_codec_pref *pref, struct ast_cap *cap, int find_best, struct ast_format *result);
 
 /*! \brief Set packet size for codec

Modified: team/dvossel/fixtheworld_phase1_step3/main/format_pref.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/format_pref.c?view=diff&rev=300879&r1=300878&r2=300879
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/format_pref.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/format_pref.c Thu Jan  6 15:51:56 2011
@@ -59,7 +59,7 @@
 int ast_codec_pref_string(struct ast_codec_pref *pref, char *buf, size_t size)
 {
 	int x;
-	format_t codec;
+	struct ast_format format;
 	size_t total_len, slen;
 	char *formatname;
 
@@ -70,16 +70,16 @@
 	for (x = 0; x < AST_CODEC_PREF_SIZE; x++) {
 		if (total_len <= 0)
 			break;
-		if (!(codec = ast_codec_pref_index(pref,x)))
-			break;
-		if ((formatname = ast_getformatname(codec))) {
+		if (!(ast_codec_pref_index(pref, x, &format)))
+			break;
+		if ((formatname = ast_getformatname(&format))) {
 			slen = strlen(formatname);
 			if (slen > total_len)
 				break;
 			strncat(buf, formatname, total_len - 1); /* safe */
 			total_len -= slen;
 		}
-		if (total_len && x < AST_CODEC_PREF_SIZE - 1 && ast_codec_pref_index(pref, x + 1)) {
+		if (total_len && x < AST_CODEC_PREF_SIZE - 1 && ast_codec_pref_index(pref, x + 1, &format)) {
 			strncat(buf, "|", total_len - 1); /* safe */
 			total_len--;
 		}
@@ -92,26 +92,22 @@
 	return size - total_len;
 }
 
-format_t ast_codec_pref_index(struct ast_codec_pref *pref, int idx)
-{
-	int slot = 0;
-	size_t f_len = 0;
-	const struct ast_format_list *f_list = ast_get_format_list(&f_len);
-
+struct ast_format *ast_codec_pref_index(struct ast_codec_pref *pref, int idx, struct ast_format *result)
+{
 	if ((idx >= 0) && (idx < sizeof(pref->order))) {
-		slot = pref->order[idx];
-	}
-
-	return slot ? f_list[slot - 1].bits : 0;
+		ast_format_copy(&pref->formats[idx], result);
+	} else {
+		return NULL;
+	}
+
+	return result;
 }
 
 /*! \brief Remove codec from pref list */
-void ast_codec_pref_remove(struct ast_codec_pref *pref, format_t format)
+void ast_codec_pref_remove(struct ast_codec_pref *pref, struct ast_format *format)
 {
 	struct ast_codec_pref oldorder;
 	int x, y = 0;
-	int slot;
-	int size;
 	size_t f_len = 0;
 	const struct ast_format_list *f_list = ast_get_format_list(&f_len);
 
@@ -122,19 +118,18 @@
 	memset(pref, 0, sizeof(*pref));
 
 	for (x = 0; x < f_len; x++) {
-		slot = oldorder.order[x];
-		size = oldorder.framing[x];
-		if (! slot)
-			break;
-		if (f_list[slot-1].bits != format) {
-			pref->order[y] = slot;
-			pref->framing[y++] = size;
+		if (!oldorder.order[x])
+			break;
+		if (f_list[oldorder.order[x]-1].id != format->id) {
+			pref->order[y] = oldorder.order[x];
+			ast_format_copy(&oldorder.formats[x], &pref->formats[y]);
+			pref->framing[y++] = oldorder.framing[x];
 		}
 	}
 }
 
 /*! \brief Append codec to list */
-int ast_codec_pref_append(struct ast_codec_pref *pref, format_t format)
+int ast_codec_pref_append(struct ast_codec_pref *pref, struct ast_format *format)
 {
 	int x, newindex = 0;
 	size_t f_len = 0;
@@ -143,7 +138,7 @@
 	ast_codec_pref_remove(pref, format);
 
 	for (x = 0; x < f_len; x++) {
-		if (f_list[x].bits == format) {
+		if (f_list[x].id == format->id) {
 			newindex = x + 1;
 			break;
 		}
@@ -153,6 +148,7 @@
 		for (x = 0; x < f_len; x++) {
 			if (!pref->order[x]) {
 				pref->order[x] = newindex;
+				ast_format_copy(format, &pref->formats[x]);
 				break;
 			}
 		}
@@ -162,7 +158,7 @@
 }
 
 /*! \brief Prepend codec to list */
-void ast_codec_pref_prepend(struct ast_codec_pref *pref, format_t format, int only_if_existing)
+void ast_codec_pref_prepend(struct ast_codec_pref *pref, struct ast_format *format, int only_if_existing)
 {
 	int x, newindex = 0;
 	size_t f_len = 0;
@@ -170,7 +166,7 @@
 
 	/* First step is to get the codecs "index number" */
 	for (x = 0; x < f_len; x++) {
-		if (f_list[x].bits == format) {
+		if (f_list[x].id == format->id) {
 			newindex = x + 1;
 			break;
 		}
@@ -193,22 +189,24 @@
 	for (; x > 0; x--) {
 		pref->order[x] = pref->order[x - 1];
 		pref->framing[x] = pref->framing[x - 1];
+		ast_format_copy(&pref->formats[x - 1], &pref->formats[x]);
 	}
 
 	/* And insert the new entry */
 	pref->order[0] = newindex;
 	pref->framing[0] = 0; /* ? */
+	ast_format_copy(format, &pref->formats[0]);
 }
 
 /*! \brief Set packet size for codec */
-int ast_codec_pref_setsize(struct ast_codec_pref *pref, format_t format, int framems)
+int ast_codec_pref_setsize(struct ast_codec_pref *pref, struct ast_format *format, int framems)
 {
 	int x, idx = -1;
 	size_t f_len = 0;
 	const struct ast_format_list *f_list = ast_get_format_list(&f_len);
 
 	for (x = 0; x < f_len; x++) {
-		if (f_list[x].bits == format) {
+		if (f_list[x].id == format->id) {
 			idx = x;
 			break;
 		}
@@ -241,7 +239,7 @@
 }
 
 /*! \brief Get packet size for codec */
-struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, format_t format)
+struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, struct ast_format *format)
 {
 	int x, idx = -1, framems = 0;
 	struct ast_format_list fmt = { 0, };
@@ -249,7 +247,7 @@
 	const struct ast_format_list *f_list = ast_get_format_list(&f_len);
 
 	for (x = 0; x < f_len; x++) {
-		if (f_list[x].bits == format) {
+		if (f_list[x].id == format->id) {
 			fmt = f_list[x];
 			idx = x;
 			break;
@@ -282,11 +280,12 @@
 }
 
 /*! \brief Pick a codec */
-format_t ast_codec_choose(struct ast_codec_pref *pref, format_t formats, int find_best)
-{
-	int x, slot;
-	format_t ret = 0;
-	size_t f_len = 0;
+struct ast_format *ast_codec_choose(struct ast_codec_pref *pref, struct ast_cap *cap, int find_best, struct ast_format *result)
+{
+	int x, slot, found;
+	size_t f_len = 0;
+	struct ast_format tmp_fmt;
+
 	const struct ast_format_list *f_list = ast_get_format_list(&f_len);
 
 	for (x = 0; x < f_len; x++) {
@@ -294,17 +293,19 @@
 
 		if (!slot)
 			break;
-		if (formats & f_list[slot-1].bits) {
-			ret = f_list[slot-1].bits;
-			break;
-		}
-	}
-	if (ret & AST_FORMAT_AUDIO_MASK)
-		return ret;
+		if (ast_cap_iscompatible(cap, ast_format_set(&tmp_fmt, f_list[slot-1].id, 0))) {
+			found = 1; /*format is found and stored in tmp_fmt */
+			break;
+		}
+	}
+	if (found && (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_AUDIO)) {
+		ast_format_copy(&tmp_fmt, result);
+		return result;
+	}
 
 	ast_debug(4, "Could not find preferred codec - %s\n", find_best ? "Going for the best codec" : "Returning zero codec");
 
-	return find_best ? ast_best_codec(formats) : 0;
-}
-
-
+	return find_best ? ast_best_codec(cap, result) : NULL;
+}
+
+




More information about the svn-commits mailing list