#include "asterisk.h"
#include "asterisk/translate.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
#include <gsm/gsm.h>
#include "../formats/msgsm.h"
#include "asterisk/slin.h"
#include "ex_gsm.h"
Go to the source code of this file.
Data Structures | |
struct | gsm_translator_pvt |
Defines | |
#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) |
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. | |
static int | lintogsm_framein (struct ast_trans_pvt *pvt, struct ast_frame *f) |
store samples into working buffer for later decode | |
static struct ast_frame * | lintogsm_frameout (struct ast_trans_pvt *pvt) |
encode and produce a frame | |
static int | load_module (void) |
static int | reload (void) |
standard module glue | |
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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .reload = reload, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_translator | gsmtolin |
static struct ast_translator | lintogsm |
Definition in file codec_gsm.c.
#define BUFFER_SAMPLES 8000 |
Definition at line 51 of file codec_gsm.c.
#define GSM_FRAME_LEN 33 |
Definition at line 53 of file codec_gsm.c.
Referenced by gsmtolin_framein(), and lintogsm_frameout().
#define GSM_SAMPLES 160 |
Definition at line 52 of file codec_gsm.c.
Referenced by gsm_read(), gsm_sample(), gsm_seek(), gsm_tell(), gsmtolin_framein(), lintogsm_frameout(), and wav_read().
#define MSGSM_FRAME_LEN 65 |
static void __reg_module | ( | void | ) | [static] |
Definition at line 231 of file codec_gsm.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 231 of file codec_gsm.c.
static void gsm_destroy_stuff | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 163 of file codec_gsm.c.
References gsm_translator_pvt::gsm, and ast_trans_pvt::pvt.
00164 { 00165 struct gsm_translator_pvt *tmp = pvt->pvt; 00166 if (tmp->gsm) 00167 gsm_destroy(tmp->gsm); 00168 }
static int gsm_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 65 of file codec_gsm.c.
References gsm_translator_pvt::gsm, and ast_trans_pvt::pvt.
00066 { 00067 struct gsm_translator_pvt *tmp = pvt->pvt; 00068 00069 return (tmp->gsm = gsm_create()) ? 0 : -1; 00070 }
static int gsmtolin_framein | ( | struct ast_trans_pvt * | pvt, | |
struct ast_frame * | f | |||
) | [static] |
decode and store in outbuf.
Definition at line 73 of file codec_gsm.c.
References ast_log(), BUFFER_SAMPLES, conv65(), ast_trans_pvt::datalen, f, gsm_translator_pvt::gsm, GSM_FRAME_LEN, GSM_SAMPLES, ast_trans_pvt::i16, len(), LOG_WARNING, MSGSM_FRAME_LEN, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
00074 { 00075 struct gsm_translator_pvt *tmp = pvt->pvt; 00076 int x; 00077 int16_t *dst = pvt->outbuf.i16; 00078 /* guess format from frame len. 65 for MSGSM, 33 for regular GSM */ 00079 int flen = (f->datalen % MSGSM_FRAME_LEN == 0) ? 00080 MSGSM_FRAME_LEN : GSM_FRAME_LEN; 00081 00082 for (x=0; x < f->datalen; x += flen) { 00083 unsigned char data[2 * GSM_FRAME_LEN]; 00084 unsigned char *src; 00085 int len; 00086 if (flen == MSGSM_FRAME_LEN) { 00087 len = 2*GSM_SAMPLES; 00088 src = data; 00089 /* Translate MSGSM format to Real GSM format before feeding in */ 00090 /* XXX what's the point here! we should just work 00091 * on the full format. 00092 */ 00093 conv65(f->data.ptr + x, data); 00094 } else { 00095 len = GSM_SAMPLES; 00096 src = f->data.ptr + x; 00097 } 00098 /* XXX maybe we don't need to check */ 00099 if (pvt->samples + len > BUFFER_SAMPLES) { 00100 ast_log(LOG_WARNING, "Out of buffer space\n"); 00101 return -1; 00102 } 00103 if (gsm_decode(tmp->gsm, src, dst + pvt->samples)) { 00104 ast_log(LOG_WARNING, "Invalid GSM data (1)\n"); 00105 return -1; 00106 } 00107 pvt->samples += GSM_SAMPLES; 00108 pvt->datalen += 2 * GSM_SAMPLES; 00109 if (flen == MSGSM_FRAME_LEN) { 00110 if (gsm_decode(tmp->gsm, data + GSM_FRAME_LEN, dst + pvt->samples)) { 00111 ast_log(LOG_WARNING, "Invalid GSM data (2)\n"); 00112 return -1; 00113 } 00114 pvt->samples += GSM_SAMPLES; 00115 pvt->datalen += 2 * GSM_SAMPLES; 00116 } 00117 } 00118 return 0; 00119 }
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 122 of file codec_gsm.c.
References ast_log(), gsm_translator_pvt::buf, BUFFER_SAMPLES, f, LOG_WARNING, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
00123 { 00124 struct gsm_translator_pvt *tmp = pvt->pvt; 00125 00126 /* XXX We should look at how old the rest of our stream is, and if it 00127 is too old, then we should overwrite it entirely, otherwise we can 00128 get artifacts of earlier talk that do not belong */ 00129 if (pvt->samples + f->samples > BUFFER_SAMPLES) { 00130 ast_log(LOG_WARNING, "Out of buffer space\n"); 00131 return -1; 00132 } 00133 memcpy(tmp->buf + pvt->samples, f->data.ptr, f->datalen); 00134 pvt->samples += f->samples; 00135 return 0; 00136 }
static struct ast_frame* lintogsm_frameout | ( | struct ast_trans_pvt * | pvt | ) | [static] |
encode and produce a frame
Definition at line 139 of file codec_gsm.c.
References ast_trans_frameout(), gsm_translator_pvt::buf, ast_trans_pvt::c, gsm_translator_pvt::gsm, GSM_FRAME_LEN, GSM_SAMPLES, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
00140 { 00141 struct gsm_translator_pvt *tmp = pvt->pvt; 00142 int datalen = 0; 00143 int samples = 0; 00144 00145 /* We can't work on anything less than a frame in size */ 00146 if (pvt->samples < GSM_SAMPLES) 00147 return NULL; 00148 while (pvt->samples >= GSM_SAMPLES) { 00149 /* Encode a frame of data */ 00150 gsm_encode(tmp->gsm, tmp->buf + samples, (gsm_byte *) pvt->outbuf.c + datalen); 00151 datalen += GSM_FRAME_LEN; 00152 samples += GSM_SAMPLES; 00153 pvt->samples -= GSM_SAMPLES; 00154 } 00155 00156 /* Move the data at the end of the buffer to the front */ 00157 if (pvt->samples) 00158 memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2); 00159 00160 return ast_trans_frameout(pvt, datalen, samples); 00161 }
static int load_module | ( | void | ) | [static] |
Definition at line 213 of file codec_gsm.c.
References AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_translator, ast_unregister_translator(), gsmtolin, and lintogsm.
00214 { 00215 int res; 00216 00217 res = ast_register_translator(&gsmtolin); 00218 if (!res) 00219 res=ast_register_translator(&lintogsm); 00220 else 00221 ast_unregister_translator(&gsmtolin); 00222 if (res) 00223 return AST_MODULE_LOAD_FAILURE; 00224 return AST_MODULE_LOAD_SUCCESS; 00225 }
static int reload | ( | void | ) | [static] |
standard module glue
Definition at line 197 of file codec_gsm.c.
References AST_MODULE_LOAD_SUCCESS.
00198 { 00199 return AST_MODULE_LOAD_SUCCESS; 00200 }
static int unload_module | ( | void | ) | [static] |
Definition at line 202 of file codec_gsm.c.
References ast_unregister_translator(), gsmtolin, and lintogsm.
00203 { 00204 int res; 00205 00206 res = ast_unregister_translator(&lintogsm); 00207 if (!res) 00208 res = ast_unregister_translator(&gsmtolin); 00209 00210 return res; 00211 }
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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .reload = reload, } [static] |
Definition at line 231 of file codec_gsm.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 231 of file codec_gsm.c.
struct ast_translator gsmtolin [static] |
struct ast_translator lintogsm [static] |