Wed Aug 11 01:10:35 2010

Asterisk developer's documentation


translate.h File Reference

Support for translation of data formats. translate.c. More...

#include "asterisk/frame.h"
#include "asterisk/plc.h"
#include "asterisk/linkedlists.h"

Include dependency graph for translate.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_trans_pvt
 Default structure for translators, with the basic fields and buffers, all allocated as part of the same chunk of memory. The buffer is preceded by AST_FRIENDLY_OFFSET bytes in front of the user portion. 'buf' points right after this space. More...
struct  ast_translator
 Descriptor of a translator. More...

Defines

#define ast_register_translator(t)   __ast_register_translator(t, ast_module_info->self)
 See __ast_register_translator().
#define MAX_AUDIO_FORMAT   15
#define MAX_FORMAT   32

Functions

int __ast_register_translator (struct ast_translator *t, struct ast_module *module)
 Register a translator This registers a codec translator with asterisk.
struct ast_frame * ast_trans_frameout (struct ast_trans_pvt *pvt, int datalen, int samples)
 generic frameout function
struct ast_frame * ast_translate (struct ast_trans_pvt *tr, struct ast_frame *f, int consume)
 translates one or more frames Apply an input frame into the translator and receive zero or one output frames. Consume determines whether the original frame should be freed
unsigned int ast_translate_available_formats (unsigned int dest, unsigned int src)
 Mask off unavailable formats from a format bitmask.
void ast_translate_frame_freed (struct ast_frame *fr)
 Hint that a frame from a translator has been freed.
unsigned int ast_translate_path_steps (unsigned int dest, unsigned int src)
 Returns the number of steps required to convert from 'src' to 'dest'.
void ast_translator_activate (struct ast_translator *t)
 Activate a previously deactivated translator.
int ast_translator_best_choice (int *dsts, int *srcs)
 Chooses the best translation path.
struct ast_trans_pvt * ast_translator_build_path (int dest, int source)
 Builds a translator path Build a path (possibly NULL) from source to dest.
void ast_translator_deactivate (struct ast_translator *t)
 Deactivate a translator.
void ast_translator_free_path (struct ast_trans_pvt *tr)
 Frees a translator path Frees the given translator path structure.
int ast_unregister_translator (struct ast_translator *t)
 Unregister a translator Unregisters the given tranlator.


Detailed Description

Support for translation of data formats. translate.c.

Definition in file translate.h.


Define Documentation

#define ast_register_translator ( t   )     __ast_register_translator(t, ast_module_info->self)

See __ast_register_translator().

Definition at line 173 of file translate.h.

Referenced by load_module(), and register_translator().

#define MAX_AUDIO_FORMAT   15

Definition at line 27 of file translate.h.

Referenced by ast_translator_best_choice().

#define MAX_FORMAT   32

Definition at line 28 of file translate.h.

Referenced by __ast_register_translator(), and rebuild_matrix().


Function Documentation

int __ast_register_translator ( struct ast_translator *  t,
struct ast_module *  mod 
)

Register a translator This registers a codec translator with asterisk.

Parameters:
t populated ast_translator structure
module handle to the module that owns this translator
Returns:
0 on success, -1 on failure

Definition at line 596 of file translate.c.

References ast_translator::active, ARRAY_LEN, ast_cli_register_multiple(), ast_getformatname(), ast_log(), AST_RWLIST_INSERT_BEFORE_CURRENT, AST_RWLIST_INSERT_HEAD, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_translator::buf_size, calc_cost(), COLOR_BLACK, COLOR_MAGENTA, ast_translator::cost, default_frameout(), ast_translator::dstfmt, ast_translator::frameout, LOG_WARNING, MAX_FORMAT, ast_translator::module, ast_translator::name, powerof(), rebuild_matrix(), ast_translator::srcfmt, and term_color().

00597 {
00598    static int added_cli = 0;
00599    struct ast_translator *u;
00600    char tmp[80];
00601 
00602    if (!mod) {
00603       ast_log(LOG_WARNING, "Missing module pointer, you need to supply one\n");
00604       return -1;
00605    }
00606 
00607    if (!t->buf_size) {
00608       ast_log(LOG_WARNING, "empty buf size, you need to supply one\n");
00609       return -1;
00610    }
00611 
00612    t->module = mod;
00613 
00614    t->srcfmt = powerof(t->srcfmt);
00615    t->dstfmt = powerof(t->dstfmt);
00616    t->active = 1;
00617 
00618    if (t->srcfmt == -1 || t->dstfmt == -1) {
00619       ast_log(LOG_WARNING, "Invalid translator path: (%s codec is not valid)\n", t->srcfmt == -1 ? "starting" : "ending");
00620       return -1;
00621    }
00622 
00623    if (t->srcfmt >= MAX_FORMAT) {
00624       ast_log(LOG_WARNING, "Source format %s is larger than MAX_FORMAT\n", ast_getformatname(t->srcfmt));
00625       return -1;
00626    }
00627 
00628    if (t->dstfmt >= MAX_FORMAT) {
00629       ast_log(LOG_WARNING, "Destination format %s is larger than MAX_FORMAT\n", ast_getformatname(t->dstfmt));
00630       return -1;
00631    }
00632 
00633    if (t->buf_size) {
00634       /*
00635        * Align buf_size properly, rounding up to the machine-specific
00636        * alignment for pointers.
00637        */
00638       struct _test_align { void *a, *b; } p;
00639       int align = (char *)&p.b - (char *)&p.a;
00640 
00641       t->buf_size = ((t->buf_size + align - 1) / align) * align;
00642    }
00643 
00644    if (t->frameout == NULL)
00645       t->frameout = default_frameout;
00646   
00647    calc_cost(t, 1);
00648 
00649    ast_verb(2, "Registered translator '%s' from format %s to %s, cost %d\n",
00650              term_color(tmp, t->name, COLOR_MAGENTA, COLOR_BLACK, sizeof(tmp)),
00651              ast_getformatname(1 << t->srcfmt), ast_getformatname(1 << t->dstfmt), t->cost);
00652 
00653    if (!added_cli) {
00654       ast_cli_register_multiple(cli_translate, ARRAY_LEN(cli_translate));
00655       added_cli++;
00656    }
00657 
00658    AST_RWLIST_WRLOCK(&translators);
00659 
00660    /* find any existing translators that provide this same srcfmt/dstfmt,
00661       and put this one in order based on cost */
00662    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&translators, u, list) {
00663       if ((u->srcfmt == t->srcfmt) &&
00664           (u->dstfmt == t->dstfmt) &&
00665           (u->cost > t->cost)) {
00666          AST_RWLIST_INSERT_BEFORE_CURRENT(t, list);
00667          t = NULL;
00668          break;
00669       }
00670    }
00671    AST_RWLIST_TRAVERSE_SAFE_END;
00672 
00673    /* if no existing translator was found for this format combination,
00674       add it to the beginning of the list */
00675    if (t)
00676       AST_RWLIST_INSERT_HEAD(&translators, t, list);
00677 
00678    rebuild_matrix(0);
00679 
00680    AST_RWLIST_UNLOCK(&translators);
00681 
00682    return 0;
00683 }

struct ast_frame* ast_trans_frameout ( struct ast_trans_pvt *  pvt,
int  datalen,
int  samples 
) [read]

generic frameout function

Definition at line 189 of file translate.c.

References AST_FRAME_VOICE, AST_FRFLAG_FROM_TRANSLATOR, AST_FRIENDLY_OFFSET, ast_set_flag, ast_trans_pvt::c, ast_frame::data, ast_trans_pvt::datalen, ast_frame::datalen, ast_translator::dstfmt, ast_trans_pvt::f, f, ast_frame::frametype, ast_frame::mallocd, ast_translator::name, ast_frame::offset, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::samples, ast_frame::samples, ast_frame::src, ast_frame::subclass, and ast_trans_pvt::t.

Referenced by default_frameout(), lintoadpcm_frameout(), lintogsm_frameout(), lintoilbc_frameout(), lintolpc10_frameout(), and lintospeex_frameout().

00191 {
00192    struct ast_frame *f = &pvt->f;
00193 
00194    if (samples)
00195       f->samples = samples;
00196    else {
00197       if (pvt->samples == 0)
00198          return NULL;
00199       f->samples = pvt->samples;
00200       pvt->samples = 0;
00201    }
00202    if (datalen)
00203       f->datalen = datalen;
00204    else {
00205       f->datalen = pvt->datalen;
00206       pvt->datalen = 0;
00207    }
00208 
00209    f->frametype = AST_FRAME_VOICE;
00210    f->subclass = 1 << (pvt->t->dstfmt);
00211    f->mallocd = 0;
00212    f->offset = AST_FRIENDLY_OFFSET;
00213    f->src = pvt->t->name;
00214    f->data.ptr = pvt->outbuf.c;
00215 
00216    ast_set_flag(f, AST_FRFLAG_FROM_TRANSLATOR);
00217 
00218    return f;
00219 }

struct ast_frame* ast_translate ( struct ast_trans_pvt *  path,
struct ast_frame *  f,
int  consume 
) [read]

translates one or more frames Apply an input frame into the translator and receive zero or one output frames. Consume determines whether the original frame should be freed

Parameters:
tr translator structure to use for translation
f frame to translate
consume Whether or not to free the original frame
Returns:
an ast_frame of the new translation format on success, NULL on failure

Definition at line 283 of file translate.c.

References ast_format_rate(), AST_FRAME_CNG, AST_FRFLAG_HAS_TIMING_INFO, ast_frfree, ast_samp2tv(), ast_set2_flag, ast_test_flag, ast_tv(), ast_tvadd(), ast_tveq(), ast_tvnow(), ast_tvsub(), ast_tvzero(), ast_frame::delivery, framein(), ast_frame::frametype, ast_frame::len, len(), ast_trans_pvt::next, ast_trans_pvt::nextin, ast_trans_pvt::nextout, ast_frame::samples, ast_frame::seqno, ast_frame::subclass, and ast_frame::ts.

Referenced by __ast_read(), ast_audiohook_read_frame(), ast_slinfactory_feed(), ast_write(), ast_writestream(), audio_audiohook_write_list(), and conf_run().

00284 {
00285    struct ast_trans_pvt *p = path;
00286    struct ast_frame *out = f;
00287    struct timeval delivery;
00288    int has_timing_info;
00289    long ts;
00290    long len;
00291    int seqno;
00292 
00293    has_timing_info = ast_test_flag(f, AST_FRFLAG_HAS_TIMING_INFO);
00294    ts = f->ts;
00295    len = f->len;
00296    seqno = f->seqno;
00297 
00298    /* XXX hmmm... check this below */
00299    if (!ast_tvzero(f->delivery)) {
00300       if (!ast_tvzero(path->nextin)) {
00301          /* Make sure this is in line with what we were expecting */
00302          if (!ast_tveq(path->nextin, f->delivery)) {
00303             /* The time has changed between what we expected and this
00304                most recent time on the new packet.  If we have a
00305                valid prediction adjust our output time appropriately */
00306             if (!ast_tvzero(path->nextout)) {
00307                path->nextout = ast_tvadd(path->nextout,
00308                           ast_tvsub(f->delivery, path->nextin));
00309             }
00310             path->nextin = f->delivery;
00311          }
00312       } else {
00313          /* This is our first pass.  Make sure the timing looks good */
00314          path->nextin = f->delivery;
00315          path->nextout = f->delivery;
00316       }
00317       /* Predict next incoming sample */
00318       path->nextin = ast_tvadd(path->nextin, ast_samp2tv(f->samples, ast_format_rate(f->subclass)));
00319    }
00320    delivery = f->delivery;
00321    for ( ; out && p ; p = p->next) {
00322       framein(p, out);
00323       if (out != f)
00324          ast_frfree(out);
00325       out = p->t->frameout(p);
00326    }
00327    if (consume)
00328       ast_frfree(f);
00329    if (out == NULL)
00330       return NULL;
00331    /* we have a frame, play with times */
00332    if (!ast_tvzero(delivery)) {
00333       /* Regenerate prediction after a discontinuity */
00334       if (ast_tvzero(path->nextout))
00335          path->nextout = ast_tvnow();
00336 
00337       /* Use next predicted outgoing timestamp */
00338       out->delivery = path->nextout;
00339       
00340       /* Predict next outgoing timestamp from samples in this
00341          frame. */
00342       path->nextout = ast_tvadd(path->nextout, ast_samp2tv(out->samples, ast_format_rate(out->subclass)));
00343    } else {
00344       out->delivery = ast_tv(0, 0);
00345       ast_set2_flag(out, has_timing_info, AST_FRFLAG_HAS_TIMING_INFO);
00346       if (has_timing_info) {
00347          out->ts = ts;
00348          out->len = len;
00349          out->seqno = seqno;
00350       }
00351    }
00352    /* Invalidate prediction if we're entering a silence period */
00353    if (out->frametype == AST_FRAME_CNG)
00354       path->nextout = ast_tv(0, 0);
00355    return out;
00356 }

unsigned int ast_translate_available_formats ( unsigned int  dest,
unsigned int  src 
)

Mask off unavailable formats from a format bitmask.

Parameters:
dest possible destination formats
src source formats
Returns:
the destination formats that are available in the source or translatable
The result will include all formats from 'dest' that are either present in 'src' or translatable from a format present in 'src'.

Note:
Only a single audio format and a single video format can be present in 'src', or the function will produce unexpected results.

Definition at line 797 of file translate.c.

References AST_FORMAT_AUDIO_MASK, AST_FORMAT_VIDEO_MASK, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, powerof(), translator_path::step, and tr_matrix.

Referenced by sip_call().

00798 {
00799    unsigned int res = dest;
00800    unsigned int x;
00801    unsigned int src_audio = src & AST_FORMAT_AUDIO_MASK;
00802    unsigned int src_video = src & AST_FORMAT_VIDEO_MASK;
00803 
00804    /* if we don't have a source format, we just have to try all
00805       possible destination formats */
00806    if (!src)
00807       return dest;
00808 
00809    /* If we have a source audio format, get its format index */
00810    if (src_audio)
00811       src_audio = powerof(src_audio);
00812 
00813    /* If we have a source video format, get its format index */
00814    if (src_video)
00815       src_video = powerof(src_video);
00816 
00817    AST_RWLIST_RDLOCK(&translators);
00818 
00819    /* For a given source audio format, traverse the list of
00820       known audio formats to determine whether there exists
00821       a translation path from the source format to the
00822       destination format. */
00823    for (x = 1; src_audio && (x & AST_FORMAT_AUDIO_MASK); x <<= 1) {
00824       /* if this is not a desired format, nothing to do */
00825       if (!(dest & x))
00826          continue;
00827 
00828       /* if the source is supplying this format, then
00829          we can leave it in the result */
00830       if (src & x)
00831          continue;
00832 
00833       /* if we don't have a translation path from the src
00834          to this format, remove it from the result */
00835       if (!tr_matrix[src_audio][powerof(x)].step) {
00836          res &= ~x;
00837          continue;
00838       }
00839 
00840       /* now check the opposite direction */
00841       if (!tr_matrix[powerof(x)][src_audio].step)
00842          res &= ~x;
00843    }
00844 
00845    /* For a given source video format, traverse the list of
00846       known video formats to determine whether there exists
00847       a translation path from the source format to the
00848       destination format. */
00849    for (; src_video && (x & AST_FORMAT_VIDEO_MASK); x <<= 1) {
00850       /* if this is not a desired format, nothing to do */
00851       if (!(dest & x))
00852          continue;
00853 
00854       /* if the source is supplying this format, then
00855          we can leave it in the result */
00856       if (src & x)
00857          continue;
00858 
00859       /* if we don't have a translation path from the src
00860          to this format, remove it from the result */
00861       if (!tr_matrix[src_video][powerof(x)].step) {
00862          res &= ~x;
00863          continue;
00864       }
00865 
00866       /* now check the opposite direction */
00867       if (!tr_matrix[powerof(x)][src_video].step)
00868          res &= ~x;
00869    }
00870 
00871    AST_RWLIST_UNLOCK(&translators);
00872 
00873    return res;
00874 }

void ast_translate_frame_freed ( struct ast_frame *  fr  ) 

Hint that a frame from a translator has been freed.

This is sort of a hack. This function gets called when ast_frame_free() gets called on a frame that has the AST_FRFLAG_FROM_TRANSLATOR flag set. This is because it is possible for a translation path to be destroyed while a frame from a translator is still in use. Specifically, this happens if a masquerade happens after a call to ast_read() but before the frame is done being processed, since the frame processing is generally done without the channel lock held.

Returns:
nothing

Definition at line 876 of file translate.c.

References ast_clear_flag, AST_FRFLAG_FROM_TRANSLATOR, destroy(), ast_trans_pvt::destroy, f, and ast_trans_pvt::pvt.

Referenced by __frame_free().

00877 {
00878    struct ast_trans_pvt *pvt;
00879 
00880    ast_clear_flag(fr, AST_FRFLAG_FROM_TRANSLATOR);
00881 
00882    pvt = (struct ast_trans_pvt *) (((char *) fr) - offsetof(struct ast_trans_pvt, f));
00883 
00884    if (!pvt->destroy)
00885       return;
00886    
00887    destroy(pvt);
00888 }

unsigned int ast_translate_path_steps ( unsigned int  dest,
unsigned int  src 
)

Returns the number of steps required to convert from 'src' to 'dest'.

Parameters:
dest destination format
src source format
Returns:
the number of translation steps required, or -1 if no path is available

Definition at line 775 of file translate.c.

References ast_log(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, LOG_WARNING, translator_path::multistep, powerof(), and tr_matrix.

Referenced by ast_channel_make_compatible_helper().

00776 {
00777    unsigned int res = -1;
00778 
00779    /* convert bitwise format numbers into array indices */
00780    src = powerof(src);
00781    dest = powerof(dest);
00782 
00783    if (src == -1 || dest == -1) {
00784       ast_log(LOG_WARNING, "No translator path: (%s codec is not valid)\n", src == -1 ? "starting" : "ending");
00785       return -1;
00786    }
00787    AST_RWLIST_RDLOCK(&translators);
00788 
00789    if (tr_matrix[src][dest].step)
00790       res = tr_matrix[src][dest].multistep + 1;
00791 
00792    AST_RWLIST_UNLOCK(&translators);
00793 
00794    return res;
00795 }

void ast_translator_activate ( struct ast_translator *  t  ) 

Activate a previously deactivated translator.

Parameters:
t translator to activate
Returns:
nothing
Enables the specified translator for use.

Definition at line 711 of file translate.c.

References ast_translator::active, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and rebuild_matrix().

00712 {
00713    AST_RWLIST_WRLOCK(&translators);
00714    t->active = 1;
00715    rebuild_matrix(0);
00716    AST_RWLIST_UNLOCK(&translators);
00717 }

int ast_translator_best_choice ( int *  dst,
int *  srcs 
)

Chooses the best translation path.

Given a list of sources, and a designed destination format, which should I choose?

Returns:
Returns 0 on success, -1 if no path could be found.
Note:
Modifies dests and srcs in place

Definition at line 728 of file translate.c.

References AST_FORMAT_AUDIO_MASK, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, translator_path::cost, ast_translator::cost, MAX_AUDIO_FORMAT, translator_path::multistep, and tr_matrix.

Referenced by ast_channel_make_compatible_helper(), ast_request(), iax2_request(), and set_format().

00729 {
00730    int x,y;
00731    int best = -1;
00732    int bestdst = 0;
00733    int cur, cursrc;
00734    int besttime = INT_MAX;
00735    int beststeps = INT_MAX;
00736    int common = ((*dst) & (*srcs)) & AST_FORMAT_AUDIO_MASK; /* are there common formats ? */
00737 
00738    if (common) { /* yes, pick one and return */
00739       for (cur = 1, y = 0; y <= MAX_AUDIO_FORMAT; cur <<= 1, y++) {
00740          if (cur & common) /* guaranteed to find one */
00741             break;
00742       }
00743       /* We are done, this is a common format to both. */
00744       *srcs = *dst = cur;
00745       return 0;
00746    } else { /* No, we will need to translate */
00747       AST_RWLIST_RDLOCK(&translators);
00748       for (cur = 1, y = 0; y <= MAX_AUDIO_FORMAT; cur <<= 1, y++) {
00749          if (! (cur & *dst))
00750             continue;
00751          for (cursrc = 1, x = 0; x <= MAX_AUDIO_FORMAT; cursrc <<= 1, x++) {
00752             if (!(*srcs & cursrc) || !tr_matrix[x][y].step ||
00753                 tr_matrix[x][y].cost >  besttime)
00754                continue;   /* not existing or no better */
00755             if (tr_matrix[x][y].cost < besttime ||
00756                 tr_matrix[x][y].multistep < beststeps) {
00757                /* better than what we have so far */
00758                best = cursrc;
00759                bestdst = cur;
00760                besttime = tr_matrix[x][y].cost;
00761                beststeps = tr_matrix[x][y].multistep;
00762             }
00763          }
00764       }
00765       AST_RWLIST_UNLOCK(&translators);
00766       if (best > -1) {
00767          *srcs = best;
00768          *dst = bestdst;
00769          best = 0;
00770       }
00771       return best;
00772    }
00773 }

struct ast_trans_pvt* ast_translator_build_path ( int  dest,
int  source 
) [read]

Builds a translator path Build a path (possibly NULL) from source to dest.

Parameters:
dest destination format
source source format
Returns:
ast_trans_pvt on success, NULL on failure

Definition at line 238 of file translate.c.

References ast_getformatname(), ast_log(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_translator_free_path(), ast_tv(), ast_translator::dstfmt, LOG_WARNING, newpvt(), ast_trans_pvt::next, ast_trans_pvt::nextin, ast_trans_pvt::nextout, powerof(), translator_path::step, ast_trans_pvt::t, and tr_matrix.

Referenced by ast_audiohook_read_frame(), ast_slinfactory_feed(), ast_writestream(), audio_audiohook_write_list(), conf_run(), and set_format().

00239 {
00240    struct ast_trans_pvt *head = NULL, *tail = NULL;
00241    
00242    source = powerof(source);
00243    dest = powerof(dest);
00244 
00245    if (source == -1 || dest == -1) {
00246       ast_log(LOG_WARNING, "No translator path: (%s codec is not valid)\n", source == -1 ? "starting" : "ending");
00247       return NULL;
00248    }
00249 
00250    AST_RWLIST_RDLOCK(&translators);
00251 
00252    while (source != dest) {
00253       struct ast_trans_pvt *cur;
00254       struct ast_translator *t = tr_matrix[source][dest].step;
00255       if (!t) {
00256          ast_log(LOG_WARNING, "No translator path from %s to %s\n", 
00257             ast_getformatname(source), ast_getformatname(dest));
00258          AST_RWLIST_UNLOCK(&translators);
00259          return NULL;
00260       }
00261       if (!(cur = newpvt(t))) {
00262          ast_log(LOG_WARNING, "Failed to build translator step from %d to %d\n", source, dest);
00263          if (head)
00264             ast_translator_free_path(head);  
00265          AST_RWLIST_UNLOCK(&translators);
00266          return NULL;
00267       }
00268       if (!head)
00269          head = cur;
00270       else
00271          tail->next = cur;
00272       tail = cur;
00273       cur->nextin = cur->nextout = ast_tv(0, 0);
00274       /* Keep going if this isn't the final destination */
00275       source = cur->t->dstfmt;
00276    }
00277 
00278    AST_RWLIST_UNLOCK(&translators);
00279    return head;
00280 }

void ast_translator_deactivate ( struct ast_translator *  t  ) 

Deactivate a translator.

Parameters:
t translator to deactivate
Returns:
nothing
Disables the specified translator from being used.

Definition at line 719 of file translate.c.

References ast_translator::active, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and rebuild_matrix().

00720 {
00721    AST_RWLIST_WRLOCK(&translators);
00722    t->active = 0;
00723    rebuild_matrix(0);
00724    AST_RWLIST_UNLOCK(&translators);
00725 }

void ast_translator_free_path ( struct ast_trans_pvt *  tr  ) 

Frees a translator path Frees the given translator path structure.

Parameters:
tr translator path to get rid of

Definition at line 228 of file translate.c.

References destroy(), and ast_trans_pvt::next.

Referenced by ast_audiohook_destroy(), ast_audiohook_detach_list(), ast_audiohook_read_frame(), ast_channel_free(), ast_slinfactory_destroy(), ast_slinfactory_feed(), ast_slinfactory_flush(), ast_translator_build_path(), ast_writestream(), audio_audiohook_write_list(), conf_free(), filestream_destructor(), free_translation(), and set_format().

00229 {
00230    struct ast_trans_pvt *pn = p;
00231    while ( (p = pn) ) {
00232       pn = p->next;
00233       destroy(p);
00234    }
00235 }

int ast_unregister_translator ( struct ast_translator *  t  ) 

Unregister a translator Unregisters the given tranlator.

Parameters:
t translator to unregister
Returns:
0 on success, -1 on failure

Definition at line 686 of file translate.c.

References ast_getformatname(), AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, COLOR_BLACK, COLOR_MAGENTA, ast_translator::dstfmt, ast_translator::list, ast_translator::name, rebuild_matrix(), ast_translator::srcfmt, and term_color().

Referenced by drop_translator(), load_module(), unload_module(), and unregister_translators().

00687 {
00688    char tmp[80];
00689    struct ast_translator *u;
00690    int found = 0;
00691 
00692    AST_RWLIST_WRLOCK(&translators);
00693    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&translators, u, list) {
00694       if (u == t) {
00695          AST_RWLIST_REMOVE_CURRENT(list);
00696          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));
00697          found = 1;
00698          break;
00699       }
00700    }
00701    AST_RWLIST_TRAVERSE_SAFE_END;
00702 
00703    if (found)
00704       rebuild_matrix(0);
00705 
00706    AST_RWLIST_UNLOCK(&translators);
00707 
00708    return (u ? 0 : -1);
00709 }


Generated on Wed Aug 11 01:10:36 2010 for Asterisk - the Open Source PBX by  doxygen 1.5.9