Asterisk - The Open Source Telephony Project GIT-master-2de1a68
Data Structures | Macros | Functions | Variables
codec_gsm.c File Reference

Translate between signed linear and Global System for Mobile Communications (GSM) More...

#include "asterisk.h"
#include "asterisk/translate.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
#include "asterisk/linkedlists.h"
#include "gsm.h"
#include "../formats/msgsm.h"
#include "asterisk/slin.h"
#include "ex_gsm.h"
Include dependency graph for codec_gsm.c:

Go to the source code of this file.

Data Structures

struct  gsm_translator_pvt
 

Macros

#define BUFFER_SAMPLES   8000
 
#define GSM_FRAME_LEN   33
 
#define GSM_SAMPLES   160
 
#define MSGSM_FRAME_LEN   65
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static void gsm_destroy_stuff (struct ast_trans_pvt *pvt)
 
static int gsm_new (struct ast_trans_pvt *pvt)
 
static int gsmtolin_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
 decode and store in outbuf. More...
 
static int lintogsm_framein (struct ast_trans_pvt *pvt, struct ast_frame *f)
 store samples into working buffer for later decode More...
 
static struct ast_framelintogsm_frameout (struct ast_trans_pvt *pvt)
 encode and produce a frame 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 = "GSM 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, .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 gsmtolin
 
static struct ast_translator lintogsm
 

Detailed Description

Translate between signed linear and Global System for Mobile Communications (GSM)

Definition in file codec_gsm.c.

Macro Definition Documentation

◆ BUFFER_SAMPLES

#define BUFFER_SAMPLES   8000

Definition at line 50 of file codec_gsm.c.

◆ GSM_FRAME_LEN

#define GSM_FRAME_LEN   33

Definition at line 52 of file codec_gsm.c.

◆ GSM_SAMPLES

#define GSM_SAMPLES   160

Definition at line 51 of file codec_gsm.c.

◆ MSGSM_FRAME_LEN

#define MSGSM_FRAME_LEN   65

Definition at line 53 of file codec_gsm.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 252 of file codec_gsm.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 252 of file codec_gsm.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 252 of file codec_gsm.c.

◆ gsm_destroy_stuff()

static void gsm_destroy_stuff ( struct ast_trans_pvt pvt)
static

Definition at line 172 of file codec_gsm.c.

173{
174 struct gsm_translator_pvt *tmp = pvt->pvt;
175 if (tmp->gsm)
176 gsm_destroy(tmp->gsm);
177}
static int tmp()
Definition: bt_open.c:389
void * pvt
Definition: translate.h:219

References ast_trans_pvt::pvt, and tmp().

◆ gsm_new()

static int gsm_new ( struct ast_trans_pvt pvt)
static

Definition at line 64 of file codec_gsm.c.

65{
66 struct gsm_translator_pvt *tmp = pvt->pvt;
67
68 return (tmp->gsm = gsm_create()) ? 0 : -1;
69}

References ast_trans_pvt::pvt, and tmp().

◆ gsmtolin_framein()

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

decode and store in outbuf.

Definition at line 72 of file codec_gsm.c.

73{
74 struct gsm_translator_pvt *tmp = pvt->pvt;
75 int x;
76 int16_t *dst = pvt->outbuf.i16;
77 /* guess format from frame len. 65 for MSGSM, 33 for regular GSM */
78 int flen = (f->datalen % MSGSM_FRAME_LEN == 0) ?
80
81 for (x=0; x < f->datalen; x += flen) {
82 unsigned char data[2 * GSM_FRAME_LEN];
83 unsigned char *src;
84 int len;
85 if (flen == MSGSM_FRAME_LEN) {
86 len = 2*GSM_SAMPLES;
87 src = data;
88 /* Translate MSGSM format to Real GSM format before feeding in */
89 /* XXX what's the point here! we should just work
90 * on the full format.
91 */
92 conv65(f->data.ptr + x, data);
93 } else {
95 src = f->data.ptr + x;
96 }
97 /* XXX maybe we don't need to check */
98 if (pvt->samples + len > BUFFER_SAMPLES) {
99 ast_log(LOG_WARNING, "Out of buffer space\n");
100 return -1;
101 }
102 if (gsm_decode(tmp->gsm, src, dst + pvt->samples)) {
103 ast_log(LOG_WARNING, "Invalid GSM data (1)\n");
104 return -1;
105 }
106 pvt->samples += GSM_SAMPLES;
107 pvt->datalen += 2 * GSM_SAMPLES;
108 if (flen == MSGSM_FRAME_LEN) {
109 if (gsm_decode(tmp->gsm, data + GSM_FRAME_LEN, dst + pvt->samples)) {
110 ast_log(LOG_WARNING, "Invalid GSM data (2)\n");
111 return -1;
112 }
113 pvt->samples += GSM_SAMPLES;
114 pvt->datalen += 2 * GSM_SAMPLES;
115 }
116 }
117 return 0;
118}
#define ast_log
Definition: astobj2.c:42
#define BUFFER_SAMPLES
Definition: codec_gsm.c:50
#define GSM_SAMPLES
Definition: codec_gsm.c:51
#define MSGSM_FRAME_LEN
Definition: codec_gsm.c:53
#define GSM_FRAME_LEN
Definition: codec_gsm.c:52
short int16_t
Definition: db.h:59
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define LOG_WARNING
static void conv65(wav_byte *c, gsm_byte *d)
Definition: msgsm.h:457
union ast_frame::@226 data
int datalen
actual space used in outbuf
Definition: translate.h:218
union ast_trans_pvt::@287 outbuf
int16_t * i16
Definition: translate.h:223

References ast_log, BUFFER_SAMPLES, conv65(), ast_frame::data, ast_frame::datalen, ast_trans_pvt::datalen, GSM_FRAME_LEN, GSM_SAMPLES, ast_trans_pvt::i16, len(), LOG_WARNING, MSGSM_FRAME_LEN, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, ast_trans_pvt::samples, and tmp().

◆ lintogsm_framein()

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

store samples into working buffer for later decode

Definition at line 121 of file codec_gsm.c.

122{
123 struct gsm_translator_pvt *tmp = pvt->pvt;
124
125 /* XXX We should look at how old the rest of our stream is, and if it
126 is too old, then we should overwrite it entirely, otherwise we can
127 get artifacts of earlier talk that do not belong */
128 if (pvt->samples + f->samples > BUFFER_SAMPLES) {
129 ast_log(LOG_WARNING, "Out of buffer space\n");
130 return -1;
131 }
132 memcpy(tmp->buf + pvt->samples, f->data.ptr, f->datalen);
133 pvt->samples += f->samples;
134 return 0;
135}

References ast_log, BUFFER_SAMPLES, ast_frame::data, ast_frame::datalen, LOG_WARNING, ast_frame::ptr, ast_trans_pvt::pvt, ast_frame::samples, ast_trans_pvt::samples, and tmp().

◆ lintogsm_frameout()

static struct ast_frame * lintogsm_frameout ( struct ast_trans_pvt pvt)
static

encode and produce a frame

Definition at line 138 of file codec_gsm.c.

139{
140 struct gsm_translator_pvt *tmp = pvt->pvt;
141 struct ast_frame *result = NULL;
142 struct ast_frame *last = NULL;
143 int samples = 0; /* output samples */
144
145 while (pvt->samples >= GSM_SAMPLES) {
146 struct ast_frame *current;
147
148 /* Encode a frame of data */
149 gsm_encode(tmp->gsm, tmp->buf + samples, (gsm_byte *) pvt->outbuf.c);
151 pvt->samples -= GSM_SAMPLES;
152
154 if (!current) {
155 continue;
156 } else if (last) {
158 } else {
159 result = current;
160 }
161 last = current;
162 }
163
164 /* Move the data at the end of the buffer to the front */
165 if (samples) {
166 memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2);
167 }
168
169 return result;
170}
struct sla_ringing_trunk * last
Definition: app_sla.c:332
static PGresult * result
Definition: cel_pgsql.c:84
unsigned char gsm_byte
Definition: gsm.h:41
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:439
size_t current
Definition: main/cli.c:113
#define NULL
Definition: resample.c:96
Data structure associated with a single frame of data.
struct ast_frame * ast_trans_frameout(struct ast_trans_pvt *pvt, int datalen, int samples)
generic frameout function
Definition: translate.c:439

References AST_LIST_NEXT, ast_trans_frameout(), ast_trans_pvt::c, current, GSM_FRAME_LEN, GSM_SAMPLES, last, NULL, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, result, ast_frame::samples, ast_trans_pvt::samples, and tmp().

◆ load_module()

static int load_module ( void  )
static

Definition at line 233 of file codec_gsm.c.

234{
235 int res;
236
239
240 if (res) {
243 }
244
246}
static struct ast_translator lintogsm
Definition: codec_gsm.c:201
static struct ast_translator gsmtolin
Definition: codec_gsm.c:179
static int unload_module(void)
Definition: codec_gsm.c:223
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
#define ast_register_translator(t)
See __ast_register_translator()
Definition: translate.h:258

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_translator, gsmtolin, lintogsm, and unload_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 223 of file codec_gsm.c.

224{
225 int res;
226
229
230 return res;
231}
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given translator.
Definition: translate.c:1350

References ast_unregister_translator(), gsmtolin, and lintogsm.

Referenced by load_module().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "GSM 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, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, }
static

Definition at line 252 of file codec_gsm.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 252 of file codec_gsm.c.

◆ gsmtolin

struct ast_translator gsmtolin
static

Definition at line 179 of file codec_gsm.c.

Referenced by load_module(), and unload_module().

◆ lintogsm

struct ast_translator lintogsm
static

Definition at line 201 of file codec_gsm.c.

Referenced by load_module(), and unload_module().