Thu Jul 9 13:41:15 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 "asterisk/linkedlists.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/translate.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

static void __reg_module (void)
static void __unreg_module (void)
static int g722tolin16_new (struct ast_trans_pvt *pvt)
static struct ast_frameg722tolin16_sample (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_frameg722tolin_sample (void)
static int lin16tog722_new (struct ast_trans_pvt *pvt)
static struct ast_framelin16tog722_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 int parse_config (int reload)
static int reload (void)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, .reload = reload, }
static const struct ast_module_infoast_module_info = &__mod_info
static struct ast_translator g722tolin
static struct ast_translator g722tolin16
static struct ast_translator lin16tog722
static struct ast_translator lintog722


Detailed Description

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

Author:
Matthew Fredrickson <creslin@digium.com>

Russell Bryant <russell@digium.com>

Definition in file codec_g722.c.


Define Documentation

#define BUF_SHIFT   5

Definition at line 47 of file codec_g722.c.

#define BUFFER_SAMPLES   8096

Definition at line 46 of file codec_g722.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 305 of file codec_g722.c.

static void __unreg_module ( void   )  [static]

Definition at line 305 of file codec_g722.c.

static int g722tolin16_new ( struct ast_trans_pvt pvt  )  [static]

Definition at line 92 of file codec_g722.c.

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

00093 {
00094    struct g722_decoder_pvt *tmp = pvt->pvt;
00095 
00096    g722_decode_init(&tmp->g722, 64000, 0);
00097 
00098    return 0;
00099 }

static struct ast_frame* g722tolin16_sample ( void   )  [static]

Definition at line 149 of file codec_g722.c.

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

00150 {
00151    static struct ast_frame f = {
00152       .frametype = AST_FRAME_VOICE,
00153       .subclass = AST_FORMAT_G722,
00154       .datalen = sizeof(g722_slin_ex),
00155       .samples = sizeof(g722_slin_ex) * 2,
00156       .src = __PRETTY_FUNCTION__,
00157       .data = g722_slin_ex,
00158    };
00159 
00160    return &f;
00161 }

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

Definition at line 101 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.

00102 {
00103    struct g722_decoder_pvt *tmp = pvt->pvt;
00104    int out_samples;
00105    int in_samples;
00106 
00107    /* g722_decode expects the samples to be in the invalid samples / 2 format */
00108    in_samples = f->samples / 2;
00109 
00110    out_samples = g722_decode(&tmp->g722, (int16_t *) &pvt->outbuf[pvt->samples * sizeof(int16_t)], 
00111       (uint8_t *) f->data, in_samples);
00112 
00113    pvt->samples += out_samples;
00114 
00115    pvt->datalen += (out_samples * sizeof(int16_t));
00116 
00117    return 0;
00118 }

static int g722tolin_new ( struct ast_trans_pvt pvt  )  [static]

init a new instance of g722_encoder_pvt.

Definition at line 83 of file codec_g722.c.

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

00084 {
00085    struct g722_decoder_pvt *tmp = pvt->pvt;
00086 
00087    g722_decode_init(&tmp->g722, 64000, G722_SAMPLE_RATE_8000);
00088 
00089    return 0;
00090 }

static struct ast_frame* g722tolin_sample ( void   )  [static]

Definition at line 135 of file codec_g722.c.

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

00136 {
00137    static struct ast_frame f = {
00138       .frametype = AST_FRAME_VOICE,
00139       .subclass = AST_FORMAT_G722,
00140       .datalen = sizeof(g722_slin_ex),
00141       .samples = sizeof(g722_slin_ex) * 2,
00142       .src = __PRETTY_FUNCTION__,
00143       .data = g722_slin_ex,
00144    };
00145 
00146    return &f;
00147 }

static int lin16tog722_new ( struct ast_trans_pvt pvt  )  [static]

Definition at line 73 of file codec_g722.c.

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

00074 {
00075    struct g722_encoder_pvt *tmp = pvt->pvt;
00076 
00077    g722_encode_init(&tmp->g722, 64000, 0);
00078 
00079    return 0;
00080 }

static struct ast_frame* lin16tog722_sample ( void   )  [static]

Definition at line 177 of file codec_g722.c.

References ARRAY_LEN, AST_FORMAT_SLINEAR16, AST_FRAME_VOICE, f, ast_frame::samples, and slin_g722_ex.

00178 {
00179    static struct ast_frame f = {
00180       .frametype = AST_FRAME_VOICE,
00181       .subclass = AST_FORMAT_SLINEAR16,
00182       .datalen = sizeof(slin_g722_ex),
00183       .samples = ARRAY_LEN(slin_g722_ex),
00184       .src = __PRETTY_FUNCTION__,
00185       .data = slin_g722_ex,
00186    };
00187 
00188    return &f;
00189 }

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

Definition at line 120 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.

00121 {
00122    struct g722_encoder_pvt *tmp = pvt->pvt;
00123    int outlen;
00124 
00125    outlen = g722_encode(&tmp->g722, (uint8_t *) (&pvt->outbuf[pvt->datalen]), 
00126       (int16_t *) f->data, f->samples);
00127 
00128    pvt->samples += outlen * 2;
00129 
00130    pvt->datalen += outlen;
00131 
00132    return 0;
00133 }

static int lintog722_new ( struct ast_trans_pvt pvt  )  [static]

init a new instance of g722_encoder_pvt.

Definition at line 64 of file codec_g722.c.

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

00065 {
00066    struct g722_encoder_pvt *tmp = pvt->pvt;
00067 
00068    g722_encode_init(&tmp->g722, 64000, G722_SAMPLE_RATE_8000);
00069 
00070    return 0;
00071 }

static struct ast_frame* lintog722_sample ( void   )  [static]

Definition at line 163 of file codec_g722.c.

References ARRAY_LEN, AST_FORMAT_SLINEAR, AST_FRAME_VOICE, f, ast_frame::samples, and slin_g722_ex.

00164 {
00165    static struct ast_frame f = {
00166       .frametype = AST_FRAME_VOICE,
00167       .subclass = AST_FORMAT_SLINEAR,
00168       .datalen = sizeof(slin_g722_ex),
00169       .samples = ARRAY_LEN(slin_g722_ex),
00170       .src = __PRETTY_FUNCTION__,
00171       .data = slin_g722_ex,
00172    };
00173 
00174    return &f;
00175 }

static int load_module ( void   )  [static]

Definition at line 281 of file codec_g722.c.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_translator, g722tolin, g722tolin16, lin16tog722, lintog722, parse_config(), and unload_module().

00282 {
00283    int res = 0;
00284 
00285    if (parse_config(0))
00286       return AST_MODULE_LOAD_DECLINE;
00287 
00288    res |= ast_register_translator(&g722tolin);
00289    res |= ast_register_translator(&lintog722);
00290    res |= ast_register_translator(&g722tolin16);
00291    res |= ast_register_translator(&lin16tog722);
00292 
00293    if (res) {
00294       unload_module();
00295       return AST_MODULE_LOAD_FAILURE;
00296    }  
00297 
00298    return AST_MODULE_LOAD_SUCCESS;
00299 }

static int parse_config ( int  reload  )  [static]

Definition at line 241 of file codec_g722.c.

References ast_config_load, ast_true(), ast_variable_browse(), ast_verb, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEUNCHANGED, g722tolin, ast_translator::useplc, and var.

00242 {
00243    struct ast_variable *var;
00244    struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
00245    struct ast_config *cfg = ast_config_load("codecs.conf", config_flags);
00246 
00247    if (cfg == NULL)
00248       return 0;
00249    if (cfg == CONFIG_STATUS_FILEUNCHANGED)
00250       return 0;
00251    for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
00252       if (!strcasecmp(var->name, "genericplc")) {
00253          g722tolin.useplc = ast_true(var->value) ? 1 : 0;
00254          ast_verb(3, "codec_g722: %susing generic PLC\n",
00255                g722tolin.useplc ? "" : "not ");
00256       }
00257    }
00258    ast_config_destroy(cfg);
00259    return 0;
00260 }

static int reload ( void   )  [static]

Definition at line 262 of file codec_g722.c.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and parse_config().

00263 {
00264    if (parse_config(1))
00265       return AST_MODULE_LOAD_DECLINE;
00266    return AST_MODULE_LOAD_SUCCESS;
00267 }

static int unload_module ( void   )  [static]

Definition at line 269 of file codec_g722.c.

References ast_unregister_translator(), g722tolin, g722tolin16, lin16tog722, and lintog722.

00270 {
00271    int res = 0;
00272 
00273    res |= ast_unregister_translator(&g722tolin);
00274    res |= ast_unregister_translator(&lintog722);
00275    res |= ast_unregister_translator(&g722tolin16);
00276    res |= ast_unregister_translator(&lin16tog722);
00277 
00278    return res;
00279 }


Variable Documentation

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

Definition at line 305 of file codec_g722.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 305 of file codec_g722.c.

struct ast_translator g722tolin [static]

Definition at line 191 of file codec_g722.c.

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

struct ast_translator g722tolin16 [static]

Definition at line 216 of file codec_g722.c.

Referenced by load_module(), and unload_module().

struct ast_translator lin16tog722 [static]

Definition at line 229 of file codec_g722.c.

Referenced by load_module(), and unload_module().

struct ast_translator lintog722 [static]

Definition at line 204 of file codec_g722.c.

Referenced by load_module(), and unload_module().


Generated on Thu Jul 9 13:41:15 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7