Thu Dec 17 15:36:02 2009

Asterisk developer's documentation


codec_ulaw.c File Reference

codec_ulaw.c - translate between signed linear and ulaw 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/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 void parse_config (void)
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 | AST_MODFLAG_BUILDSUM, .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 = "6989f2ec67f8497e38c12890500c525b" , .load = load_module, .unload = unload_module, .reload = reload, }
static const 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 47 of file codec_ulaw.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 201 of file codec_ulaw.c.

static void __unreg_module ( void   )  [static]

Definition at line 201 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 72 of file codec_ulaw.c.

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

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

static struct ast_frame* lintoulaw_sample ( void   )  [static]

LinToulaw_Sample.

Definition at line 106 of file codec_ulaw.c.

References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, f, and slin_ulaw_ex.

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

static int load_module ( void   )  [static]

Definition at line 183 of file codec_ulaw.c.

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

00184 {
00185    int res;
00186 
00187    parse_config();
00188    res = ast_register_translator(&ulawtolin);
00189    if (!res)
00190       res = ast_register_translator(&lintoulaw);
00191    else
00192       ast_unregister_translator(&ulawtolin);
00193 
00194    return res;
00195 }

static void parse_config ( void   )  [static]

Definition at line 150 of file codec_ulaw.c.

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

00151 {
00152    struct ast_variable *var;
00153    struct ast_config *cfg = ast_config_load("codecs.conf");
00154    if (!cfg)
00155       return;
00156    for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
00157       if (!strcasecmp(var->name, "genericplc")) {
00158          ulawtolin.useplc = ast_true(var->value) ? 1 : 0;
00159          if (option_verbose > 2)
00160             ast_verbose(VERBOSE_PREFIX_3 "codec_ulaw: %susing generic PLC\n", ulawtolin.useplc ? "" : "not ");
00161       }
00162    }
00163    ast_config_destroy(cfg);
00164 }

static int reload ( void   )  [static]

Definition at line 166 of file codec_ulaw.c.

References parse_config().

00167 {
00168    parse_config();
00169 
00170    return 0;
00171 }

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

convert and store samples in outbuf

Definition at line 55 of file codec_ulaw.c.

References AST_MULAW, 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    /* convert and copy in outbuf */
00065    while (i--)
00066       *dst++ = AST_MULAW(*src++);
00067 
00068    return 0;
00069 }

static struct ast_frame* ulawtolin_sample ( void   )  [static]

ulawToLin_Sample

*

Definition at line 88 of file codec_ulaw.c.

References AST_FORMAT_ULAW, AST_FRAME_VOICE, f, and ulaw_slin_ex.

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

static int unload_module ( void   )  [static]

Definition at line 173 of file codec_ulaw.c.

References ast_unregister_translator(), lintoulaw, and ulawtolin.

00174 {
00175    int res;
00176 
00177    res = ast_unregister_translator(&lintoulaw);
00178    res |= ast_unregister_translator(&ulawtolin);
00179 
00180    return res;
00181 }


Variable Documentation

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

Definition at line 201 of file codec_ulaw.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 201 of file codec_ulaw.c.

struct ast_translator lintoulaw [static]

The complete translator for LinToulaw.

Definition at line 140 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 125 of file codec_ulaw.c.

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


Generated on Thu Dec 17 15:36:02 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7