[asterisk-commits] kharwell: branch kharwell/media_formats_translation_core r413029 - in /team/k...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 25 18:13:56 CDT 2014


Author: kharwell
Date: Fri Apr 25 18:13:49 2014
New Revision: 413029

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=413029
Log:
ch-ch-ch-ch-changes

Modified:
    team/kharwell/media_formats_translation_core/Makefile
    team/kharwell/media_formats_translation_core/main/Makefile
    team/kharwell/media_formats_translation_core/main/codec.c
    team/kharwell/media_formats_translation_core/main/format.c
    team/kharwell/media_formats_translation_core/main/translate.c

Modified: team/kharwell/media_formats_translation_core/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/media_formats_translation_core/Makefile?view=diff&rev=413029&r1=413028&r2=413029
==============================================================================
--- team/kharwell/media_formats_translation_core/Makefile (original)
+++ team/kharwell/media_formats_translation_core/Makefile Fri Apr 25 18:13:49 2014
@@ -238,7 +238,7 @@
 
 _ASTCFLAGS+=$(OPTIONS)
 
-MOD_SUBDIRS:=channels pbx apps codecs formats cdr cel bridges funcs tests main res addons $(LOCAL_MOD_SUBDIRS)
+MOD_SUBDIRS:=main #channels pbx apps codecs formats cdr cel bridges funcs tests main res addons $(LOCAL_MOD_SUBDIRS)
 OTHER_SUBDIRS:=utils agi
 SUBDIRS:=$(OTHER_SUBDIRS) $(MOD_SUBDIRS)
 SUBDIRS_INSTALL:=$(SUBDIRS:%=%-install)

Modified: team/kharwell/media_formats_translation_core/main/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/media_formats_translation_core/main/Makefile?view=diff&rev=413029&r1=413028&r2=413029
==============================================================================
--- team/kharwell/media_formats_translation_core/main/Makefile (original)
+++ team/kharwell/media_formats_translation_core/main/Makefile Fri Apr 25 18:13:49 2014
@@ -23,7 +23,7 @@
 SRC:=$(filter-out libasteriskssl.c,$(SRC))
 endif
 OBJSFILTER=fskmodem_int.o fskmodem_float.o cygload.o buildinfo.o
-OBJS=$(filter-out $(OBJSFILTER),$(SRC:.c=.o))
+OBJS=translate.o # $(filter-out $(OBJSFILTER),$(SRC:.c=.o))
 
 # we need to link in the objects statically, not as a library, because
 # otherwise modules will not have them available if none of the static

Modified: team/kharwell/media_formats_translation_core/main/codec.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/media_formats_translation_core/main/codec.c?view=diff&rev=413029&r1=413028&r2=413029
==============================================================================
--- team/kharwell/media_formats_translation_core/main/codec.c (original)
+++ team/kharwell/media_formats_translation_core/main/codec.c Fri Apr 25 18:13:49 2014
@@ -350,4 +350,85 @@
 	}
 
 	return codec->get_length(samples);
-}
+}
+
+static int codec_append_name(void *obj, void *arg, int flags)
+{
+	const struct ast_codec *left = obj;
+	const struct ast_codec *right = arg;
+
+	if (left->original_id == right->original_id) {
+		ast_str_append(buf, 0, "%s|", left->name);
+	}
+	return 0;
+}
+
+struct ast_str **ast_codec_get_names(const struct ast_codec *codec,
+				     struct ast_str **buf)
+{
+	int size = ast_str_strlen(*buf) + 1;
+
+	ast_str_append(buf, 0, "(");
+	ao2_callback(codecs, OBJ_NODATA, codec_append_name, codec);
+
+	if (size == ast_str_strlen(*buf)) {
+		ast_str_append(buf, 0, "nothing)");
+	} else {
+		ast_str_truncate(buf, -1);
+		ast_str_append(buf, 0, ")");
+	}
+	return buf;
+}
+
+struct ast_codec *ast_codec_complete(
+	const char *name, enum ast_media_type type, int state)
+{
+	struct ao2_iterator i;
+	struct ast_codec *obj;
+	int which = 0;
+	int size = strlen(name);
+	char *res = NULL;
+
+	ao2_rdlock(codecs);
+	i = ao2_iterator_init(codecs, AO2_ITERATOR_DONTLOCK);
+	for (; (obj = ao2_iterator_next(&i)); ao2_ref(obj, -1)) {
+		if (obj->type != type) {
+			continue;
+		}
+		if (!strncasecmp(name, obj->name, size) && ++which > state) {
+			res = ast_strdup(obj->name);
+			break;
+		}
+	}
+	ao2_iterator_destroy(&i);
+	ao2_unlock(codecs);
+	return res;
+}
+
+static int codec_longest_size(void *obj, void *arg, int flags)
+{
+	const struct ast_codec *codec = obj;
+	int *size = arg;
+	int len = strlen(codec->name);
+
+	if (len > *size) {
+		*size = len;
+	}
+	return 0;
+}
+
+int ast_codec_get_longest_size(void)
+{
+	int size = 0;
+	struct ast_codec *codec = ao2_callback(
+		codecs, 0, codec_longest_size, &size);
+
+	if (!codec) {
+		return 0;
+	}
+
+	size = strlen(codec->name);
+	ao2_ref(codec, -1);
+	return size;
+}
+

Modified: team/kharwell/media_formats_translation_core/main/format.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/media_formats_translation_core/main/format.c?view=diff&rev=413029&r1=413028&r2=413029
==============================================================================
--- team/kharwell/media_formats_translation_core/main/format.c (original)
+++ team/kharwell/media_formats_translation_core/main/format.c Fri Apr 25 18:13:49 2014
@@ -298,4 +298,4 @@
 unsigned int ast_format_determine_length(const struct ast_format *format, unsigned int samples)
 {
 	return ast_codec_determine_length(format->codec, samples);
-}
+}

Modified: team/kharwell/media_formats_translation_core/main/translate.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/media_formats_translation_core/main/translate.c?view=diff&rev=413029&r1=413028&r2=413029
==============================================================================
--- team/kharwell/media_formats_translation_core/main/translate.c (original)
+++ team/kharwell/media_formats_translation_core/main/translate.c Fri Apr 25 18:13:49 2014
@@ -76,11 +76,11 @@
 static struct translator_path **__matrix;
 
 /*!
- * \brief table for converting index to format id values.
+ * \brief table for converting index to format values.
  *
  * \note this table is protected by the table_lock.
  */
-static int *__indextable;
+static struct ast_format **__indextable;
 
 /*! protects the __indextable for resizing */
 static ast_rwlock_t tablelock;
@@ -99,15 +99,15 @@
 
 /*!
  * \internal
- * \brief converts format id to index value.
- */
-static int format2index(enum ast_format_id id)
+ * \brief converts format to index value.
+ */
+static int format2index(struct ast_format *format)
 {
 	int x;
 
 	ast_rwlock_rdlock(&tablelock);
 	for (x = 0; x < cur_max_index; x++) {
-		if (__indextable[x] == id) {
+		if (__indextable[x] == format) {
 			/* format already exists in index2format table */
 			ast_rwlock_unlock(&tablelock);
 			return x;
@@ -126,9 +126,9 @@
  * \retval 0, success
  * \retval -1, matrix and index table need to be resized
  */
-static int add_format2index(enum ast_format_id id)
-{
-	if (format2index(id) != -1) {
+static int add_format2index(struct ast_format *format)
+{
+	if (format2index(format) != -1) {
 		/* format is already already indexed */
 		return 0;
 	}
@@ -138,7 +138,7 @@
 		ast_rwlock_unlock(&tablelock);
 		return -1; /* hit max length */
 	}
-	__indextable[cur_max_index] = id;
+	__indextable[cur_max_index] = format;
 	cur_max_index++;
 	ast_rwlock_unlock(&tablelock);
 
@@ -147,20 +147,20 @@
 
 /*!
  * \internal
- * \brief converts index value back to format id
- */
-static enum ast_format_id index2format(int index)
-{
-	enum ast_format_id format_id;
+ * \brief converts index value back to format
+ */
+static struct ast_format *format index2format(int index)
+{
+	struct ast_format *format;
 
 	if (index >= cur_max_index) {
 		return 0;
 	}
 	ast_rwlock_rdlock(&tablelock);
-	format_id = __indextable[index];
+	format = __indextable[index];
 	ast_rwlock_unlock(&tablelock);
 
-	return format_id;
+	return format;
 }
 
 /*!
@@ -196,13 +196,13 @@
 	}
 
 	for (x = 0; x < index_size; x++) {
-		if (!(tmp_matrix[x] = ast_calloc(1, sizeof(struct translator_path) * (index_size)))) {
+		if (!(tmp_matrix[x] = ast_calloc(1, sizeof(struct translator_path*) * (index_size)))) {
 			goto resize_cleanup;
 		}
 	}
 
 	/* make new index table */
-	if (!(tmp_table = ast_calloc(1, sizeof(int) * index_size))) {
+	if (!(tmp_table = ast_calloc(1, sizeof(struct ast_format*) * index_size))) {
 		goto resize_cleanup;
 	}
 
@@ -213,7 +213,7 @@
 		}
 		ast_free(__matrix);
 
-		memcpy(tmp_table, __indextable, sizeof(int) * old_index);
+		memcpy(tmp_table, __indextable, sizeof(struct ast_format*) * old_index);
 		ast_free(__indextable);
 	}
 
@@ -306,7 +306,8 @@
 	/* if a explicit destination format is provided, set that on the pvt so the
 	 * translator will process it. */
 	if (explicit_dst) {
-		ast_format_copy(&pvt->explicit_dst, explicit_dst);
+		ao2_cleanup(pvt->explicit_dst);
+		pvt->explicit_dst = ast_format_copy(explicit_dst);
 	}
 	/* call local init routine, if present */
 	if (t->newpvt && t->newpvt(pvt)) {
@@ -324,6 +325,7 @@
 	if (t->destroy)
 		t->destroy(pvt);
 	ao2_cleanup(pvt->f.subclass.format);
+	ao2_cleanup(pvt->explicit_dst);
 	ast_free(pvt);
 	ast_module_unref(t->module);
 }
@@ -391,7 +393,10 @@
 	}
 
 	f->frametype = AST_FRAME_VOICE;
-	ast_format_copy(&f->subclass.format, &pvt->t->dst_format);
+	f->subclass.format = ast_format_create(
+		ast_codec_get(pvt->t->dst_codec->name,
+			      pvt->t->dst_codec->type,
+			      pvt->t->dst_codec->sample_rate));
 	f->mallocd = 0;
 	f->offset = AST_FRIENDLY_OFFSET;
 	f->src = pvt->t->name;
@@ -421,11 +426,9 @@
 {
 	struct ast_trans_pvt *head = NULL, *tail = NULL;
 	int src_index, dst_index;
-	struct ast_format tmp_fmt1;
-	struct ast_format tmp_fmt2;
-
-	src_index = format2index(src->id);
-	dst_index = format2index(dst->id);
+
+	src_index = format2index(src);
+	dst_index = format2index(dst);
 
 	if (src_index == -1 || dst_index == -1) {
 		ast_log(LOG_WARNING, "No translator path: (%s codec is not valid)\n", src_index == -1 ? "starting" : "ending");
@@ -439,11 +442,8 @@
 		struct ast_format *explicit_dst = NULL;
 		struct ast_translator *t = matrix_get(src_index, dst_index)->step;
 		if (!t) {
-			int src_id = index2format(src_index);
-			int dst_id = index2format(dst_index);
 			ast_log(LOG_WARNING, "No translator path from %s to %s\n",
-				ast_getformatname(ast_format_set(&tmp_fmt1, src_id, 0)),
-				ast_getformatname(ast_format_set(&tmp_fmt2, dst_id, 0)));
+				ast_format_get_name(src), ast_format_get_name(dst));
 			AST_RWLIST_UNLOCK(&translators);
 			return NULL;
 		}
@@ -451,11 +451,8 @@
 			explicit_dst = dst;
 		}
 		if (!(cur = newpvt(t, explicit_dst))) {
-			int src_id = index2format(src_index);
-			int dst_id = index2format(dst_index);
 			ast_log(LOG_WARNING, "Failed to build translator step from %s to %s\n",
-				ast_getformatname(ast_format_set(&tmp_fmt1, src_id, 0)),
-				ast_getformatname(ast_format_set(&tmp_fmt2, dst_id, 0)));
+				ast_format_get_name(src), ast_format_get_name(dst));
 			if (head) {
 				ast_translator_free_path(head);
 			}
@@ -512,7 +509,8 @@
 			path->nextout = f->delivery;
 		}
 		/* Predict next incoming sample */
-		path->nextin = ast_tvadd(path->nextin, ast_samp2tv(f->samples, ast_format_rate(&f->subclass.format)));
+		path->nextin = ast_tvadd(path->nextin, ast_samp2tv(
+			 f->samples, ast_format_get_sample_rate(f->subclass.format)));
 	}
 	delivery = f->delivery;
 	for (out = f; out && p ; p = p->next) {
@@ -535,7 +533,8 @@
 
 			/* Predict next outgoing timestamp from samples in this
 			   frame. */
-			path->nextout = ast_tvadd(path->nextout, ast_samp2tv(out->samples, ast_format_rate(&out->subclass.format)));
+			path->nextout = ast_tvadd(path->nextout, ast_samp2tv(
+				 out->samples, ast_format_get_sample_rate(out->subclass.format)));
 			if (f->samples != out->samples && ast_test_flag(out, AST_FRFLAG_HAS_TIMING_INFO)) {
 				ast_debug(4, "Sample size different %u vs %u\n", f->samples, out->samples);
 				ast_clear_flag(out, AST_FRFLAG_HAS_TIMING_INFO);
@@ -576,7 +575,7 @@
 	struct rusage start;
 	struct rusage end;
 	int cost;
-	int out_rate = ast_format_rate(&t->dst_format);
+	int out_rate = t->dst_codec->sample_rate;
 
 	if (!seconds) {
 		seconds = 1;
@@ -649,19 +648,21 @@
  */
 static int generate_table_cost(struct ast_format *src, struct ast_format *dst)
 {
-	int src_rate = ast_format_rate(src);
+	int src_rate = ast_format_get_sample_rate(src);
 	int src_ll = 0;
-	int dst_rate = ast_format_rate(dst);
+	int dst_rate = ast_format_get_sample_rate(dst);
 	int dst_ll = 0;
 
-	if ((AST_FORMAT_GET_TYPE(src->id) != AST_FORMAT_TYPE_AUDIO) || (AST_FORMAT_GET_TYPE(dst->id) != AST_FORMAT_TYPE_AUDIO)) {
+	if ((ast_format_get_type(src) != AST_MEDIA_TYPE_AUDIO) ||
+	    (ast_format_get_type(dst) != AST_MEDIA_TYPE_AUDIO)) {
 		/* This method of generating table cost is limited to audio.
 		 * Translators for media other than audio must manually set their
 		 * table cost. */
 		return 0;
 	}
-	src_ll = ast_format_is_slinear(src);
-	dst_ll = ast_format_is_slinear(dst);
+
+	src_ll = ast_format_cmp(src, ast_format_slin) == AST_FORMAT_CMP_EQUAL;
+	dst_ll = ast_format_cmp(dst, ast_format_slin) == AST_FORMAT_CMP_EQUAL;
 	if (src_ll) {
 		if (dst_ll && (src_rate == dst_rate)) {
 			return AST_TRANS_COST_LL_LL_ORIGSAMP;
@@ -767,18 +768,15 @@
 					/* if no step already exists between x and z OR the new cost of using the intermediate
 					 * step is cheaper, use this step. */
 					if (!matrix_get(x, z)->step || (newtablecost < matrix_get(x, z)->table_cost)) {
-						struct ast_format tmpx;
-						struct ast_format tmpy;
-						struct ast_format tmpz;
 						matrix_get(x, z)->step = matrix_get(x, y)->step;
 						matrix_get(x, z)->table_cost = newtablecost;
 						matrix_get(x, z)->multistep = 1;
 						changed++;
 						ast_debug(10, "Discovered %d cost path from %s to %s, via %s\n",
 							matrix_get(x, z)->table_cost,
-							ast_getformatname(ast_format_set(&tmpx, index2format(x), 0)),
-							ast_getformatname(ast_format_set(&tmpy, index2format(z), 0)),
-							ast_getformatname(ast_format_set(&tmpz, index2format(y), 0)));
+							  ast_format_get_name(index2format(x)),
+							  ast_format_get_name(index2format(z)),
+							  ast_format_get_name(index2format(y));
 					}
 				}
 			}
@@ -792,17 +790,16 @@
 const char *ast_translate_path_to_str(struct ast_trans_pvt *p, struct ast_str **str)
 {
 	struct ast_trans_pvt *pn = p;
-	char tmp[256];
 
 	if (!p || !p->t) {
 		return "";
 	}
 
-	ast_str_set(str, 0, "%s", ast_getformatname_multiple_byid(tmp, sizeof(tmp), p->t->src_format.id));
-
-	while ( (p = pn) ) {
-		pn = p->next;
-		ast_str_append(str, 0, "->%s", ast_getformatname_multiple_byid(tmp, sizeof(tmp), p->t->dst_format.id));
+	ast_codec_get_names(p->t->src_codec, str);
+	while (p) {
+		ast_str_append(str, 0, "->%s");
+		ast_codec_get_names(p->t->dst_codec, str);
+		p = p->next;
 	}
 
 	return ast_str_buffer(*str);
@@ -810,24 +807,7 @@
 
 static char *complete_trans_path_choice(const char *line, const char *word, int pos, int state)
 {
-	int which = 0;
-	int wordlen = strlen(word);
-	int i;
-	char *ret = NULL;
-	size_t len = 0;
-	const struct ast_format_list *format_list = ast_format_list_get(&len);
-
-	for (i = 0; i < len; i++) {
-		if (AST_FORMAT_GET_TYPE(format_list[i].format.id) != AST_FORMAT_TYPE_AUDIO) {
-			continue;
-		}
-		if (!strncasecmp(word, format_list[i].name, wordlen) && ++which > state) {
-			ret = ast_strdup(format_list[i].name);
-			break;
-		}
-	}
-	ast_format_list_destroy(format_list);
-	return ret;
+	return ast_codec_complete(word, AST_MEDIA_TYPE_AUDIO, state);
 }
 
 static void handle_cli_recalc(struct ast_cli_args *a)
@@ -856,7 +836,8 @@
 	int i;
 	int k;
 	int curlen = 0;
-	int longest = 0;
+	/* Get the length of the longest (usable?) codec name, so we know how wide the left side should be */
+	int longest = ast_codec_get_longest_size();
 	int f_len;
 	size_t f_size = 0;
 	const struct ast_format_list *f_list = ast_format_list_get(&f_size);
@@ -866,17 +847,6 @@
 	AST_RWLIST_RDLOCK(&translators);
 	ast_cli(a->fd, "         Translation times between formats (in microseconds) for one second of data\n");
 	ast_cli(a->fd, "          Source Format (Rows) Destination Format (Columns)\n\n");
-
-	/* Get the length of the longest (usable?) codec name, so we know how wide the left side should be */
-	for (i = 0; i < f_len; i++) {
-		/* translation only applies to audio right now. */
-		if (AST_FORMAT_GET_TYPE(f_list[i].format.id) != AST_FORMAT_TYPE_AUDIO)
-			continue;
-		curlen = strlen(ast_getformatname(&f_list[i].format));
-		if (curlen > longest) {
-			longest = curlen;
-		}
-	}
 
 	for (i = -1; i < f_len; i++) {
 		x = -1;




More information about the asterisk-commits mailing list