Fri Jul 3 20:37:34 2009

Asterisk developer's documentation


codec_g722.c File Reference

codec_g722.c - translate between signed linear and ITU G.722-64kbps 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/linkedlists.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/options.h"
#include "asterisk/translate.h"
#include "asterisk/channel.h"
#include "asterisk/utils.h"
#include "g722/g722.h"
#include "slin_g722_ex.h"
#include "g722_slin_ex.h"

Include dependency graph for codec_g722.c:

Go to the source code of this file.

Data Structures

struct  g722_decoder_pvt
struct  g722_encoder_pvt

Defines

#define BUF_SHIFT   5
#define BUFFER_SAMPLES   8096

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int g722tolin_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
static int g722tolin_new (struct ast_trans_pvt *pvt)
 init a new instance of g722_encoder_pvt.
static struct ast_frame * g722tolin_sample (void)
static int lintog722_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
static int lintog722_new (struct ast_trans_pvt *pvt)
 init a new instance of g722_encoder_pvt.
static struct ast_frame * lintog722_sample (void)
static int load_module (void)
static void parse_config (void)
static int reload (void)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "ITU G.722-64kbps G722 Transcoder" , .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 g722tolin
static struct ast_translator lintog722


Detailed Description

codec_g722.c - translate between signed linear and ITU G.722-64kbps

Definition in file codec_g722.c.


Define Documentation

#define BUF_SHIFT   5

Definition at line 51 of file codec_g722.c.

#define BUFFER_SAMPLES   8096

Definition at line 50 of file codec_g722.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 222 of file codec_g722.c.

static void __unreg_module ( void   )  [static]

Definition at line 222 of file codec_g722.c.

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

Definition at line 87 of file codec_g722.c.

References ast_frame::data, ast_trans_pvt::datalen, g722_decoder_pvt::g722, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, ast_frame::samples, and ast_trans_pvt::samples.

00088 {
00089    struct g722_decoder_pvt *tmp = pvt->pvt;
00090    unsigned char *src = f->data;
00091    int16_t *dst = (int16_t *) pvt->outbuf + pvt->samples;
00092 
00093    g722_decode(&tmp->g722, dst, src, f->samples);
00094    pvt->samples += f->samples;
00095    pvt->datalen += 2 * f->samples;
00096 
00097    return 0;
00098 }

static int g722tolin_new ( struct ast_trans_pvt *  pvt  )  [static]

init a new instance of g722_encoder_pvt.

Definition at line 78 of file codec_g722.c.

References g722_decoder_pvt::g722, and ast_trans_pvt::pvt.

00079 {
00080    struct g722_decoder_pvt *tmp = pvt->pvt;
00081 
00082    g722_decode_init(&tmp->g722, 64000, G722_SAMPLE_RATE_8000);
00083 
00084    return 0;
00085 }

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

Definition at line 114 of file codec_g722.c.

References AST_FORMAT_G722, AST_FRAME_VOICE, ast_frame::frametype, g722_slin_ex, and ast_frame::samples.

00115 {
00116    static struct ast_frame f = {
00117       .frametype = AST_FRAME_VOICE,
00118       .subclass = AST_FORMAT_G722,
00119       .datalen = sizeof(g722_slin_ex),
00120       .samples = sizeof(g722_slin_ex),
00121       .src = __PRETTY_FUNCTION__,
00122       .data = g722_slin_ex,
00123    };
00124 
00125    return &f;
00126 }

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

Definition at line 100 of file codec_g722.c.

References ast_frame::data, ast_trans_pvt::datalen, g722_encoder_pvt::g722, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, ast_trans_pvt::samples, and ast_frame::samples.

00101 {
00102    struct g722_encoder_pvt *tmp = pvt->pvt;
00103    int16_t *src = f->data;
00104 
00105    g722_encode(&tmp->g722, (uint8_t*)(&pvt->outbuf[pvt->datalen]), src, f->samples);
00106    /* Since G.722 64kbps per second is one bye per sample, all of these
00107       calculations are easy */
00108    pvt->samples += f->samples;
00109    pvt->datalen += f->samples;
00110 
00111    return 0;
00112 }

static int lintog722_new ( struct ast_trans_pvt *  pvt  )  [static]

init a new instance of g722_encoder_pvt.

Definition at line 68 of file codec_g722.c.

References g722_encoder_pvt::g722, and ast_trans_pvt::pvt.

00069 {
00070    struct g722_encoder_pvt *tmp = pvt->pvt;
00071 
00072    g722_encode_init(&tmp->g722, 64000, G722_SAMPLE_RATE_8000);
00073 
00074    return 0;
00075 }

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

Definition at line 128 of file codec_g722.c.

References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_frame::frametype, ast_frame::samples, and slin_g722_ex.

00129 {
00130    static struct ast_frame f = {
00131       .frametype = AST_FRAME_VOICE,
00132       .subclass = AST_FORMAT_SLINEAR,
00133       .datalen = sizeof(slin_g722_ex),
00134       .samples = sizeof(slin_g722_ex),
00135       .src = __PRETTY_FUNCTION__,
00136       .data = slin_g722_ex,
00137    };
00138 
00139    return &f;
00140 }

static int load_module ( void   )  [static]

Definition at line 202 of file codec_g722.c.

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

00203 {
00204    int res = 0;
00205 
00206 
00207    parse_config();
00208 
00209    res |= ast_register_translator(&g722tolin);
00210    res |= ast_register_translator(&lintog722);
00211 
00212    if (res)
00213       unload_module();
00214 
00215    return res;
00216 }

static void parse_config ( void   )  [static]

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

00168 {
00169    struct ast_variable *var;
00170    struct ast_config *cfg = ast_config_load("codecs.conf");
00171 
00172    if (!cfg)
00173       return;
00174    for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
00175       if (!strcasecmp(var->name, "genericplc")) {
00176          g722tolin.useplc = ast_true(var->value) ? 1 : 0;
00177          if (option_verbose > 2)
00178             ast_verbose(VERBOSE_PREFIX_3 "codec_g722: %susing generic PLC\n",
00179                g722tolin.useplc ? "" : "not ");
00180       }
00181    }
00182    ast_config_destroy(cfg);
00183 }

static int reload ( void   )  [static]

Definition at line 185 of file codec_g722.c.

References parse_config().

00186 {
00187    parse_config();
00188 
00189    return 0;
00190 }

static int unload_module ( void   )  [static]

Definition at line 192 of file codec_g722.c.

References ast_unregister_translator().

00193 {
00194    int res = 0;
00195 
00196    res |= ast_unregister_translator(&g722tolin);
00197    res |= ast_unregister_translator(&lintog722);
00198 
00199    return res;
00200 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "ITU G.722-64kbps G722 Transcoder" , .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 222 of file codec_g722.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 222 of file codec_g722.c.

struct ast_translator g722tolin [static]

Definition at line 142 of file codec_g722.c.

struct ast_translator lintog722 [static]

Definition at line 155 of file codec_g722.c.


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