Tue Nov 4 13:20:36 2008

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"

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

 AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,"ITU G.722-64kbps G722 Transcoder",.load=load_module,.unload=unload_module,.reload=reload,)
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_frameg722tolin_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_framelintog722_sample (void)
static int load_module (void)
static void parse_config (int reload)
static int reload (void)
static int unload_module (void)

Variables

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

AST_MODULE_INFO ( ASTERISK_GPL_KEY  ,
AST_MODFLAG_DEFAULT  ,
"ITU G.722-64kbps G722 Transcoder"  ,
load = load_module,
unload = unload_module,
reload = reload 
)

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_trans_pvt::datalen, f, g722_decoder_pvt::g722, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, 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]

Definition at line 114 of file codec_g722.c.

References AST_FORMAT_G722, AST_FRAME_VOICE, ast_frame::data, f, g722_slin_ex, ast_frame::samples, and ast_frame::src.

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) / sizeof(g722_slin_ex[0]),
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_trans_pvt::datalen, f, g722_encoder_pvt::g722, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, and ast_trans_pvt::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]

Definition at line 128 of file codec_g722.c.

References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_frame::data, f, ast_frame::samples, slin_g722_ex, and ast_frame::src.

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) / sizeof(slin_g722_ex[0]),
00135       .src = __PRETTY_FUNCTION__,
00136       .data = slin_g722_ex,
00137    };
00138 
00139    return &f;
00140 }

static int load_module ( void   )  [static]

Definition at line 201 of file codec_g722.c.

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

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

static void parse_config ( int  reload  )  [static]

Definition at line 167 of file codec_g722.c.

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

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", g722tolin.useplc ? "" : "not ");
00179       }
00180    }
00181    ast_config_destroy(cfg);
00182 }

static int reload ( void   )  [static]

Definition at line 184 of file codec_g722.c.

References parse_config().

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

static int unload_module ( void   )  [static]

Definition at line 191 of file codec_g722.c.

References ast_unregister_translator(), g722tolin, and lintog722.

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


Variable Documentation

struct ast_translator g722tolin [static]

Definition at line 142 of file codec_g722.c.

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

struct ast_translator lintog722 [static]

Definition at line 155 of file codec_g722.c.

Referenced by load_module(), and unload_module().


Generated on Tue Nov 4 13:20:36 2008 for Asterisk - the Open Source PBX by  doxygen 1.4.7