2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2006, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief Translate via the use of pseudo channels
23 * \author Mark Spencer <markster@digium.com>
28 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
31 #include <sys/resource.h>
33 #include "asterisk/lock.h"
34 #include "asterisk/channel.h"
35 #include "asterisk/translate.h"
36 #include "asterisk/module.h"
37 #include "asterisk/frame.h"
38 #include "asterisk/sched.h"
39 #include "asterisk/cli.h"
40 #include "asterisk/term.h"
42 #define MAX_RECALC 1000 /* max sample recalc */
44 /*! \brief the list of translators */
45 static AST_RWLIST_HEAD_STATIC(translators, ast_translator);
47 struct translator_path {
48 struct ast_translator *step; /*!< Next step translator */
49 unsigned int cost; /*!< Complete cost to destination */
50 unsigned int multistep; /*!< Multiple conversions required for this translation */
53 /*! \brief a matrix that, for any pair of supported formats,
54 * indicates the total cost of translation and the first step.
55 * The full path can be reconstricted iterating on the matrix
56 * until step->dstfmt == desired_format.
58 * Array indexes are 'src' and 'dest', in that order.
60 * Note: the lock in the 'translators' list is also used to protect
63 static struct translator_path tr_matrix[MAX_FORMAT][MAX_FORMAT];
66 * TODO: sample frames for each supported input format.
67 * We build this on the fly, by taking an SLIN frame and using
68 * the existing converter to play with it.
71 /*! \brief returns the index of the lowest bit set */
72 static force_inline int powerof(unsigned int d)
79 ast_log(LOG_WARNING, "No bits set? %d\n", d);
85 * wrappers around the translator routines.
89 * \brief Allocate the descriptor, required outbuf space,
90 * and possibly also plc and desc.
92 static void *newpvt(struct ast_translator *t)
94 struct ast_trans_pvt *pvt;
96 int useplc = t->plc_samples > 0 && t->useplc; /* cache, because it can change on the fly */
100 * compute the required size adding private descriptor,
101 * plc, buffer, AST_FRIENDLY_OFFSET.
103 len = sizeof(*pvt) + t->desc_size;
105 len += sizeof(plc_state_t);
107 len += AST_FRIENDLY_OFFSET + t->buf_size;
108 pvt = ast_calloc(1, len);
112 ofs = (char *)(pvt + 1); /* pointer to data space */
113 if (t->desc_size) { /* first comes the descriptor */
117 if (useplc) { /* then plc state */
118 pvt->plc = (plc_state_t *)ofs;
119 ofs += sizeof(plc_state_t);
121 if (t->buf_size) /* finally buffer and header */
122 pvt->outbuf = ofs + AST_FRIENDLY_OFFSET;
123 /* call local init routine, if present */
124 if (t->newpvt && t->newpvt(pvt)) {
128 ast_module_ref(t->module);
132 static void destroy(struct ast_trans_pvt *pvt)
134 struct ast_translator *t = pvt->t;
136 if (ast_test_flag(&pvt->f, AST_FRFLAG_FROM_TRANSLATOR)) {
137 /* If this flag is still set, that means that the translation path has
138 * been torn down, while we still have a frame out there being used.
139 * When ast_frfree() gets called on that frame, this ast_trans_pvt
140 * will get destroyed, too. */
150 ast_module_unref(t->module);
153 /*! \brief framein wrapper, deals with plc and bound checks. */
154 static int framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
156 int16_t *dst = (int16_t *)pvt->outbuf;
158 int samples = pvt->samples; /* initial value */
160 /* Copy the last in jb timing info to the pvt */
161 ast_copy_flags(&pvt->f, f, AST_FRFLAG_HAS_TIMING_INFO);
164 pvt->f.seqno = f->seqno;
166 if (f->samples == 0) {
167 ast_log(LOG_WARNING, "no samples for %s\n", pvt->t->name);
169 if (pvt->t->buffer_samples) { /* do not pass empty frames to callback */
170 if (f->datalen == 0) { /* perform PLC with nominal framesize of 20ms/160 samples */
172 int l = pvt->t->plc_samples;
173 if (pvt->samples + l > pvt->t->buffer_samples) {
174 ast_log(LOG_WARNING, "Out of buffer space\n");
177 l = plc_fillin(pvt->plc, dst + pvt->samples, l);
179 pvt->datalen = pvt->samples * 2; /* SLIN has 2bytes for 1sample */
181 /* We don't want generic PLC. If the codec has native PLC, then do that */
182 if (!pvt->t->native_plc)
185 if (pvt->samples + f->samples > pvt->t->buffer_samples) {
186 ast_log(LOG_WARNING, "Out of buffer space\n");
190 /* we require a framein routine, wouldn't know how to do
193 ret = pvt->t->framein(pvt, f);
194 /* possibly store data for plc */
195 if (!ret && pvt->plc) {
196 int l = pvt->t->plc_samples;
197 if (pvt->samples < l)
199 plc_rx(pvt->plc, dst + pvt->samples - l, l);
202 if (pvt->samples == samples)
203 ast_log(LOG_WARNING, "%s did not update samples %d\n",
204 pvt->t->name, pvt->samples);
208 /*! \brief generic frameout routine.
209 * If samples and datalen are 0, take whatever is in pvt
210 * and reset them, otherwise take the values in the caller and
211 * leave alone the pvt values.
213 struct ast_frame *ast_trans_frameout(struct ast_trans_pvt *pvt,
214 int datalen, int samples)
216 struct ast_frame *f = &pvt->f;
219 f->samples = samples;
221 if (pvt->samples == 0)
223 f->samples = pvt->samples;
227 f->datalen = datalen;
229 f->datalen = pvt->datalen;
233 f->frametype = AST_FRAME_VOICE;
234 f->subclass = 1 << (pvt->t->dstfmt);
236 f->offset = AST_FRIENDLY_OFFSET;
237 f->src = pvt->t->name;
238 f->data = pvt->outbuf;
240 ast_set_flag(f, AST_FRFLAG_FROM_TRANSLATOR);
245 static struct ast_frame *default_frameout(struct ast_trans_pvt *pvt)
247 return ast_trans_frameout(pvt, 0, 0);
250 /* end of callback wrappers and helpers */
252 void ast_translator_free_path(struct ast_trans_pvt *p)
254 struct ast_trans_pvt *pn = p;
261 /*! \brief Build a chain of translators based upon the given source and dest formats */
262 struct ast_trans_pvt *ast_translator_build_path(int dest, int source)
264 struct ast_trans_pvt *head = NULL, *tail = NULL;
266 source = powerof(source);
267 dest = powerof(dest);
269 AST_RWLIST_RDLOCK(&translators);
271 while (source != dest) {
272 struct ast_trans_pvt *cur;
273 struct ast_translator *t = tr_matrix[source][dest].step;
275 ast_log(LOG_WARNING, "No translator path from %s to %s\n",
276 ast_getformatname(source), ast_getformatname(dest));
277 AST_RWLIST_UNLOCK(&translators);
280 if (!(cur = newpvt(t))) {
281 ast_log(LOG_WARNING, "Failed to build translator step from %d to %d\n", source, dest);
283 ast_translator_free_path(head);
284 AST_RWLIST_UNLOCK(&translators);
292 cur->nextin = cur->nextout = ast_tv(0, 0);
293 /* Keep going if this isn't the final destination */
294 source = cur->t->dstfmt;
297 AST_RWLIST_UNLOCK(&translators);
301 static inline int format_rate(int format)
303 if (format == AST_FORMAT_G722 || format == AST_FORMAT_SLINEAR16)
309 /*! \brief do the actual translation */
310 struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f, int consume)
312 struct ast_trans_pvt *p = path;
313 struct ast_frame *out = f;
314 struct timeval delivery;
320 has_timing_info = ast_test_flag(f, AST_FRFLAG_HAS_TIMING_INFO);
325 /* XXX hmmm... check this below */
326 if (!ast_tvzero(f->delivery)) {
327 if (!ast_tvzero(path->nextin)) {
328 /* Make sure this is in line with what we were expecting */
329 if (!ast_tveq(path->nextin, f->delivery)) {
330 /* The time has changed between what we expected and this
331 most recent time on the new packet. If we have a
332 valid prediction adjust our output time appropriately */
333 if (!ast_tvzero(path->nextout)) {
334 path->nextout = ast_tvadd(path->nextout,
335 ast_tvsub(f->delivery, path->nextin));
337 path->nextin = f->delivery;
340 /* This is our first pass. Make sure the timing looks good */
341 path->nextin = f->delivery;
342 path->nextout = f->delivery;
344 /* Predict next incoming sample */
345 path->nextin = ast_tvadd(path->nextin, ast_samp2tv(f->samples, format_rate(f->subclass)));
347 delivery = f->delivery;
348 for ( ; out && p ; p = p->next) {
352 out = p->t->frameout(p);
358 /* we have a frame, play with times */
359 if (!ast_tvzero(delivery)) {
360 /* Regenerate prediction after a discontinuity */
361 if (ast_tvzero(path->nextout))
362 path->nextout = ast_tvnow();
364 /* Use next predicted outgoing timestamp */
365 out->delivery = path->nextout;
367 /* Predict next outgoing timestamp from samples in this
369 path->nextout = ast_tvadd(path->nextout, ast_samp2tv(out->samples, format_rate(out->subclass)));
371 out->delivery = ast_tv(0, 0);
372 ast_set2_flag(out, has_timing_info, AST_FRFLAG_HAS_TIMING_INFO);
373 if (has_timing_info) {
379 /* Invalidate prediction if we're entering a silence period */
380 if (out->frametype == AST_FRAME_CNG)
381 path->nextout = ast_tv(0, 0);
385 /*! \brief compute the cost of a single translation step */
386 static void calc_cost(struct ast_translator *t, int seconds)
389 struct ast_trans_pvt *pvt;
393 int out_rate = format_rate(t->dstfmt);
398 /* If they don't make samples, give them a terrible score */
400 ast_log(LOG_WARNING, "Translator '%s' does not produce sample frames.\n", t->name);
407 ast_log(LOG_WARNING, "Translator '%s' appears to be broken and will probably fail.\n", t->name);
412 getrusage(RUSAGE_SELF, &start);
414 /* Call the encoder until we've processed the required number of samples */
415 while (num_samples < seconds * out_rate) {
416 struct ast_frame *f = t->sample();
418 ast_log(LOG_WARNING, "Translator '%s' failed to produce a sample frame.\n", t->name);
425 while ((f = t->frameout(pvt))) {
426 num_samples += f->samples;
431 getrusage(RUSAGE_SELF, &end);
433 cost = ((end.ru_utime.tv_sec - start.ru_utime.tv_sec) * 1000000) + end.ru_utime.tv_usec - start.ru_utime.tv_usec;
434 cost += ((end.ru_stime.tv_sec - start.ru_stime.tv_sec) * 1000000) + end.ru_stime.tv_usec - start.ru_stime.tv_usec;
438 t->cost = cost / seconds;
445 * \brief rebuild a translation matrix.
446 * \note This function expects the list of translators to be locked
448 static void rebuild_matrix(int samples)
450 struct ast_translator *t;
451 int x; /* source format index */
452 int y; /* intermediate format index */
453 int z; /* destination format index */
455 ast_debug(1, "Resetting translation matrix\n");
457 bzero(tr_matrix, sizeof(tr_matrix));
459 /* first, compute all direct costs */
460 AST_RWLIST_TRAVERSE(&translators, t, list) {
468 calc_cost(t, samples);
470 if (!tr_matrix[x][z].step || t->cost < tr_matrix[x][z].cost) {
471 tr_matrix[x][z].step = t;
472 tr_matrix[x][z].cost = t->cost;
477 * For each triple x, y, z of distinct formats, check if there is
478 * a path from x to z through y which is cheaper than what is
479 * currently known, and in case, update the matrix.
480 * Repeat until the matrix is stable.
484 for (x = 0; x < MAX_FORMAT; x++) { /* source format */
485 for (y = 0; y < MAX_FORMAT; y++) { /* intermediate format */
486 if (x == y) /* skip ourselves */
489 for (z = 0; z<MAX_FORMAT; z++) { /* dst format */
492 if (z == x || z == y) /* skip null conversions */
494 if (!tr_matrix[x][y].step) /* no path from x to y */
496 if (!tr_matrix[y][z].step) /* no path from y to z */
498 newcost = tr_matrix[x][y].cost + tr_matrix[y][z].cost;
499 if (tr_matrix[x][z].step && newcost >= tr_matrix[x][z].cost)
500 continue; /* x->y->z is more expensive than
501 * the existing path */
502 /* ok, we can get from x to z via y with a cost that
503 is the sum of the transition from x to y and
506 tr_matrix[x][z].step = tr_matrix[x][y].step;
507 tr_matrix[x][z].cost = newcost;
508 tr_matrix[x][z].multistep = 1;
509 ast_debug(3, "Discovered %d cost path from %s to %s, via %d\n", tr_matrix[x][z].cost, ast_getformatname(x), ast_getformatname(z), y);
519 static char *handle_cli_core_show_translation(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
521 #define SHOW_TRANS 16
523 int curlen = 0, longest = 0;
527 e->command = "core show translation [recalc]";
529 "Usage: core show translation [recalc [<recalc seconds>]]\n"
530 " Displays known codec translators and the cost associated\n"
531 " with each conversion. If the argument 'recalc' is supplied along\n"
532 " with optional number of seconds to test a new test will be performed\n"
533 " as the chart is being displayed.\n";
540 return CLI_SHOWUSAGE;
542 if (a->argv[3] && !strcasecmp(a->argv[3], "recalc")) {
543 z = a->argv[4] ? atoi(a->argv[4]) : 1;
546 ast_cli(a->fd, " Recalc must be greater than 0. Defaulting to 1.\n");
550 if (z > MAX_RECALC) {
551 ast_cli(a->fd, " Maximum limit of recalc exceeded by %d, truncating value to %d\n", z - MAX_RECALC, MAX_RECALC);
554 ast_cli(a->fd, " Recalculating Codec Translation (number of sample seconds: %d)\n\n", z);
555 AST_RWLIST_WRLOCK(&translators);
557 AST_RWLIST_UNLOCK(&translators);
558 } else if (a->argc > 3)
559 return CLI_SHOWUSAGE;
561 AST_RWLIST_RDLOCK(&translators);
563 ast_cli(a->fd, " Translation times between formats (in microseconds) for one second of data\n");
564 ast_cli(a->fd, " Source Format (Rows) Destination Format (Columns)\n\n");
565 /* Get the length of the longest (usable?) codec name, so we know how wide the left side should be */
566 for (x = 0; x < SHOW_TRANS; x++) {
567 curlen = strlen(ast_getformatname(1 << (x)));
568 if (curlen > longest)
571 for (x = -1; x < SHOW_TRANS; x++) {
572 struct ast_str *out = ast_str_alloca(120);
573 /*Go ahead and move to next iteration if dealing with an unknown codec*/
574 if(x >= 0 && !strcmp(ast_getformatname(1 << (x)), "unknown"))
576 ast_str_set(&out, -1, " ");
577 for (y = -1; y < SHOW_TRANS; y++) {
578 /*Go ahead and move to next iteration if dealing with an unknown codec*/
579 if (y >= 0 && !strcmp(ast_getformatname(1 << (y)), "unknown"))
582 curlen = strlen(ast_getformatname(1 << (y)));
585 if (x >= 0 && y >= 0 && tr_matrix[x][y].step) {
586 /* XXX 99999 is a little hackish
587 We don't want this number being larger than the shortest (or current) codec
588 For now, that is "gsm" */
589 ast_str_append(&out, -1, "%*d", curlen + 1, tr_matrix[x][y].cost > 99999 ? 0 : tr_matrix[x][y].cost);
590 } else if (x == -1 && y >= 0) {
591 /* Top row - use a dynamic size */
592 ast_str_append(&out, -1, "%*s", curlen + 1, ast_getformatname(1 << (y)) );
593 } else if (y == -1 && x >= 0) {
594 /* Left column - use a static size. */
595 ast_str_append(&out, -1, "%*s", longest, ast_getformatname(1 << (x)) );
596 } else if (x >= 0 && y >= 0) {
597 ast_str_append(&out, -1, "%*s", curlen + 1, "-");
599 ast_str_append(&out, -1, "%*s", longest, "");
602 ast_str_append(&out, -1, "\n");
603 ast_cli(a->fd, out->str);
605 AST_RWLIST_UNLOCK(&translators);
609 static struct ast_cli_entry cli_translate[] = {
610 AST_CLI_DEFINE(handle_cli_core_show_translation, "Display translation matrix")
613 /*! \brief register codec translator */
614 int __ast_register_translator(struct ast_translator *t, struct ast_module *mod)
616 static int added_cli = 0;
617 struct ast_translator *u;
621 ast_log(LOG_WARNING, "Missing module pointer, you need to supply one\n");
626 ast_log(LOG_WARNING, "empty buf size, you need to supply one\n");
632 t->srcfmt = powerof(t->srcfmt);
633 t->dstfmt = powerof(t->dstfmt);
636 if (t->plc_samples) {
637 if (t->buffer_samples < t->plc_samples) {
638 ast_log(LOG_WARNING, "plc_samples %d buffer_samples %d\n",
639 t->plc_samples, t->buffer_samples);
642 if (t->dstfmt != powerof(AST_FORMAT_SLINEAR))
643 ast_log(LOG_WARNING, "plc_samples %d format %x\n",
644 t->plc_samples, t->dstfmt);
646 if (t->srcfmt >= MAX_FORMAT) {
647 ast_log(LOG_WARNING, "Source format %s is larger than MAX_FORMAT\n", ast_getformatname(t->srcfmt));
651 if (t->dstfmt >= MAX_FORMAT) {
652 ast_log(LOG_WARNING, "Destination format %s is larger than MAX_FORMAT\n", ast_getformatname(t->dstfmt));
658 * Align buf_size properly, rounding up to the machine-specific
659 * alignment for pointers.
661 struct _test_align { void *a, *b; } p;
662 int align = (char *)&p.b - (char *)&p.a;
664 t->buf_size = ((t->buf_size + align - 1) / align) * align;
667 if (t->frameout == NULL)
668 t->frameout = default_frameout;
672 ast_verb(2, "Registered translator '%s' from format %s to %s, cost %d\n",
673 term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)),
674 ast_getformatname(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt), t->cost);
677 ast_cli_register_multiple(cli_translate, sizeof(cli_translate) / sizeof(struct ast_cli_entry));
681 AST_RWLIST_WRLOCK(&translators);
683 /* find any existing translators that provide this same srcfmt/dstfmt,
684 and put this one in order based on cost */
685 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&translators, u, list) {
686 if ((u->srcfmt == t->srcfmt) &&
687 (u->dstfmt == t->dstfmt) &&
688 (u->cost > t->cost)) {
689 AST_RWLIST_INSERT_BEFORE_CURRENT(t, list);
693 AST_RWLIST_TRAVERSE_SAFE_END;
695 /* if no existing translator was found for this format combination,
696 add it to the beginning of the list */
698 AST_RWLIST_INSERT_HEAD(&translators, t, list);
702 AST_RWLIST_UNLOCK(&translators);
707 /*! \brief unregister codec translator */
708 int ast_unregister_translator(struct ast_translator *t)
711 struct ast_translator *u;
714 AST_RWLIST_WRLOCK(&translators);
715 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&translators, u, list) {
717 AST_RWLIST_REMOVE_CURRENT(list);
718 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(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt));
723 AST_RWLIST_TRAVERSE_SAFE_END;
728 AST_RWLIST_UNLOCK(&translators);
733 void ast_translator_activate(struct ast_translator *t)
735 AST_RWLIST_WRLOCK(&translators);
738 AST_RWLIST_UNLOCK(&translators);
741 void ast_translator_deactivate(struct ast_translator *t)
743 AST_RWLIST_WRLOCK(&translators);
746 AST_RWLIST_UNLOCK(&translators);
749 /*! \brief Calculate our best translator source format, given costs, and a desired destination */
750 int ast_translator_best_choice(int *dst, int *srcs)
756 int besttime = INT_MAX;
757 int beststeps = INT_MAX;
758 int common = ((*dst) & (*srcs)) & AST_FORMAT_AUDIO_MASK; /* are there common formats ? */
760 if (common) { /* yes, pick one and return */
761 for (cur = 1, y = 0; y <= MAX_AUDIO_FORMAT; cur <<= 1, y++) {
762 if (cur & common) /* guaranteed to find one */
765 /* We are done, this is a common format to both. */
768 } else { /* No, we will need to translate */
769 AST_RWLIST_RDLOCK(&translators);
770 for (cur = 1, y = 0; y <= MAX_AUDIO_FORMAT; cur <<= 1, y++) {
773 for (cursrc = 1, x = 0; x <= MAX_AUDIO_FORMAT; cursrc <<= 1, x++) {
774 if (!(*srcs & cursrc) || !tr_matrix[x][y].step ||
775 tr_matrix[x][y].cost > besttime)
776 continue; /* not existing or no better */
777 if (tr_matrix[x][y].cost < besttime ||
778 tr_matrix[x][y].multistep < beststeps) {
779 /* better than what we have so far */
782 besttime = tr_matrix[x][y].cost;
783 beststeps = tr_matrix[x][y].multistep;
787 AST_RWLIST_UNLOCK(&translators);
797 unsigned int ast_translate_path_steps(unsigned int dest, unsigned int src)
799 unsigned int res = -1;
801 /* convert bitwise format numbers into array indices */
803 dest = powerof(dest);
805 AST_RWLIST_RDLOCK(&translators);
807 if (tr_matrix[src][dest].step)
808 res = tr_matrix[src][dest].multistep + 1;
810 AST_RWLIST_UNLOCK(&translators);
815 unsigned int ast_translate_available_formats(unsigned int dest, unsigned int src)
817 unsigned int res = dest;
819 unsigned int src_audio = src & AST_FORMAT_AUDIO_MASK;
820 unsigned int src_video = src & AST_FORMAT_VIDEO_MASK;
822 /* if we don't have a source format, we just have to try all
823 possible destination formats */
827 /* If we have a source audio format, get its format index */
829 src_audio = powerof(src_audio);
831 /* If we have a source video format, get its format index */
833 src_video = powerof(src_video);
835 AST_RWLIST_RDLOCK(&translators);
837 /* For a given source audio format, traverse the list of
838 known audio formats to determine whether there exists
839 a translation path from the source format to the
840 destination format. */
841 for (x = 1; src_audio && (x & AST_FORMAT_AUDIO_MASK); x <<= 1) {
842 /* if this is not a desired format, nothing to do */
846 /* if the source is supplying this format, then
847 we can leave it in the result */
851 /* if we don't have a translation path from the src
852 to this format, remove it from the result */
853 if (!tr_matrix[src_audio][powerof(x)].step) {
858 /* now check the opposite direction */
859 if (!tr_matrix[powerof(x)][src_audio].step)
863 /* For a given source video format, traverse the list of
864 known video formats to determine whether there exists
865 a translation path from the source format to the
866 destination format. */
867 for (; src_video && (x & AST_FORMAT_VIDEO_MASK); x <<= 1) {
868 /* if this is not a desired format, nothing to do */
872 /* if the source is supplying this format, then
873 we can leave it in the result */
877 /* if we don't have a translation path from the src
878 to this format, remove it from the result */
879 if (!tr_matrix[src_video][powerof(x)].step) {
884 /* now check the opposite direction */
885 if (!tr_matrix[powerof(x)][src_video].step)
889 AST_RWLIST_UNLOCK(&translators);
894 void ast_translate_frame_freed(struct ast_frame *fr)
896 struct ast_trans_pvt *pvt;
898 ast_clear_flag(fr, AST_FRFLAG_FROM_TRANSLATOR);
900 pvt = (struct ast_trans_pvt *) (((char *) fr) - offsetof(struct ast_trans_pvt, f));