Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Functions | Variables
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 "asterisk/slin.h"
#include "ex_g722.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
 

Macros

#define BUF_SHIFT   5
 
#define BUFFER_SAMPLES   8096 /* size for the translation buffers */
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int g722tolin16_new (struct ast_trans_pvt *pvt)
 
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. More...
 
static int lin16tog722_new (struct ast_trans_pvt *pvt)
 
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. More...
 
static int load_module (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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, }
 
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 cresl.nosp@m.in@d.nosp@m.igium.nosp@m..com
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com

Definition in file codec_g722.c.

Macro Definition Documentation

◆ BUF_SHIFT

#define BUF_SHIFT   5

Definition at line 49 of file codec_g722.c.

◆ BUFFER_SAMPLES

#define BUFFER_SAMPLES   8096 /* size for the translation buffers */

Definition at line 48 of file codec_g722.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 254 of file codec_g722.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 254 of file codec_g722.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 254 of file codec_g722.c.

◆ g722tolin16_new()

static int g722tolin16_new ( struct ast_trans_pvt pvt)
static

Definition at line 94 of file codec_g722.c.

References g722_decoder_pvt::g722, g722_decode_init(), ast_trans_pvt::pvt, and tmp().

95 {
96  struct g722_decoder_pvt *tmp = pvt->pvt;
97 
98  g722_decode_init(&tmp->g722, 64000, 0);
99 
100  return 0;
101 }
static int tmp()
Definition: bt_open.c:389
g722_decode_state_t g722
Definition: codec_g722.c:62
void * pvt
Definition: translate.h:219
g722_decode_state_t * g722_decode_init(g722_decode_state_t *s, int rate, int options)
Definition: g722_decode.c:153

◆ g722tolin_framein()

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

Definition at line 103 of file codec_g722.c.

References ast_frame::data, ast_trans_pvt::datalen, g722_decoder_pvt::g722, g722_decode(), ast_trans_pvt::i16, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, ast_frame::samples, ast_trans_pvt::samples, and tmp().

104 {
105  struct g722_decoder_pvt *tmp = pvt->pvt;
106  int out_samples;
107  int in_samples;
108 
109  /* g722_decode expects the samples to be in the invalid samples / 2 format */
110  in_samples = f->samples / 2;
111 
112  out_samples = g722_decode(&tmp->g722, &pvt->outbuf.i16[pvt->samples * sizeof(int16_t)],
113  (uint8_t *) f->data.ptr, in_samples);
114 
115  pvt->samples += out_samples;
116 
117  pvt->datalen += (out_samples * sizeof(int16_t));
118 
119  return 0;
120 }
int datalen
actual space used in outbuf
Definition: translate.h:218
int g722_decode(g722_decode_state_t *s, int16_t amp[], const uint8_t g722_data[], int len)
Definition: g722_decode.c:186
short int16_t
Definition: db.h:59
static int tmp()
Definition: bt_open.c:389
g722_decode_state_t g722
Definition: codec_g722.c:62
void * pvt
Definition: translate.h:219
int16_t * i16
Definition: translate.h:223
union ast_trans_pvt::@327 outbuf
union ast_frame::@263 data

◆ g722tolin_new()

static int g722tolin_new ( struct ast_trans_pvt pvt)
static

init a new instance of g722_encoder_pvt.

Definition at line 85 of file codec_g722.c.

References g722_decoder_pvt::g722, g722_decode_init(), G722_SAMPLE_RATE_8000, ast_trans_pvt::pvt, and tmp().

86 {
87  struct g722_decoder_pvt *tmp = pvt->pvt;
88 
90 
91  return 0;
92 }
static int tmp()
Definition: bt_open.c:389
g722_decode_state_t g722
Definition: codec_g722.c:62
void * pvt
Definition: translate.h:219
g722_decode_state_t * g722_decode_init(g722_decode_state_t *s, int rate, int options)
Definition: g722_decode.c:153

◆ lin16tog722_new()

static int lin16tog722_new ( struct ast_trans_pvt pvt)
static

Definition at line 75 of file codec_g722.c.

References g722_encoder_pvt::g722, g722_encode_init(), ast_trans_pvt::pvt, and tmp().

76 {
77  struct g722_encoder_pvt *tmp = pvt->pvt;
78 
79  g722_encode_init(&tmp->g722, 64000, 0);
80 
81  return 0;
82 }
static int tmp()
Definition: bt_open.c:389
void * pvt
Definition: translate.h:219
g722_encode_state_t * g722_encode_init(g722_encode_state_t *s, int rate, int options)
Definition: g722_encode.c:152
g722_encode_state_t g722
Definition: codec_g722.c:58

◆ lintog722_framein()

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

Definition at line 122 of file codec_g722.c.

References ast_frame::data, ast_trans_pvt::datalen, g722_encoder_pvt::g722, g722_encode(), ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, ast_frame::samples, ast_trans_pvt::samples, tmp(), and ast_trans_pvt::ui8.

123 {
124  struct g722_encoder_pvt *tmp = pvt->pvt;
125  int outlen;
126 
127  outlen = g722_encode(&tmp->g722, (&pvt->outbuf.ui8[pvt->datalen]),
128  (int16_t *) f->data.ptr, f->samples);
129 
130  pvt->samples += outlen * 2;
131 
132  pvt->datalen += outlen;
133 
134  return 0;
135 }
int datalen
actual space used in outbuf
Definition: translate.h:218
short int16_t
Definition: db.h:59
static int tmp()
Definition: bt_open.c:389
void * pvt
Definition: translate.h:219
uint8_t * ui8
Definition: translate.h:224
union ast_trans_pvt::@327 outbuf
int g722_encode(g722_encode_state_t *s, uint8_t g722_data[], const int16_t amp[], int len)
Definition: g722_encode.c:185
union ast_frame::@263 data
g722_encode_state_t g722
Definition: codec_g722.c:58

◆ lintog722_new()

static int lintog722_new ( struct ast_trans_pvt pvt)
static

init a new instance of g722_encoder_pvt.

Definition at line 66 of file codec_g722.c.

References g722_encoder_pvt::g722, g722_encode_init(), G722_SAMPLE_RATE_8000, ast_trans_pvt::pvt, and tmp().

67 {
68  struct g722_encoder_pvt *tmp = pvt->pvt;
69 
71 
72  return 0;
73 }
static int tmp()
Definition: bt_open.c:389
void * pvt
Definition: translate.h:219
g722_encode_state_t * g722_encode_init(g722_encode_state_t *s, int rate, int options)
Definition: g722_encode.c:152
g722_encode_state_t g722
Definition: codec_g722.c:58

◆ load_module()

static int load_module ( void  )
static

Definition at line 233 of file codec_g722.c.

References AST_MODFLAG_DEFAULT, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, ast_register_translator, ASTERISK_GPL_KEY, and unload_module().

234 {
235  int res = 0;
236 
241 
242  if (res) {
243  unload_module();
245  }
246 
248 }
static int unload_module(void)
Definition: codec_g722.c:221
static struct ast_translator lintog722
Definition: codec_g722.c:158
static struct ast_translator g722tolin
Definition: codec_g722.c:137
#define ast_register_translator(t)
See __ast_register_translator()
Definition: translate.h:257
static struct ast_translator g722tolin16
Definition: codec_g722.c:179
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static struct ast_translator lin16tog722
Definition: codec_g722.c:200

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 221 of file codec_g722.c.

References ast_unregister_translator().

Referenced by load_module().

222 {
223  int res = 0;
224 
229 
230  return res;
231 }
static struct ast_translator lintog722
Definition: codec_g722.c:158
static struct ast_translator g722tolin
Definition: codec_g722.c:137
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given tranlator.
Definition: translate.c:1333
static struct ast_translator g722tolin16
Definition: codec_g722.c:179
static struct ast_translator lin16tog722
Definition: codec_g722.c:200

Variable Documentation

◆ __mod_info

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, }
static

Definition at line 254 of file codec_g722.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 254 of file codec_g722.c.

◆ g722tolin

struct ast_translator g722tolin
static

Definition at line 137 of file codec_g722.c.

◆ g722tolin16

struct ast_translator g722tolin16
static

Definition at line 179 of file codec_g722.c.

◆ lin16tog722

struct ast_translator lin16tog722
static

Definition at line 200 of file codec_g722.c.

◆ lintog722

struct ast_translator lintog722
static

Definition at line 158 of file codec_g722.c.