#include <asterisk/frame.h>Go to the source code of this file.
Data Structures | |
| struct | ast_translator |
| data structure associated with a translator More... | |
Defines | |
| #define | MAX_FORMAT 32 |
Functions | |
| int | ast_register_translator (struct ast_translator *t) |
| Register a translator. | |
| int | ast_unregister_translator (struct ast_translator *t) |
| Unregister a translator. | |
| int | ast_translator_best_choice (int *dsts, int *srcs) |
| Chooses the best translation path. | |
| ast_trans_pvt * | ast_translator_build_path (int dest, int source) |
| Builds a translator path. | |
| void | ast_translator_free_path (struct ast_trans_pvt *tr) |
| Frees a translator path. | |
| ast_frame * | ast_translate (struct ast_trans_pvt *tr, struct ast_frame *f, int consume) |
| translates one or more frames | |
|
|
Definition at line 17 of file translate.h. Referenced by ast_register_translator(), and ast_translator_best_choice(). |
|
|
Register a translator.
Definition at line 290 of file translate.c. References ast_cli_register(), ast_getformatname(), ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_verbose(), COLOR_BLACK, COLOR_MAGENTA, ast_translator::cost, ast_translator::dstfmt, LOG_WARNING, MAX_FORMAT, ast_translator::name, ast_translator::next, option_verbose, ast_translator::srcfmt, term_color(), and VERBOSE_PREFIX_2.
00291 {
00292 char tmp[80];
00293 t->srcfmt = powerof(t->srcfmt);
00294 t->dstfmt = powerof(t->dstfmt);
00295 if ((t->srcfmt >= MAX_FORMAT) || (t->dstfmt >= MAX_FORMAT)) {
00296 ast_log(LOG_WARNING, "Format %s is larger than MAX_FORMAT\n", ast_getformatname(t->srcfmt));
00297 return -1;
00298 }
00299 calc_cost(t);
00300 if (option_verbose > 1)
00301 ast_verbose(VERBOSE_PREFIX_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(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt), t->cost);
00302 ast_mutex_lock(&list_lock);
00303 if (!added_cli) {
00304 ast_cli_register(&show_trans);
00305 added_cli++;
00306 }
00307 t->next = list;
00308 list = t;
00309 rebuild_matrix();
00310 ast_mutex_unlock(&list_lock);
00311 return 0;
00312 }
|
|
||||||||||||||||
|
translates one or more frames
Definition at line 130 of file translate.c. References ast_frfree(), ast_log(), ast_translator::framein, LOG_WARNING, and ast_trans_pvt::step. Referenced by ast_read(), ast_write(), and ast_writestream().
00131 {
00132 struct ast_trans_pvt *p;
00133 struct ast_frame *out;
00134 p = path;
00135 /* Feed the first frame into the first translator */
00136 p->step->framein(p->state, f);
00137 if (consume)
00138 ast_frfree(f);
00139 while(p) {
00140 out = p->step->frameout(p->state);
00141 /* If we get nothing out, return NULL */
00142 if (!out)
00143 return NULL;
00144 /* If there is a next state, feed it in there. If not,
00145 return this frame */
00146 if (p->next)
00147 p->next->step->framein(p->next->state, out);
00148 else
00149 return out;
00150 p = p->next;
00151 }
00152 ast_log(LOG_WARNING, "I should never get here...\n");
00153 return NULL;
00154 }
|
|
||||||||||||
|
Chooses the best translation path. Given a list of sources, and a designed destination format, which should I choose? Returns 0 on success, -1 if no path could be found. Modifies dests and srcs in place Definition at line 335 of file translate.c. References ast_mutex_lock, ast_mutex_unlock, ast_translator_dir::cost, MAX_FORMAT, and ast_translator_dir::step. Referenced by ast_channel_make_compatible(), ast_request(), ast_set_read_format(), and ast_set_write_format().
00336 {
00337 /* Calculate our best source format, given costs, and a desired destination */
00338 int x,y;
00339 int best=-1;
00340 int bestdst=0;
00341 int cur = 1;
00342 int besttime=999999999;
00343 ast_mutex_lock(&list_lock);
00344 for (y=0;y<MAX_FORMAT;y++) {
00345 if ((cur & *dst) && (cur & *srcs)) {
00346 /* This is a common format to both. Pick it if we don't have one already */
00347 besttime=0;
00348 bestdst = cur;
00349 best = cur;
00350 break;
00351 }
00352 if (cur & *dst)
00353 for (x=0;x<MAX_FORMAT;x++) {
00354 if (tr_matrix[x][y].step && /* There's a step */
00355 (tr_matrix[x][y].cost < besttime) && /* We're better than what exists now */
00356 (*srcs & (1 << x))) /* x is a valid source format */
00357 {
00358 best = 1 << x;
00359 bestdst = cur;
00360 besttime = tr_matrix[x][y].cost;
00361 }
00362 }
00363 cur = cur << 1;
00364 }
00365 if (best > -1) {
00366 *srcs = best;
00367 *dst = bestdst;
00368 best = 0;
00369 }
00370 ast_mutex_unlock(&list_lock);
00371 return best;
00372 }
|
|
||||||||||||
|
Builds a translator path.
Definition at line 84 of file translate.c. References ast_getformatname(), ast_log(), free, LOG_WARNING, malloc, ast_translator::new, and ast_translator_dir::step. Referenced by ast_set_read_format(), ast_set_write_format(), and ast_writestream().
00085 {
00086 struct ast_trans_pvt *tmpr = NULL, *tmp = NULL;
00087 /* One of the hardest parts: Build a set of translators based upon
00088 the given source and destination formats */
00089 source = powerof(source);
00090 dest = powerof(dest);
00091 while(source != dest) {
00092 if (tr_matrix[source][dest].step) {
00093 if (tmp) {
00094 tmp->next = malloc(sizeof(struct ast_trans_pvt));
00095 tmp = tmp->next;
00096 } else
00097 tmp = malloc(sizeof(struct ast_trans_pvt));
00098
00099
00100 if (tmp) {
00101 tmp->next = NULL;
00102 tmp->step = tr_matrix[source][dest].step;
00103 tmp->state = tmp->step->new();
00104 if (!tmp->state) {
00105 ast_log(LOG_WARNING, "Failed to build translator step from %d to %d\n", source, dest);
00106 free(tmp);
00107 tmp = NULL;
00108 return NULL;
00109 }
00110 /* Set the root, if it doesn't exist yet... */
00111 if (!tmpr)
00112 tmpr = tmp;
00113 /* Keep going if this isn't the final destination */
00114 source = tmp->step->dstfmt;
00115 } else {
00116 /* XXX This could leak XXX */
00117 ast_log(LOG_WARNING, "Out of memory\n");
00118 return NULL;
00119 }
00120 } else {
00121 /* We shouldn't have allocated any memory */
00122 ast_log(LOG_WARNING, "No translator path from %s to %s\n",
00123 ast_getformatname(source), ast_getformatname(dest));
00124 return NULL;
00125 }
00126 }
00127 return tmpr;
00128 }
|
|
|
Frees a translator path.
Definition at line 71 of file translate.c. References ast_translator::destroy, free, ast_trans_pvt::next, and ast_trans_pvt::step. Referenced by ast_channel_free(), ast_closestream(), ast_set_read_format(), ast_set_write_format(), and ast_writestream().
00072 {
00073 struct ast_trans_pvt *pl, *pn;
00074 pn = p;
00075 while(pn) {
00076 pl = pn;
00077 pn = pn->next;
00078 if (pl->state && pl->step->destroy)
00079 pl->step->destroy(pl->state);
00080 free(pl);
00081 }
00082 }
|
|
|
Unregister a translator.
Definition at line 314 of file translate.c. References ast_mutex_lock, ast_mutex_unlock, and ast_translator::next.
00315 {
00316 struct ast_translator *u, *ul = NULL;
00317 ast_mutex_lock(&list_lock);
00318 u = list;
00319 while(u) {
00320 if (u == t) {
00321 if (ul)
00322 ul->next = u->next;
00323 else
00324 list = u->next;
00325 break;
00326 }
00327 ul = u;
00328 u = u->next;
00329 }
00330 rebuild_matrix();
00331 ast_mutex_unlock(&list_lock);
00332 return (u ? 0 : -1);
00333 }
|
1.3.6-20040222