[svn-commits] dvossel: branch dvossel/fixtheworld_phase1_step2 r299398 - /team/dvossel/fixt...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Tue Dec 21 21:04:08 UTC 2010
Author: dvossel
Date: Tue Dec 21 15:04:04 2010
New Revision: 299398
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=299398
Log:
Translator matix index values are decoupled from bitfield conversion
Modified:
team/dvossel/fixtheworld_phase1_step2/main/translate.c
Modified: team/dvossel/fixtheworld_phase1_step2/main/translate.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step2/main/translate.c?view=diff&rev=299398&r1=299397&r2=299398
==============================================================================
--- team/dvossel/fixtheworld_phase1_step2/main/translate.c (original)
+++ team/dvossel/fixtheworld_phase1_step2/main/translate.c Tue Dec 21 15:04:04 2010
@@ -42,6 +42,11 @@
#define MAX_RECALC 1000 /* max sample recalc */
+/*! This value is used to define how large the tr_matrix and tr_index2format arrays
+ * are defined to be in memory by default. Once Asterisk can represent more formats
+ * than this number represents with translation, increase it. */
+#define DEFAULT_INDEX 256
+
/*! \brief the list of translators */
static AST_RWLIST_HEAD_STATIC(translators, ast_translator);
@@ -61,7 +66,11 @@
* Note: the lock in the 'translators' list is also used to protect
* this structure.
*/
-static struct translator_path tr_matrix[MAX_FORMAT][MAX_FORMAT];
+static struct translator_path tr_matrix[DEFAULT_INDEX][DEFAULT_INDEX];
+/*! table for converting index to format id values. */
+static format_t tr_index2format[DEFAULT_INDEX];
+/*! the current largest index used by the tr_matrix and tr_index2format tables */
+static int cur_max_index = 0;
/*! \todo
* TODO: sample frames for each supported input format.
@@ -73,24 +82,32 @@
* \internal
* \brief converts format id to index value.
*/
-static force_inline int format2index(format_t d)
-{
- int x = ffsll(d);
-
- if (x)
- return x - 1;
-
- ast_log(LOG_WARNING, "No bits set? %llu\n", (unsigned long long) d);
-
- return -1;
-}
+static force_inline int format2index(format_t id)
+{
+ int x;
+ for (x = 0; x < cur_max_index; x++) {
+ if (tr_index2format[x] == id) {
+ /* format already exists in index2format table */
+ return x;
+ }
+ }
+
+ if (cur_max_index == ARRAY_LEN(tr_index2format)) {
+ return -1; /* hit max length. */
+ }
+ tr_index2format[cur_max_index] = id;
+ cur_max_index++;
+
+ return cur_max_index - 1;
+}
+
/*!
* \internal
* \brief converts index value back to format id
*/
static force_inline format_t index2format(int index)
{
- return 1LL << index;
+ return tr_index2format[index];
}
/*
@@ -149,7 +166,7 @@
{
int ret;
int samples = pvt->samples; /* initial value */
-
+
/* Copy the last in jb timing info to the pvt */
ast_copy_flags(&pvt->f, f, AST_FRFLAG_HAS_TIMING_INFO);
pvt->f.ts = f->ts;
@@ -236,7 +253,7 @@
struct ast_trans_pvt *ast_translator_build_path(format_t dest, format_t source)
{
struct ast_trans_pvt *head = NULL, *tail = NULL;
-
+
source = format2index(source);
dest = format2index(dest);
@@ -335,7 +352,7 @@
/* Use next predicted outgoing timestamp */
out->delivery = path->nextout;
-
+
/* Predict next outgoing timestamp from samples in this
frame. */
path->nextout = ast_tvadd(path->nextout, ast_samp2tv(out->samples, ast_format_rate(out->subclass.codec)));
@@ -537,11 +554,11 @@
*/
for (;;) {
int changed = 0;
- for (x = 0; x < MAX_FORMAT; x++) { /* source format */
- for (y = 0; y < MAX_FORMAT; y++) { /* intermediate format */
+ for (x = 0; x < cur_max_index; x++) { /* source format */
+ for (y = 0; y < cur_max_index; y++) { /* intermediate format */
if (x == y) /* skip ourselves */
continue;
- for (z = 0; z < MAX_FORMAT; z++) { /* dst format */
+ for (z = 0; z < cur_max_index; z++) { /* dst format */
if (z == x || z == y) /* skip null conversions */
continue;
if (!tr_matrix[x][y].step) /* no path from x to y */
@@ -810,13 +827,13 @@
ast_log(LOG_WARNING, "Invalid translator path: (%s codec is not valid)\n", t->srcfmt == -1 ? "starting" : "ending");
return -1;
}
- if (t->srcfmt >= MAX_FORMAT) {
- ast_log(LOG_WARNING, "Source format %s is larger than MAX_FORMAT\n", ast_getformatname(t->srcfmt));
+ if (t->srcfmt >= cur_max_index) {
+ ast_log(LOG_WARNING, "Source format %s is larger than cur_max_index\n", ast_getformatname(t->srcfmt));
return -1;
}
- if (t->dstfmt >= MAX_FORMAT) {
- ast_log(LOG_WARNING, "Destination format %s is larger than MAX_FORMAT\n", ast_getformatname(t->dstfmt));
+ if (t->dstfmt >= cur_max_index) {
+ ast_log(LOG_WARNING, "Destination format %s is larger than cur_max_index\n", ast_getformatname(t->dstfmt));
return -1;
}
@@ -833,7 +850,7 @@
if (t->frameout == NULL)
t->frameout = default_frameout;
-
+
generate_computational_cost(t, 1);
ast_verb(2, "Registered translator '%s' from format %s to %s, cost %d\n",
@@ -999,7 +1016,8 @@
format_t ast_translate_available_formats(format_t dest, format_t src)
{
format_t res = dest;
- format_t x;
+ format_t tmp_fmt;
+ int index;
format_t src_audio = src & AST_FORMAT_AUDIO_MASK;
format_t src_video = src & AST_FORMAT_VIDEO_MASK;
@@ -1022,60 +1040,62 @@
known audio formats to determine whether there exists
a translation path from the source format to the
destination format. */
- for (x = 1LL; src_audio && x > 0; x <<= 1) {
- if (!(x & AST_FORMAT_AUDIO_MASK)) {
+ for (index = 0; src_audio && index < cur_max_index; index++) {
+ tmp_fmt = index2format(index);
+ if (!(tmp_fmt & AST_FORMAT_AUDIO_MASK)) {
continue;
}
/* if this is not a desired format, nothing to do */
- if (!(dest & x))
+ if (!(dest & tmp_fmt))
continue;
/* if the source is supplying this format, then
we can leave it in the result */
- if (src & x)
+ if (src & tmp_fmt)
continue;
/* if we don't have a translation path from the src
to this format, remove it from the result */
- if (!tr_matrix[src_audio][format2index(x)].step) {
- res &= ~x;
+ if (!tr_matrix[src_audio][index].step) {
+ res &= ~tmp_fmt;
continue;
}
/* now check the opposite direction */
- if (!tr_matrix[format2index(x)][src_audio].step)
- res &= ~x;
+ if (!tr_matrix[index][src_audio].step)
+ res &= tmp_fmt;
}
/* For a given source video format, traverse the list of
known video formats to determine whether there exists
a translation path from the source format to the
destination format. */
- for (x = 1LL; src_video && x > 0; x <<= 1) {
- if (!(x & AST_FORMAT_VIDEO_MASK)) {
+ for (index = 0; src_video && index > cur_max_index; index++) {
+ tmp_fmt = index2format(index);
+ if (!(tmp_fmt & AST_FORMAT_VIDEO_MASK)) {
continue;
}
/* if this is not a desired format, nothing to do */
- if (!(dest & x))
+ if (!(dest & tmp_fmt))
continue;
/* if the source is supplying this format, then
we can leave it in the result */
- if (src & x)
+ if (src & tmp_fmt)
continue;
/* if we don't have a translation path from the src
to this format, remove it from the result */
- if (!tr_matrix[src_video][format2index(x)].step) {
- res &= ~x;
+ if (!tr_matrix[src_video][index].step) {
+ res &= ~tmp_fmt;
continue;
}
/* now check the opposite direction */
- if (!tr_matrix[format2index(x)][src_video].step)
- res &= ~x;
+ if (!tr_matrix[index][src_video].step)
+ res &= ~tmp_fmt;
}
AST_RWLIST_UNLOCK(&translators);
More information about the svn-commits
mailing list