Fri Jul 3 20:37:33 2009

Asterisk developer's documentation


codec_alaw.c File Reference

codec_alaw.c - translate between signed linear and alaw More...

#include "asterisk.h"
#include <fcntl.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <spandsp/bit_operations.h>
#include <spandsp/g711.h>
#include "asterisk/lock.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/options.h"
#include "asterisk/translate.h"
#include "asterisk/channel.h"
#include "asterisk/alaw.h"
#include "asterisk/utils.h"
#include "slin_ulaw_ex.h"
#include "ulaw_slin_ex.h"

Include dependency graph for codec_alaw.c:

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 alawtolin_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
 decode frame into lin and fill output buffer.
static struct ast_frame * alawtolin_sample (void)
 alawToLin_Sample
static int lintoalaw_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
 convert and store input samples in output buffer
static struct ast_frame * lintoalaw_sample (void)
 LinToalaw_Sample.
static int load_module (void)
static void parse_config (void)
static int reload (void)
 standard module stuff
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "A-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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, }
static struct ast_translator alawtolin
static const struct
ast_module_info * 
ast_module_info = &__mod_info
static struct ast_translator lintoalaw


Detailed Description

codec_alaw.c - translate between signed linear and alaw

Definition in file codec_alaw.c.


Define Documentation

#define BUFFER_SAMPLES   8096

Definition at line 54 of file codec_alaw.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 196 of file codec_alaw.c.

static void __unreg_module ( void   )  [static]

Definition at line 196 of file codec_alaw.c.

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

decode frame into lin and fill output buffer.

Definition at line 62 of file codec_alaw.c.

References ast_frame::data, ast_trans_pvt::datalen, ast_trans_pvt::outbuf, ast_trans_pvt::samples, and ast_frame::samples.

00063 {
00064    int i = f->samples;
00065    unsigned char *src = f->data;
00066    int16_t *dst = (int16_t *)pvt->outbuf + pvt->samples;
00067 
00068    pvt->samples += i;
00069    pvt->datalen += i * 2;  /* 2 bytes/sample */
00070    
00071    while (i--)
00072       *dst++ = alaw_to_linear(*src++);
00073 
00074    return 0;
00075 }

static struct ast_frame* alawtolin_sample ( void   )  [static, read]

alawToLin_Sample

Definition at line 94 of file codec_alaw.c.

References AST_FORMAT_ALAW, AST_FRAME_VOICE, ast_frame::data, ast_frame::datalen, ast_frame::frametype, ast_frame::mallocd, ast_frame::offset, ast_frame::samples, ast_frame::src, ast_frame::subclass, and ulaw_slin_ex.

00095 {
00096    static struct ast_frame f;
00097    f.frametype = AST_FRAME_VOICE;
00098    f.subclass = AST_FORMAT_ALAW;
00099    f.datalen = sizeof(ulaw_slin_ex);
00100    f.samples = sizeof(ulaw_slin_ex);
00101    f.mallocd = 0;
00102    f.offset = 0;
00103    f.src = __PRETTY_FUNCTION__;
00104    f.data = ulaw_slin_ex;
00105    return &f;
00106 }

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

convert and store input samples in output buffer

Definition at line 78 of file codec_alaw.c.

References ast_frame::data, ast_trans_pvt::datalen, ast_trans_pvt::outbuf, ast_trans_pvt::samples, and ast_frame::samples.

00079 {
00080    int i = f->samples;
00081    char *dst = pvt->outbuf + pvt->samples;
00082    int16_t *src = f->data;
00083 
00084    pvt->samples += i;
00085    pvt->datalen += i;   /* 1 byte/sample */
00086 
00087    while (i--) 
00088       *dst++ = linear_to_alaw(*src++);
00089 
00090    return 0;
00091 }

static struct ast_frame* lintoalaw_sample ( void   )  [static, read]

LinToalaw_Sample.

Definition at line 109 of file codec_alaw.c.

References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_frame::data, ast_frame::datalen, ast_frame::frametype, ast_frame::mallocd, ast_frame::offset, ast_frame::samples, slin_ulaw_ex, ast_frame::src, and ast_frame::subclass.

00110 {
00111    static struct ast_frame f;
00112    f.frametype = AST_FRAME_VOICE;
00113    f.subclass = AST_FORMAT_SLINEAR;
00114    f.datalen = sizeof(slin_ulaw_ex);
00115    f.samples = sizeof(slin_ulaw_ex) / 2;
00116    f.mallocd = 0;
00117    f.offset = 0;
00118    f.src = __PRETTY_FUNCTION__;
00119    f.data = slin_ulaw_ex;
00120    return &f;
00121 }

static int load_module ( void   )  [static]

Definition at line 178 of file codec_alaw.c.

References ast_register_translator, ast_unregister_translator(), and parse_config().

00179 {
00180    int res;
00181 
00182    parse_config();
00183    res = ast_register_translator(&alawtolin);
00184    if (!res)
00185       res = ast_register_translator(&lintoalaw);
00186    else
00187       ast_unregister_translator(&alawtolin);
00188 
00189    return res;
00190 }

static void parse_config ( void   )  [static]

Definition at line 144 of file codec_alaw.c.

References ast_config_destroy(), ast_config_load(), ast_true(), ast_variable_browse(), ast_verbose(), ast_variable::name, ast_variable::next, option_verbose, ast_translator::useplc, ast_variable::value, var, and VERBOSE_PREFIX_3.

Referenced by load_module(), and reload().

00145 {
00146    struct ast_variable *var;
00147    struct ast_config *cfg = ast_config_load("codecs.conf");
00148    if (!cfg)
00149       return;
00150    for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
00151       if (!strcasecmp(var->name, "genericplc")) {
00152          alawtolin.useplc = ast_true(var->value) ? 1 : 0;
00153          if (option_verbose > 2)
00154             ast_verbose(VERBOSE_PREFIX_3 "codec_alaw: %susing generic PLC\n", alawtolin.useplc ? "" : "not ");
00155       }
00156    }
00157    ast_config_destroy(cfg);
00158 }

static int reload ( void   )  [static]

standard module stuff

Definition at line 162 of file codec_alaw.c.

References parse_config().

00163 {
00164    parse_config();
00165    return 0;
00166 }

static int unload_module ( void   )  [static]

Definition at line 168 of file codec_alaw.c.

References ast_unregister_translator().

00169 {
00170    int res;
00171 
00172    res = ast_unregister_translator(&lintoalaw);
00173    res |= ast_unregister_translator(&alawtolin);
00174 
00175    return res;
00176 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "A-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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } [static]

Definition at line 196 of file codec_alaw.c.

struct ast_translator alawtolin [static]

Definition at line 123 of file codec_alaw.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 196 of file codec_alaw.c.

struct ast_translator lintoalaw [static]

Definition at line 134 of file codec_alaw.c.


Generated on Fri Jul 3 20:37:33 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.9