Fri Jul 24 00:41:39 2009

Asterisk developer's documentation


codec_ulaw.c File Reference

codec_ulaw.c - translate between signed linear and ulaw More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/translate.h"
#include "asterisk/ulaw.h"
#include "asterisk/utils.h"
#include "slin_ulaw_ex.h"
#include "ulaw_slin_ex.h"

Go to the source code of this file.

Defines

#define BUFFER_SAMPLES   8096

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int lintoulaw_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
 convert and store samples in outbuf
static struct ast_framelintoulaw_sample (void)
 LinToulaw_Sample.
static int load_module (void)
static int parse_config (int reload)
static int reload (void)
static int ulawtolin_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
 convert and store samples in outbuf
static struct ast_frameulawtolin_sample (void)
 ulawToLin_Sample
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "mu-Law Coder/Decoder" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, .reload = reload, }
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_translator lintoulaw
 The complete translator for LinToulaw.
static struct ast_translator ulawtolin
 The complete translator for ulawToLin.


Detailed Description

codec_ulaw.c - translate between signed linear and ulaw

Definition in file codec_ulaw.c.


Define Documentation

#define BUFFER_SAMPLES   8096

Definition at line 36 of file codec_ulaw.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 195 of file codec_ulaw.c.

static void __unreg_module ( void   )  [static]

Definition at line 195 of file codec_ulaw.c.

static int lintoulaw_framein ( struct ast_trans_pvt pvt,
struct ast_frame f 
) [static]

convert and store samples in outbuf

Definition at line 61 of file codec_ulaw.c.

References AST_LIN2MU, ast_trans_pvt::c, ast_trans_pvt::datalen, f, ast_trans_pvt::outbuf, and ast_trans_pvt::samples.

00062 {
00063    int i = f->samples;
00064    char *dst = pvt->outbuf.c + pvt->samples;
00065    int16_t *src = f->data.ptr;
00066 
00067    pvt->samples += i;
00068    pvt->datalen += i;   /* 1 byte/sample */
00069 
00070    while (i--)
00071       *dst++ = AST_LIN2MU(*src++);
00072 
00073    return 0;
00074 }

static struct ast_frame* lintoulaw_sample ( void   )  [static]

LinToulaw_Sample.

Definition at line 95 of file codec_ulaw.c.

References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, f, and slin_ulaw_ex.

00096 {
00097    static struct ast_frame f;
00098    f.frametype = AST_FRAME_VOICE;
00099    f.subclass = AST_FORMAT_SLINEAR;
00100    f.datalen = sizeof(slin_ulaw_ex);
00101    /* Assume 8000 Hz */
00102    f.samples = sizeof(slin_ulaw_ex) / 2;
00103    f.mallocd = 0;
00104    f.offset = 0;
00105    f.src = __PRETTY_FUNCTION__;
00106    f.data.ptr = slin_ulaw_ex;
00107    return &f;
00108 }

static int load_module ( void   )  [static]

Definition at line 175 of file codec_ulaw.c.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_translator, ast_unregister_translator(), lintoulaw, parse_config(), and ulawtolin.

00176 {
00177    int res;
00178 
00179    if (parse_config(0))
00180       return AST_MODULE_LOAD_DECLINE;
00181    res = ast_register_translator(&ulawtolin);
00182    if (!res)
00183       res = ast_register_translator(&lintoulaw);
00184    else
00185       ast_unregister_translator(&ulawtolin);
00186    if (res)
00187       return AST_MODULE_LOAD_FAILURE;
00188    return AST_MODULE_LOAD_SUCCESS;
00189 }

static int parse_config ( int  reload  )  [static]

Definition at line 139 of file codec_ulaw.c.

References ast_config_load, ast_true(), ast_variable_browse(), ast_verb, CONFIG_FLAG_FILEUNCHANGED, config_flags, CONFIG_STATUS_FILEUNCHANGED, ulawtolin, ast_translator::useplc, and var.

00140 {
00141    struct ast_variable *var;
00142    struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
00143    struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
00144    if (cfg == NULL)
00145       return 0;
00146    if (cfg == CONFIG_STATUS_FILEUNCHANGED)
00147       return 0;
00148    for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
00149       if (!strcasecmp(var->name, "genericplc")) {
00150          ulawtolin.useplc = ast_true(var->value) ? 1 : 0;
00151          ast_verb(3, "codec_ulaw: %susing generic PLC\n", ulawtolin.useplc ? "" : "not ");
00152       }
00153    }
00154    ast_config_destroy(cfg);
00155    return 0;
00156 }

static int reload ( void   )  [static]

Definition at line 158 of file codec_ulaw.c.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and parse_config().

00159 {
00160    if (parse_config(1))
00161       return AST_MODULE_LOAD_DECLINE;
00162    return AST_MODULE_LOAD_SUCCESS;
00163 }

static int ulawtolin_framein ( struct ast_trans_pvt pvt,
struct ast_frame f 
) [static]

convert and store samples in outbuf

Definition at line 44 of file codec_ulaw.c.

References AST_MULAW, ast_trans_pvt::datalen, f, ast_trans_pvt::i16, ast_trans_pvt::outbuf, and ast_trans_pvt::samples.

00045 {
00046    int i = f->samples;
00047    unsigned char *src = f->data.ptr;
00048    int16_t *dst = pvt->outbuf.i16 + pvt->samples;
00049 
00050    pvt->samples += i;
00051    pvt->datalen += i * 2;  /* 2 bytes/sample */
00052 
00053    /* convert and copy in outbuf */
00054    while (i--)
00055       *dst++ = AST_MULAW(*src++);
00056 
00057    return 0;
00058 }

static struct ast_frame* ulawtolin_sample ( void   )  [static]

ulawToLin_Sample

*

Definition at line 77 of file codec_ulaw.c.

References AST_FORMAT_ULAW, AST_FRAME_VOICE, f, and ulaw_slin_ex.

00078 {
00079    static struct ast_frame f;
00080    f.frametype = AST_FRAME_VOICE;
00081    f.subclass = AST_FORMAT_ULAW;
00082    f.datalen = sizeof(ulaw_slin_ex);
00083    f.samples = sizeof(ulaw_slin_ex);
00084    f.mallocd = 0;
00085    f.offset = 0;
00086    f.src = __PRETTY_FUNCTION__;
00087    f.data.ptr = ulaw_slin_ex;
00088    return &f;
00089 }

static int unload_module ( void   )  [static]

Definition at line 165 of file codec_ulaw.c.

References ast_unregister_translator(), lintoulaw, and ulawtolin.

00166 {
00167    int res;
00168 
00169    res = ast_unregister_translator(&lintoulaw);
00170    res |= ast_unregister_translator(&ulawtolin);
00171 
00172    return res;
00173 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "mu-Law Coder/Decoder" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, .reload = reload, } [static]

Definition at line 195 of file codec_ulaw.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 195 of file codec_ulaw.c.

struct ast_translator lintoulaw [static]

The complete translator for LinToulaw.

Definition at line 129 of file codec_ulaw.c.

Referenced by dahdi_encoder_framein(), load_module(), and unload_module().

struct ast_translator ulawtolin [static]

The complete translator for ulawToLin.

Definition at line 114 of file codec_ulaw.c.

Referenced by dahdi_decoder_frameout(), load_module(), parse_config(), and unload_module().


Generated on Fri Jul 24 00:41:39 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7