Fri Aug 13 18:21:23 2010

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 "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"

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_framealawtolin_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_framelintoalaw_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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, .reload = reload, }
static struct ast_translator alawtolin
static const struct ast_module_infoast_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 47 of file codec_alaw.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 189 of file codec_alaw.c.

static void __unreg_module ( void   )  [static]

Definition at line 189 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 55 of file codec_alaw.c.

References AST_ALAW, ast_trans_pvt::datalen, f, ast_trans_pvt::outbuf, and ast_trans_pvt::samples.

00056 {
00057    int i = f->samples;
00058    unsigned char *src = f->data;
00059    int16_t *dst = (int16_t *)pvt->outbuf + pvt->samples;
00060 
00061    pvt->samples += i;
00062    pvt->datalen += i * 2;  /* 2 bytes/sample */
00063    
00064    while (i--)
00065       *dst++ = AST_ALAW(*src++);
00066 
00067    return 0;
00068 }

static struct ast_frame* alawtolin_sample ( void   )  [static]

alawToLin_Sample

Definition at line 87 of file codec_alaw.c.

References AST_FORMAT_ALAW, AST_FRAME_VOICE, f, and ulaw_slin_ex.

00088 {
00089    static struct ast_frame f;
00090    f.frametype = AST_FRAME_VOICE;
00091    f.subclass = AST_FORMAT_ALAW;
00092    f.datalen = sizeof(ulaw_slin_ex);
00093    f.samples = sizeof(ulaw_slin_ex);
00094    f.mallocd = 0;
00095    f.offset = 0;
00096    f.src = __PRETTY_FUNCTION__;
00097    f.data = ulaw_slin_ex;
00098    return &f;
00099 }

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 71 of file codec_alaw.c.

References AST_LIN2A, ast_trans_pvt::datalen, f, ast_trans_pvt::outbuf, and ast_trans_pvt::samples.

00072 {
00073    int i = f->samples;
00074    char *dst = pvt->outbuf + pvt->samples;
00075    int16_t *src = f->data;
00076 
00077    pvt->samples += i;
00078    pvt->datalen += i;   /* 1 byte/sample */
00079 
00080    while (i--) 
00081       *dst++ = AST_LIN2A(*src++);
00082 
00083    return 0;
00084 }

static struct ast_frame* lintoalaw_sample ( void   )  [static]

LinToalaw_Sample.

Definition at line 102 of file codec_alaw.c.

References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, f, and slin_ulaw_ex.

00103 {
00104    static struct ast_frame f;
00105    f.frametype = AST_FRAME_VOICE;
00106    f.subclass = AST_FORMAT_SLINEAR;
00107    f.datalen = sizeof(slin_ulaw_ex);
00108    f.samples = sizeof(slin_ulaw_ex) / 2;
00109    f.mallocd = 0;
00110    f.offset = 0;
00111    f.src = __PRETTY_FUNCTION__;
00112    f.data = slin_ulaw_ex;
00113    return &f;
00114 }

static int load_module ( void   )  [static]

Definition at line 171 of file codec_alaw.c.

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

00172 {
00173    int res;
00174 
00175    parse_config();
00176    res = ast_register_translator(&alawtolin);
00177    if (!res)
00178       res = ast_register_translator(&lintoalaw);
00179    else
00180       ast_unregister_translator(&alawtolin);
00181 
00182    return res;
00183 }

static void parse_config ( void   )  [static]

Definition at line 137 of file codec_alaw.c.

References alawtolin, ast_config_load(), ast_true(), ast_variable_browse(), ast_verbose(), option_verbose, ast_translator::useplc, var, and VERBOSE_PREFIX_3.

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

static int reload ( void   )  [static]

standard module stuff

Definition at line 155 of file codec_alaw.c.

References parse_config().

00156 {
00157    parse_config();
00158    return 0;
00159 }

static int unload_module ( void   )  [static]

Definition at line 161 of file codec_alaw.c.

References alawtolin, ast_unregister_translator(), and lintoalaw.

00162 {
00163    int res;
00164 
00165    res = ast_unregister_translator(&lintoalaw);
00166    res |= ast_unregister_translator(&alawtolin);
00167 
00168    return res;
00169 }


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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, .reload = reload, } [static]

Definition at line 189 of file codec_alaw.c.

struct ast_translator alawtolin [static]

Definition at line 116 of file codec_alaw.c.

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

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 189 of file codec_alaw.c.

struct ast_translator lintoalaw [static]

Definition at line 127 of file codec_alaw.c.

Referenced by load_module(), and unload_module().


Generated on Fri Aug 13 18:21:23 2010 for Asterisk - the Open Source PBX by  doxygen 1.4.7