Fri Jul 3 20:37: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 <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/ulaw.h"
#include "asterisk/utils.h"
#include "slin_ulaw_ex.h"
#include "ulaw_slin_ex.h"

Include dependency graph for codec_ulaw.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 lintoulaw_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
 convert and store samples in outbuf
static struct ast_frame * lintoulaw_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_frame * ulawtolin_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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, }
static const struct
ast_module_info * 
ast_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 54 of file codec_ulaw.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 208 of file codec_ulaw.c.

static void __unreg_module ( void   )  [static]

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

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

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

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

LinToulaw_Sample.

Definition at line 113 of file codec_ulaw.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.

00114 {
00115    static struct ast_frame f;
00116    f.frametype = AST_FRAME_VOICE;
00117    f.subclass = AST_FORMAT_SLINEAR;
00118    f.datalen = sizeof(slin_ulaw_ex);
00119    /* Assume 8000 Hz */
00120    f.samples = sizeof(slin_ulaw_ex) / 2;
00121    f.mallocd = 0;
00122    f.offset = 0;
00123    f.src = __PRETTY_FUNCTION__;
00124    f.data = slin_ulaw_ex;
00125    return &f;
00126 }

static int load_module ( void   )  [static]

Definition at line 190 of file codec_ulaw.c.

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

00191 {
00192    int res;
00193 
00194    parse_config();
00195    res = ast_register_translator(&ulawtolin);
00196    if (!res)
00197       res = ast_register_translator(&lintoulaw);
00198    else
00199       ast_unregister_translator(&ulawtolin);
00200 
00201    return res;
00202 }

static void parse_config ( void   )  [static]

Definition at line 157 of file codec_ulaw.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().

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

static int reload ( void   )  [static]

Definition at line 173 of file codec_ulaw.c.

References parse_config().

00174 {
00175    parse_config();
00176 
00177    return 0;
00178 }

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

convert and store samples in outbuf

Definition at line 62 of file codec_ulaw.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    /* convert and copy in outbuf */
00072    while (i--)
00073       *dst++ = ulaw_to_linear(*src++);
00074 
00075    return 0;
00076 }

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

ulawToLin_Sample

*

Definition at line 95 of file codec_ulaw.c.

References AST_FORMAT_ULAW, 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.

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

static int unload_module ( void   )  [static]

Definition at line 180 of file codec_ulaw.c.

References ast_unregister_translator().

00181 {
00182    int res;
00183 
00184    res = ast_unregister_translator(&lintoulaw);
00185    res |= ast_unregister_translator(&ulawtolin);
00186 
00187    return res;
00188 }


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

Definition at line 208 of file codec_ulaw.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 208 of file codec_ulaw.c.

struct ast_translator lintoulaw [static]

The complete translator for LinToulaw.

Definition at line 147 of file codec_ulaw.c.

struct ast_translator ulawtolin [static]

The complete translator for ulawToLin.

Definition at line 132 of file codec_ulaw.c.


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