[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r301133 - in /team/dvossel/f...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Jan 8 00:11:46 UTC 2011
Author: dvossel
Date: Fri Jan 7 18:11:42 2011
New Revision: 301133
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=301133
Log:
Last of the ast_format conversions for the Asterisk Core.
Modified:
team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h
team/dvossel/fixtheworld_phase1_step3/main/translate.c
team/dvossel/fixtheworld_phase1_step3/main/udptl.c
Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h?view=diff&rev=301133&r1=301132&r2=301133
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/translate.h Fri Jan 7 18:11:42 2011
@@ -138,8 +138,8 @@
*/
struct ast_translator {
const char name[80]; /*!< Name of translator */
- struct ast_format *src_fmt; /*!< Source format */
- struct ast_format *dst_fmt; /*!< Destination format */
+ struct ast_format src_format; /*!< Source format */
+ struct ast_format dst_format; /*!< Destination format */
int table_cost; /*!< Cost value associated with this translator based
* on translation cost table. */
@@ -182,6 +182,8 @@
struct ast_module *module; /*!< opaque reference to the parent module */
int active; /*!< Whether this translator should be used or not */
+ int src_fmt_index; /*!< index of the source format in the matrix table */
+ int dst_fmt_index; /*!< index of the destination format in the matrix table */
AST_LIST_ENTRY(ast_translator) list; /*!< link field */
};
@@ -321,10 +323,11 @@
unsigned int ast_translate_path_steps(struct ast_format *dest, struct ast_format *src);
/*!
- * \brief Mask off unavailable formats from a format bitmask
+ * \brief Find available formats
* \param dest possible destination formats
* \param src source formats
- * \param result capabilities structure to store results in
+ * \param result capabilities structure to store available formats in
+ *
* \return the destination formats that are available in the source or translatable
*
* The result will include all formats from 'dest' that are either present
Modified: team/dvossel/fixtheworld_phase1_step3/main/translate.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/translate.c?view=diff&rev=301133&r1=301132&r2=301133
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/translate.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/translate.c Fri Jan 7 18:11:42 2011
@@ -76,7 +76,7 @@
*
* \note this table is protected by the table_lock.
*/
-static format_t *__indextable;
+static int *__indextable;
/*! protects the __indextable for resizing */
static ast_rwlock_t tablelock;
@@ -97,7 +97,7 @@
* \internal
* \brief converts format id to index value.
*/
-static int format2index(format_t id)
+static int format2index(enum ast_format_id id)
{
int x;
@@ -122,7 +122,7 @@
* \retval 0, success
* \retval -1, matrix and index table need to be resized
*/
-static int add_format2index(format_t id)
+static int add_format2index(enum ast_format_id id)
{
if (format2index(id) != -1) {
/* format is already already indexed */
@@ -145,15 +145,18 @@
* \internal
* \brief converts index value back to format id
*/
-static force_inline format_t index2format(int index)
-{
- format_t format;
-
+static force_inline enum ast_format_id index2format(int index)
+{
+ enum ast_format_id format_id;
+
+ if (index >= cur_max_index) {
+ return 0;
+ }
ast_rwlock_rdlock(&tablelock);
- format = __indextable[index];
+ format_id = __indextable[index];
ast_rwlock_unlock(&tablelock);
- return format;
+ return format_id;
}
/*
@@ -169,7 +172,7 @@
static int matrix_resize(int init)
{
struct translator_path **tmp_matrix = NULL;
- format_t *tmp_table = NULL;
+ int *tmp_table = NULL;
int old_index;
int x;
@@ -195,7 +198,7 @@
}
/* make new index table */
- if (!(tmp_table = ast_calloc(1, sizeof(format_t) * index_size))) {
+ if (!(tmp_table = ast_calloc(1, sizeof(int) * index_size))) {
goto resize_cleanup;
}
@@ -206,7 +209,7 @@
}
ast_free(__matrix);
- memcpy(tmp_table, __indextable, sizeof(format_t) * old_index);
+ memcpy(tmp_table, __indextable, sizeof(int) * old_index);
ast_free(__indextable);
}
@@ -256,6 +259,9 @@
*/
static struct translator_path *matrix_get(int x, int y)
{
+ if (!(x > 0 && y > 0)) {
+ return NULL;
+ }
return __matrix[x] + y;
}
@@ -373,7 +379,7 @@
}
f->frametype = AST_FRAME_VOICE;
- f->subclass.codec = index2format(pvt->t->dstfmt);
+ ast_format_copy(&pvt->t->dst_format, &f->subclass.format);
f->mallocd = 0;
f->offset = AST_FRIENDLY_OFFSET;
f->src = pvt->t->name;
@@ -399,32 +405,41 @@
}
/*! \brief Build a chain of translators based upon the given source and dest formats */
-struct ast_trans_pvt *ast_translator_build_path(format_t dest, format_t source)
+struct ast_trans_pvt *ast_translator_build_path(struct ast_format *dst, struct ast_format *src)
{
struct ast_trans_pvt *head = NULL, *tail = NULL;
-
- source = format2index(source);
- dest = format2index(dest);
-
- if (source == -1 || dest == -1) {
- ast_log(LOG_WARNING, "No translator path: (%s codec is not valid)\n", source == -1 ? "starting" : "ending");
+ 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);
+
+ 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");
return NULL;
}
AST_RWLIST_RDLOCK(&translators);
- while (source != dest) {
+ while (src_index != dst_index) {
struct ast_trans_pvt *cur;
- struct ast_translator *t = matrix_get(source, dest)->step;
+ struct ast_translator *t = matrix_get(src_index, dst_index)->step;
if (!t) {
- ast_log(LOG_WARNING, "No translator path from %s to %s\n",
- ast_getformatname(source), ast_getformatname(dest));
+ 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_RWLIST_UNLOCK(&translators);
return NULL;
}
if (!(cur = newpvt(t))) {
+ 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(source), ast_getformatname(dest));
+ ast_getformatname(ast_format_set(&tmp_fmt1, src_id, 0)),
+ ast_getformatname(ast_format_set(&tmp_fmt2, dst_id, 0)));
if (head) {
ast_translator_free_path(head);
}
@@ -439,7 +454,7 @@
tail = cur;
cur->nextin = cur->nextout = ast_tv(0, 0);
/* Keep going if this isn't the final destination */
- source = cur->t->dstfmt;
+ src_index = cur->t->dst_fmt_index;
}
AST_RWLIST_UNLOCK(&translators);
@@ -481,7 +496,7 @@
path->nextout = f->delivery;
}
/* Predict next incoming sample */
- path->nextin = ast_tvadd(path->nextin, ast_samp2tv(f->samples, ast_format_rate(f->subclass.codec)));
+ path->nextin = ast_tvadd(path->nextin, ast_samp2tv(f->samples, ast_format_rate(&f->subclass.format)));
}
delivery = f->delivery;
for (out = f; out && p ; p = p->next) {
@@ -509,7 +524,7 @@
/* 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)));
+ path->nextout = ast_tvadd(path->nextout, ast_samp2tv(out->samples, ast_format_rate(&out->subclass.format)));
} else {
out->delivery = ast_tv(0, 0);
ast_set2_flag(out, has_timing_info, AST_FRFLAG_HAS_TIMING_INFO);
@@ -542,7 +557,7 @@
struct rusage start;
struct rusage end;
int cost;
- int out_rate = ast_format_rate(t->dstfmt);
+ int out_rate = ast_format_rate(&t->dst_format);
if (!seconds) {
seconds = 1;
@@ -613,23 +628,23 @@
* \retval Table Cost value greater than 0.
* \retval 0 on error.
*/
-static int generate_table_cost(format_t src, format_t dst)
+static int generate_table_cost(struct ast_format *src, struct ast_format *dst)
{
int src_rate = ast_format_rate(src);
int src_ll = 0;
int dst_rate = ast_format_rate(dst);
int dst_ll = 0;
- if (!(src & AST_FORMAT_AUDIO_MASK) || !(src & AST_FORMAT_AUDIO_MASK)) {
+ if ((AST_FORMAT_GET_TYPE(src->id) != AST_FORMAT_TYPE_AUDIO) || (AST_FORMAT_GET_TYPE(dst->id) != AST_FORMAT_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;
}
- if ((src == AST_FORMAT_SLINEAR) || (src == AST_FORMAT_SLINEAR16)) {
+ if ((src->id == AST_FORMAT_SLINEAR) || (src->id == AST_FORMAT_SLINEAR16)) {
src_ll = 1;
}
- if ((dst == AST_FORMAT_SLINEAR) || (dst == AST_FORMAT_SLINEAR16)) {
+ if ((dst->id == AST_FORMAT_SLINEAR) || (dst->id == AST_FORMAT_SLINEAR16)) {
dst_ll = 1;
}
@@ -690,8 +705,8 @@
continue;
}
- x = t->srcfmt;
- z = t->dstfmt;
+ x = t->src_fmt_index;
+ z = t->dst_fmt_index;
if (samples) {
generate_computational_cost(t, samples);
@@ -738,15 +753,18 @@
/* 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(3, "Discovered %d cost path from %s to %s, via %s\n",
matrix_get(x, z)->table_cost,
- ast_getformatname(index2format(x)),
- ast_getformatname(index2format(z)),
- ast_getformatname(index2format(y)));
+ 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)));
}
}
}
@@ -765,11 +783,11 @@
return "";
}
- ast_str_set(str, 0, "%s", ast_getformatname(index2format(p->t->srcfmt)));
+ ast_str_set(str, 0, "%s", ast_getformatname(&p->t->src_format));
while ( (p = pn) ) {
pn = p->next;
- ast_str_append(str, 0, "->%s", ast_getformatname(index2format(p->t->dstfmt)));
+ ast_str_append(str, 0, "->%s", ast_getformatname(&p->t->dst_format));
}
return ast_str_buffer(*str);
@@ -785,7 +803,7 @@
const struct ast_format_list *format_list = ast_get_format_list(&len);
for (i = 0; i < len; i++) {
- if (!(format_list[i].bits & AST_FORMAT_AUDIO_MASK)) {
+ if (AST_FORMAT_GET_TYPE(format_list[i].id) != AST_FORMAT_TYPE_AUDIO) {
continue;
}
if (!strncasecmp(word, format_list[i].name, wordlen) && ++which > state) {
@@ -819,7 +837,7 @@
{
int x, y;
int curlen = 0, longest = 0;
-
+ struct ast_format tmp_fmt;
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");
@@ -827,9 +845,9 @@
/* Get the length of the longest (usable?) codec name, so we know how wide the left side should be */
for (x = 0; x < cur_max_index; x++) {
/* translation only applies to audio right now. */
- if (!(AST_FORMAT_AUDIO_MASK & (index2format(x))))
+ if (AST_FORMAT_GET_TYPE(index2format(x) != AST_FORMAT_TYPE_AUDIO))
continue;
- curlen = strlen(ast_getformatname(index2format(x)));
+ curlen = strlen(ast_getformatname(ast_format_set(&tmp_fmt, index2format(x), 0)));
if (curlen > longest) {
longest = curlen;
}
@@ -838,25 +856,25 @@
for (x = -1; x < cur_max_index; x++) {
struct ast_str *out = ast_str_alloca(256);
/* translation only applies to audio right now. */
- if (x >= 0 && !(AST_FORMAT_AUDIO_MASK & (index2format(x)))) {
+ if (x >= 0 && (AST_FORMAT_GET_TYPE(index2format(x)) != AST_FORMAT_TYPE_AUDIO)) {
continue;
}
/*Go ahead and move to next iteration if dealing with an unknown codec*/
- if (x >= 0 && !strcmp(ast_getformatname(index2format(x)), "unknown")) {
+ if (x >= 0 && !strcmp(ast_getformatname(ast_format_set(&tmp_fmt, index2format(x), 0)), "unknown")) {
continue;
}
ast_str_set(&out, -1, " ");
for (y = -1; y < cur_max_index; y++) {
/* translation only applies to audio right now. */
- if (y >= 0 && !(AST_FORMAT_AUDIO_MASK & (index2format(y)))) {
+ if (y >= 0 && (AST_FORMAT_GET_TYPE(index2format(y)) != AST_FORMAT_TYPE_AUDIO)) {
continue;
}
/*Go ahead and move to next iteration if dealing with an unknown codec*/
- if (y >= 0 && !strcmp(ast_getformatname(index2format(y)), "unknown")) {
+ if (y >= 0 && !strcmp(ast_getformatname(ast_format_set(&tmp_fmt, index2format(y), 0)), "unknown")) {
continue;
}
if (y >= 0) {
- curlen = strlen(ast_getformatname(index2format(y)));
+ curlen = strlen(ast_getformatname(ast_format_set(&tmp_fmt, index2format(y), 0)));
}
if (curlen < 5) {
curlen = 5;
@@ -867,10 +885,10 @@
ast_str_append(&out, -1, "%*d", curlen + 1, (matrix_get(x, y)->table_cost/100));
} else if (x == -1 && y >= 0) {
/* Top row - use a dynamic size */
- ast_str_append(&out, -1, "%*s", curlen + 1, ast_getformatname(index2format(y)) );
+ ast_str_append(&out, -1, "%*s", curlen + 1, ast_getformatname(ast_format_set(&tmp_fmt, index2format(y), 0)));
} else if (y == -1 && x >= 0) {
/* Left column - use a static size. */
- ast_str_append(&out, -1, "%*s", longest, ast_getformatname(index2format(x)) );
+ ast_str_append(&out, -1, "%*s", longest, ast_getformatname(ast_format_set(&tmp_fmt, index2format(x), 0)));
} else if (x >= 0 && y >= 0) {
/* Codec not supported */
ast_str_append(&out, -1, "%*s", curlen + 1, "-");
@@ -888,48 +906,50 @@
static char *handle_show_translation_path(struct ast_cli_args *a)
{
- format_t input_src = 0;
- format_t src = 0;
+ struct ast_format input_src_format;
size_t len = 0;
- int dst;
int i;
const struct ast_format_list *format_list = ast_get_format_list(&len);
struct ast_str *str = ast_str_alloca(256);
struct ast_translator *step;
+ ast_format_clear(&input_src_format);
+
for (i = 0; i < len; i++) {
- if (!(format_list[i].bits & AST_FORMAT_AUDIO_MASK)) {
+ if (AST_FORMAT_GET_TYPE(format_list[i].id) != AST_FORMAT_TYPE_AUDIO) {
continue;
}
if (!strncasecmp(format_list[i].name, a->argv[4], strlen(format_list[i].name))) {
- input_src = format_list[i].bits;
- }
- }
-
- if (!input_src) {
+ ast_format_set(&input_src_format, format_list[i].id, 0);
+ }
+ }
+
+ if (!input_src_format.id) {
ast_cli(a->fd, "Source codec \"%s\" is not found.\n", a->argv[4]);
return CLI_FAILURE;
}
AST_RWLIST_RDLOCK(&translators);
- ast_cli(a->fd, "--- Translation paths SRC Codec \"%s\" sample rate %d ---\n", a->argv[4], ast_format_rate(input_src));
+ ast_cli(a->fd, "--- Translation paths SRC Codec \"%s\" sample rate %d ---\n", a->argv[4], ast_format_rate(&input_src_format));
for (i = 0; i < len; i++) {
- if (!(format_list[i].bits & AST_FORMAT_AUDIO_MASK) || (format_list[i].bits == input_src)) {
+ int src;
+ int dst;
+ if ((AST_FORMAT_GET_TYPE(format_list[i].id) != AST_FORMAT_TYPE_AUDIO) || (format_list[i].id == input_src_format.id)) {
continue;
}
- dst = format2index(format_list[i].bits);
- src = format2index(input_src);
+ dst = format2index(format_list[i].id);
+ src = format2index(input_src_format.id);
ast_str_reset(str);
if ((len >= cur_max_index) && (src != -1) && (dst != -1) && matrix_get(src, dst)->step) {
- ast_str_append(&str, 0, "%s", ast_getformatname(index2format(matrix_get(src, dst)->step->srcfmt)));
+ ast_str_append(&str, 0, "%s", ast_getformatname(&matrix_get(src, dst)->step->src_format));
while (src != dst) {
step = matrix_get(src, dst)->step;
if (!step) {
ast_str_reset(str);
break;
}
- ast_str_append(&str, 0, "->%s", ast_getformatname(index2format(step->dstfmt)));
- src = step->dstfmt;
+ ast_str_append(&str, 0, "->%s", ast_getformatname(&step->dst_format));
+ src = step->dst_fmt_index;
}
}
@@ -991,17 +1011,16 @@
/*! \brief register codec translator */
int __ast_register_translator(struct ast_translator *t, struct ast_module *mod)
{
- static int added_cli = 0;
struct ast_translator *u;
char tmp[80];
- if (add_format2index(t->srcfmt) || add_format2index(t->dstfmt)) {
+ if (add_format2index(t->src_format.id) || add_format2index(t->dst_format.id)) {
if (matrix_resize(0)) {
ast_log(LOG_WARNING, "Translator matrix can not represent any more translators. Out of resources.\n");
return -1;
}
- add_format2index(t->srcfmt);
- add_format2index(t->dstfmt);
+ add_format2index(t->src_format.id);
+ add_format2index(t->dst_format.id);
}
if (!mod) {
@@ -1013,28 +1032,28 @@
ast_log(LOG_WARNING, "empty buf size, you need to supply one\n");
return -1;
}
- if (!t->table_cost && !(t->table_cost = generate_table_cost(t->srcfmt, t->dstfmt))) {
+ if (!t->table_cost && !(t->table_cost = generate_table_cost(&t->src_format, &t->dst_format))) {
ast_log(LOG_WARNING, "Table cost could not be generated for %s, "
"Please set table_cost variable on translator.\n", t->name);
return -1;
}
t->module = mod;
- t->srcfmt = format2index(t->srcfmt);
- t->dstfmt = format2index(t->dstfmt);
+ t->src_fmt_index = format2index(t->src_format.id);
+ t->dst_fmt_index = format2index(t->dst_format.id);
t->active = 1;
- if (t->srcfmt == -1 || t->dstfmt == -1) {
- ast_log(LOG_WARNING, "Invalid translator path: (%s codec is not valid)\n", t->srcfmt == -1 ? "starting" : "ending");
+ if (t->src_fmt_index == -1 || t->dst_fmt_index == -1) {
+ ast_log(LOG_WARNING, "Invalid translator path: (%s codec is not valid)\n", t->src_fmt_index == -1 ? "starting" : "ending");
return -1;
}
- if (t->srcfmt >= cur_max_index) {
- ast_log(LOG_WARNING, "Source format %s is larger than cur_max_index\n", ast_getformatname(t->srcfmt));
+ if (t->src_fmt_index >= cur_max_index) {
+ ast_log(LOG_WARNING, "Source format %s is larger than cur_max_index\n", ast_getformatname(&t->src_format));
return -1;
}
- if (t->dstfmt >= cur_max_index) {
- ast_log(LOG_WARNING, "Destination format %s is larger than cur_max_index\n", ast_getformatname(t->dstfmt));
+ if (t->dst_fmt_index >= cur_max_index) {
+ ast_log(LOG_WARNING, "Destination format %s is larger than cur_max_index\n", ast_getformatname(&t->dst_format));
return -1;
}
@@ -1057,20 +1076,15 @@
ast_verb(2, "Registered translator '%s' from format %s to %s, cost %d\n",
term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)),
- ast_getformatname(index2format(t->srcfmt)), ast_getformatname(index2format(t->dstfmt)), t->comp_cost);
-
- if (!added_cli) {
- ast_cli_register_multiple(cli_translate, ARRAY_LEN(cli_translate));
- added_cli++;
- }
+ ast_getformatname(&t->src_format), ast_getformatname(&t->dst_format), t->comp_cost);
AST_RWLIST_WRLOCK(&translators);
/* find any existing translators that provide this same srcfmt/dstfmt,
and put this one in order based on computational cost */
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&translators, u, list) {
- if ((u->srcfmt == t->srcfmt) &&
- (u->dstfmt == t->dstfmt) &&
+ if ((u->src_fmt_index == t->src_fmt_index) &&
+ (u->dst_fmt_index == t->dst_fmt_index) &&
(u->comp_cost > t->comp_cost)) {
AST_RWLIST_INSERT_BEFORE_CURRENT(t, list);
t = NULL;
@@ -1105,8 +1119,8 @@
AST_RWLIST_REMOVE_CURRENT(list);
ast_verb(2, "Unregistered translator '%s' from format %s to %s\n",
term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)),
- ast_getformatname(index2format(t->srcfmt)),
- ast_getformatname(index2format(t->dstfmt)));
+ ast_getformatname(&t->src_format),
+ ast_getformatname(&t->dst_format));
found = 1;
break;
}
@@ -1139,72 +1153,88 @@
}
/*! \brief Calculate our best translator source format, given costs, and a desired destination */
-format_t ast_translator_best_choice(format_t *dst, format_t *srcs)
-{
- int x,y;
+int ast_translator_best_choice(struct ast_cap *dst_cap,
+ struct ast_cap *src_cap,
+ struct ast_format *dst_fmt_out,
+ struct ast_format *src_fmt_out)
+{
int besttablecost = INT_MAX;
int beststeps = INT_MAX;
- format_t best = -1;
- format_t bestdst = 0;
- format_t cur, cursrc;
- format_t common = ((*dst) & (*srcs)) & AST_FORMAT_AUDIO_MASK; /* are there common formats ? */
-
- if (common) { /* yes, pick one and return */
- for (cur = 1, y = 0; y <= MAX_AUDIO_FORMAT; cur <<= 1, y++) {
- if (!(cur & common)) {
+ struct ast_format best;
+ struct ast_format bestdst;
+ struct ast_cap *joint_cap = ast_cap_joint(dst_cap, src_cap);
+ ast_format_clear(&best);
+ ast_format_clear(&bestdst);
+
+ if (joint_cap) { /* yes, pick one and return */
+ struct ast_format tmp_fmt;
+ ast_cap_iter_start(joint_cap);
+ while (!ast_cap_iter_next(joint_cap, &tmp_fmt)) {
+ /* We are guaranteed to find one common format. */
+ if (!best.id) {
+ ast_format_copy(&tmp_fmt, &best);
continue;
}
-
- /* We are guaranteed to find one common format. */
- if (best == -1) {
- best = cur;
+ /* If there are multiple common formats, pick the one with the highest sample rate */
+ if (ast_format_rate(&best) < ast_format_rate(&tmp_fmt)) {
+ ast_format_copy(&tmp_fmt, &best);
continue;
}
- /* If there are multiple common formats, pick the one with the highest sample rate */
- if (ast_format_rate(best) < ast_format_rate(cur)) {
- best = cur;
- continue;
- }
- }
+
+ }
+ ast_cap_iter_end(joint_cap);
+
/* We are done, this is a common format to both. */
- *srcs = *dst = best;
+ ast_format_copy(&best, dst_fmt_out);
+ ast_format_copy(&best, src_fmt_out);
+ ast_cap_destroy(joint_cap);
return 0;
} else { /* No, we will need to translate */
+ struct ast_format cur_dst;
+ struct ast_format cur_src;
AST_RWLIST_RDLOCK(&translators);
- for (cur = 1, y = 0; y <= MAX_AUDIO_FORMAT; cur <<= 1, y++) {
- if (! (cur & *dst)) {
- continue;
- }
- for (cursrc = 1, x = 0; x <= MAX_AUDIO_FORMAT; cursrc <<= 1, x++) {
- if (!(*srcs & cursrc) || !matrix_get(x, y)->step) {
+
+ ast_cap_iter_start(dst_cap);
+ while (!ast_cap_iter_next(dst_cap, &cur_dst)) {
+ ast_cap_iter_start(src_cap);
+ while (!ast_cap_iter_next(src_cap, &cur_src)) {
+ int x = format2index(cur_src.id);
+ int y = format2index(cur_dst.id);
+ if (x < 0 || y < 0) {
+ continue;
+ }
+ if (!matrix_get(x, y) || !(matrix_get(x, y)->step)) {
continue;
}
if ((matrix_get(x, y)->table_cost < besttablecost || matrix_get(x, y)->multistep < beststeps)) {
/* better than what we have so far */
- best = cursrc;
- bestdst = cur;
+ ast_format_copy(&cur_src, &best);
+ ast_format_copy(&cur_dst, &bestdst);
besttablecost = matrix_get(x, y)->table_cost;
beststeps = matrix_get(x, y)->multistep;
}
}
- }
+ ast_cap_iter_end(src_cap);
+ }
+
+ ast_cap_iter_end(dst_cap);
AST_RWLIST_UNLOCK(&translators);
- if (best > -1) {
- *srcs = best;
- *dst = bestdst;
- best = 0;
- }
- return best;
- }
-}
-
-unsigned int ast_translate_path_steps(format_t dest, format_t src)
+ if (best.id) {
+ ast_format_copy(&bestdst, dst_fmt_out);
+ ast_format_copy(&best, src_fmt_out);
+ return 0;
+ }
+ return -1;
+ }
+}
+
+unsigned int ast_translate_path_steps(struct ast_format *dst_format, struct ast_format *src_format)
{
unsigned int res = -1;
-
+ int src, dest;
/* convert bitwise format numbers into array indices */
- src = format2index(src);
- dest = format2index(dest);
+ src = format2index(src_format->id);
+ dest = format2index(dst_format->id);
if (src == -1 || dest == -1) {
ast_log(LOG_WARNING, "No translator path: (%s codec is not valid)\n", src == -1 ? "starting" : "ending");
@@ -1221,107 +1251,114 @@
return res;
}
-format_t ast_translate_available_formats(format_t dest, format_t src)
-{
- format_t res = dest;
- format_t tmp_fmt;
+void ast_translate_available_formats(struct ast_cap *dest, struct ast_cap *src, struct ast_cap *result)
+{
+ struct ast_format tmp_fmt;
+ struct ast_format cur_src;
+ int src_audio = 0;
+ int src_video = 0;
int index;
- format_t src_audio = src & AST_FORMAT_AUDIO_MASK;
- format_t src_video = src & AST_FORMAT_VIDEO_MASK;
+ ast_cap_remove_all(result);
+ ast_cap_append(dest, result);
/* if we don't have a source format, we just have to try all
possible destination formats */
if (!src) {
- return dest;
- }
-
- /* If we have a source audio format, get its format index */
- if (src_audio) {
- src_audio = format2index(src_audio);
- }
-
- /* If we have a source video format, get its format index */
- if (src_video) {
- src_video = format2index(src_video);
- }
-
- AST_RWLIST_RDLOCK(&translators);
-
- /* For a given source audio format, traverse the list of
- known audio formats to determine whether there exists
- a translation path from the source format to the
- destination format. */
- 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 & tmp_fmt)) {
- continue;
- }
-
- /* if the source is supplying this format, then
- we can leave it in the result */
- 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 (!matrix_get(src_audio, index)->step) {
- res &= ~tmp_fmt;
- continue;
- }
-
- /* now check the opposite direction */
- if (!matrix_get(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 (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 & tmp_fmt)) {
- continue;
- }
-
- /* if the source is supplying this format, then
- we can leave it in the result */
- 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 (!matrix_get(src_video, index)->step) {
- res &= ~tmp_fmt;
- continue;
- }
-
- /* now check the opposite direction */
- if (!matrix_get(index, src_video)->step) {
- res &= ~tmp_fmt;
- }
- }
-
- AST_RWLIST_UNLOCK(&translators);
-
+ return;
+ }
+
+ ast_cap_iter_start(src);
+ while (!ast_cap_iter_next(src, &cur_src)) {
+ /* If we have a source audio format, get its format index */
+ if (AST_FORMAT_GET_TYPE(cur_src.id) == AST_FORMAT_TYPE_AUDIO) {
+ src_audio = format2index(cur_src.id);
+ }
+
+ /* If we have a source video format, get its format index */
+ if (AST_FORMAT_GET_TYPE(cur_src.id) == AST_FORMAT_TYPE_VIDEO) {
+ src_video = format2index(cur_src.id);
+ }
+
+ AST_RWLIST_RDLOCK(&translators);
+
+ /* For a given source audio format, traverse the list of
+ known audio formats to determine whether there exists
+ a translation path from the source format to the
+ destination format. */
+ for (index = 0; (src_audio >= 0) && index < cur_max_index; index++) {
+ ast_format_set(&tmp_fmt, index2format(index), 0);
+
+ if (AST_FORMAT_GET_TYPE(tmp_fmt.id) != AST_FORMAT_TYPE_AUDIO) {
+ continue;
+ }
+
+ /* if this is not a desired format, nothing to do */
+ if (!ast_cap_iscompatible(dest, &tmp_fmt)) {
+ continue;
+ }
+
+ /* if the source is supplying this format, then
+ we can leave it in the result */
+ if (ast_cap_iscompatible(src, &tmp_fmt)) {
+ continue;
+ }
+
+ /* if we don't have a translation path from the src
+ to this format, remove it from the result */
+ if (!matrix_get(src_audio, index)->step) {
+ ast_cap_remove_byid(result, tmp_fmt.id);
+ continue;
+ }
+
+ /* now check the opposite direction */
+ if (!matrix_get(index, src_audio)->step) {
+ ast_cap_remove_byid(result, tmp_fmt.id);
+ }
+ }
+
+ /* 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 (index = 0; (src_video >= 0) && index < cur_max_index; index++) {
+ ast_format_set(&tmp_fmt, index2format(index), 0);
+ if (AST_FORMAT_GET_TYPE(tmp_fmt.id) != AST_FORMAT_TYPE_VIDEO) {
+ continue;
+ }
+
+ /* if this is not a desired format, nothing to do */
+ if (!ast_cap_iscompatible(dest, &tmp_fmt)) {
+ continue;
+ }
+
+ /* if the source is supplying this format, then
+ we can leave it in the result */
+ if (ast_cap_iscompatible(src, &tmp_fmt)) {
+ continue;
+ }
+
+ /* if we don't have a translation path from the src
+ to this format, remove it from the result */
+ if (!matrix_get(src_video, index)->step) {
+ ast_cap_remove_byid(result, tmp_fmt.id);
+ continue;
+ }
+
+ /* now check the opposite direction */
+ if (!matrix_get(index, src_video)->step) {
+ ast_cap_remove_byid(result, tmp_fmt.id);
+ }
+ }
+ AST_RWLIST_UNLOCK(&translators);
+ }
+ ast_cap_iter_end(src);
+}
+
+int ast_translate_init(void)
+{
+ int res = 0;
+ ast_rwlock_init(&tablelock);
+ res = matrix_resize(1);
+ res |= ast_cli_register_multiple(cli_translate, ARRAY_LEN(cli_translate));
return res;
}
-
-int ast_translate_init(void)
-{
- ast_rwlock_init(&tablelock);
- return matrix_resize(1);
-}
Modified: team/dvossel/fixtheworld_phase1_step3/main/udptl.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/udptl.c?view=diff&rev=301133&r1=301132&r2=301133
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/udptl.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/udptl.c Fri Jan 7 18:11:42 2011
@@ -381,7 +381,7 @@
/* Decode the secondary IFP packet */
//fprintf(stderr, "Secondary %d, len %d\n", seq_no - i, lengths[i - 1]);
s->f[ifp_no].frametype = AST_FRAME_MODEM;
- s->f[ifp_no].subclass.codec = AST_MODEM_T38;
+ s->f[ifp_no].subclass.integer = AST_MODEM_T38;
s->f[ifp_no].mallocd = 0;
s->f[ifp_no].seqno = seq_no - i;
@@ -483,7 +483,7 @@
if (repaired[l]) {
//fprintf(stderr, "Fixed packet %d, len %d\n", j, l);
s->f[ifp_no].frametype = AST_FRAME_MODEM;
- s->f[ifp_no].subclass.codec = AST_MODEM_T38;
+ s->f[ifp_no].subclass.integer = AST_MODEM_T38;
s->f[ifp_no].mallocd = 0;
s->f[ifp_no].seqno = j;
@@ -504,7 +504,7 @@
if (seq_no >= s->rx_seq_no) {
/* Decode the primary IFP packet */
s->f[ifp_no].frametype = AST_FRAME_MODEM;
- s->f[ifp_no].subclass.codec = AST_MODEM_T38;
+ s->f[ifp_no].subclass.integer = AST_MODEM_T38;
s->f[ifp_no].mallocd = 0;
s->f[ifp_no].seqno = seq_no;
@@ -1062,7 +1062,7 @@
return 0;
if ((f->frametype != AST_FRAME_MODEM) ||
- (f->subclass.codec != AST_MODEM_T38)) {
+ (f->subclass.integer != AST_MODEM_T38)) {
ast_log(LOG_WARNING, "(%s): UDPTL can only send T.38 data.\n",
LOG_TAG(s));
return -1;
More information about the asterisk-commits
mailing list