Wed Oct 28 11:53:22 2009

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_frameast_trans_frameout (struct ast_trans_pvt *pvt, int datalen, int samples)
 generic frameout function
struct ast_frameast_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.
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_pvtast_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 (  )     __ast_register_translator(t, ast_module_info->self)

See __ast_register_translator().

Definition at line 172 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 608 of file translate.c.

References ast_translator::active, ast_cli_register_multiple(), AST_FORMAT_SLINEAR, 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, ast_translator::buffer_samples, 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, ast_translator::plc_samples, powerof(), rebuild_matrix(), ast_translator::srcfmt, and term_color().

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

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

generic frameout function

Definition at line 203 of file translate.c.

References AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_frisolate(), 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().

00205 {
00206    struct ast_frame *f = &pvt->f;
00207 
00208    if (samples)
00209       f->samples = samples;
00210    else {
00211       if (pvt->samples == 0)
00212          return NULL;
00213       f->samples = pvt->samples;
00214       pvt->samples = 0;
00215    }
00216    if (datalen)
00217       f->datalen = datalen;
00218    else {
00219       f->datalen = pvt->datalen;
00220       pvt->datalen = 0;
00221    }
00222 
00223    f->frametype = AST_FRAME_VOICE;
00224    f->subclass = 1 << (pvt->t->dstfmt);
00225    f->mallocd = 0;
00226    f->offset = AST_FRIENDLY_OFFSET;
00227    f->src = pvt->t->name;
00228    f->data.ptr = pvt->outbuf.c;
00229 
00230    return ast_frisolate(f);
00231 }

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 295 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(), conf_run(), and process_ast_dsp().

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

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 817 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().

00818 {
00819    unsigned int res = dest;
00820    unsigned int x;
00821    unsigned int src_audio = src & AST_FORMAT_AUDIO_MASK;
00822    unsigned int src_video = src & AST_FORMAT_VIDEO_MASK;
00823 
00824    /* if we don't have a source format, we just have to try all
00825       possible destination formats */
00826    if (!src)
00827       return dest;
00828 
00829    /* If we have a source audio format, get its format index */
00830    if (src_audio)
00831       src_audio = powerof(src_audio);
00832 
00833    /* If we have a source video format, get its format index */
00834    if (src_video)
00835       src_video = powerof(src_video);
00836 
00837    AST_RWLIST_RDLOCK(&translators);
00838 
00839    /* For a given source audio format, traverse the list of
00840       known audio formats to determine whether there exists
00841       a translation path from the source format to the
00842       destination format. */
00843    for (x = 1; src_audio && (x & AST_FORMAT_AUDIO_MASK); x <<= 1) {
00844       /* if this is not a desired format, nothing to do */
00845       if (!(dest & x))
00846          continue;
00847 
00848       /* if the source is supplying this format, then
00849          we can leave it in the result */
00850       if (src & x)
00851          continue;
00852 
00853       /* if we don't have a translation path from the src
00854          to this format, remove it from the result */
00855       if (!tr_matrix[src_audio][powerof(x)].step) {
00856          res &= ~x;
00857          continue;
00858       }
00859 
00860       /* now check the opposite direction */
00861       if (!tr_matrix[powerof(x)][src_audio].step)
00862          res &= ~x;
00863    }
00864 
00865    /* For a given source video format, traverse the list of
00866       known video formats to determine whether there exists
00867       a translation path from the source format to the
00868       destination format. */
00869    for (; src_video && (x & AST_FORMAT_VIDEO_MASK); x <<= 1) {
00870       /* if this is not a desired format, nothing to do */
00871       if (!(dest & x))
00872          continue;
00873 
00874       /* if the source is supplying this format, then
00875          we can leave it in the result */
00876       if (src & x)
00877          continue;
00878 
00879       /* if we don't have a translation path from the src
00880          to this format, remove it from the result */
00881       if (!tr_matrix[src_video][powerof(x)].step) {
00882          res &= ~x;
00883          continue;
00884       }
00885 
00886       /* now check the opposite direction */
00887       if (!tr_matrix[powerof(x)][src_video].step)
00888          res &= ~x;
00889    }
00890 
00891    AST_RWLIST_UNLOCK(&translators);
00892 
00893    return res;
00894 }

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 795 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().

00796 {
00797    unsigned int res = -1;
00798 
00799    /* convert bitwise format numbers into array indices */
00800    src = powerof(src);
00801    dest = powerof(dest);
00802 
00803    if (src == -1 || dest == -1) {
00804       ast_log(LOG_WARNING, "No translator path: (%s codec is not valid)\n", src == -1 ? "starting" : "ending");
00805       return -1;
00806    }
00807    AST_RWLIST_RDLOCK(&translators);
00808 
00809    if (tr_matrix[src][dest].step)
00810       res = tr_matrix[src][dest].multistep + 1;
00811 
00812    AST_RWLIST_UNLOCK(&translators);
00813 
00814    return res;
00815 }

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 731 of file translate.c.

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

00732 {
00733    AST_RWLIST_WRLOCK(&translators);
00734    t->active = 1;
00735    rebuild_matrix(0);
00736    AST_RWLIST_UNLOCK(&translators);
00737 }

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 748 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().

00749 {
00750    int x,y;
00751    int best = -1;
00752    int bestdst = 0;
00753    int cur, cursrc;
00754    int besttime = INT_MAX;
00755    int beststeps = INT_MAX;
00756    int common = ((*dst) & (*srcs)) & AST_FORMAT_AUDIO_MASK; /* are there common formats ? */
00757 
00758    if (common) { /* yes, pick one and return */
00759       for (cur = 1, y = 0; y <= MAX_AUDIO_FORMAT; cur <<= 1, y++) {
00760          if (cur & common) /* guaranteed to find one */
00761             break;
00762       }
00763       /* We are done, this is a common format to both. */
00764       *srcs = *dst = cur;
00765       return 0;
00766    } else { /* No, we will need to translate */
00767       AST_RWLIST_RDLOCK(&translators);
00768       for (cur = 1, y = 0; y <= MAX_AUDIO_FORMAT; cur <<= 1, y++) {
00769          if (! (cur & *dst))
00770             continue;
00771          for (cursrc = 1, x = 0; x <= MAX_AUDIO_FORMAT; cursrc <<= 1, x++) {
00772             if (!(*srcs & cursrc) || !tr_matrix[x][y].step ||
00773                 tr_matrix[x][y].cost >  besttime)
00774                continue;   /* not existing or no better */
00775             if (tr_matrix[x][y].cost < besttime ||
00776                 tr_matrix[x][y].multistep < beststeps) {
00777                /* better than what we have so far */
00778                best = cursrc;
00779                bestdst = cur;
00780                besttime = tr_matrix[x][y].cost;
00781                beststeps = tr_matrix[x][y].multistep;
00782             }
00783          }
00784       }
00785       AST_RWLIST_UNLOCK(&translators);
00786       if (best > -1) {
00787          *srcs = best;
00788          *dst = bestdst;
00789          best = 0;
00790       }
00791       return best;
00792    }
00793 }

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 250 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(), misdn_set_opt_exec(), read_config(), and set_format().

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

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 739 of file translate.c.

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

00740 {
00741    AST_RWLIST_WRLOCK(&translators);
00742    t->active = 0;
00743    rebuild_matrix(0);
00744    AST_RWLIST_UNLOCK(&translators);
00745 }

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 240 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(), cl_dequeue_chan(), conf_free(), filestream_destructor(), free_translation(), and set_format().

00241 {
00242    struct ast_trans_pvt *pn = p;
00243    while ( (p = pn) ) {
00244       pn = p->next;
00245       destroy(p);
00246    }
00247 }

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 706 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().

00707 {
00708    char tmp[80];
00709    struct ast_translator *u;
00710    int found = 0;
00711 
00712    AST_RWLIST_WRLOCK(&translators);
00713    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&translators, u, list) {
00714       if (u == t) {
00715          AST_RWLIST_REMOVE_CURRENT(list);
00716          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));
00717          found = 1;
00718          break;
00719       }
00720    }
00721    AST_RWLIST_TRAVERSE_SAFE_END;
00722 
00723    if (found)
00724       rebuild_matrix(0);
00725 
00726    AST_RWLIST_UNLOCK(&translators);
00727 
00728    return (u ? 0 : -1);
00729 }


Generated on Wed Oct 28 11:53:22 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6