#include "asterisk.h"
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <string.h>
#include <stdio.h>
#include "asterisk/lock.h"
#include "asterisk/translate.h"
#include "asterisk/config.h"
#include "asterisk/options.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/utils.h"
#include <gsm/gsm.h>
#include "../formats/msgsm.h"
#include "slin_gsm_ex.h"
#include "gsm_slin_ex.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 struct ast_frame * | gsmtolin_sample (void) |
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 struct ast_frame * | lintogsm_sample (void) |
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 | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, .reload = reload, } |
static const 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 65 of file codec_gsm.c.
#define GSM_FRAME_LEN 33 |
Definition at line 67 of file codec_gsm.c.
Referenced by gsmtolin_framein(), and lintogsm_frameout().
#define GSM_SAMPLES 160 |
Definition at line 66 of file codec_gsm.c.
Referenced by gsm_read(), gsm_seek(), gsm_tell(), gsmtolin_framein(), gsmtolin_sample(), lintogsm_frameout(), and wav_read().
#define MSGSM_FRAME_LEN 65 |
static void __reg_module | ( | void | ) | [static] |
Definition at line 270 of file codec_gsm.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 270 of file codec_gsm.c.
static void gsm_destroy_stuff | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 203 of file codec_gsm.c.
References gsm_translator_pvt::gsm, and ast_trans_pvt::pvt.
00204 { 00205 struct gsm_translator_pvt *tmp = pvt->pvt; 00206 if (tmp->gsm) 00207 gsm_destroy(tmp->gsm); 00208 }
static int gsm_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
Definition at line 75 of file codec_gsm.c.
References gsm_translator_pvt::gsm, and ast_trans_pvt::pvt.
00076 { 00077 struct gsm_translator_pvt *tmp = pvt->pvt; 00078 00079 return (tmp->gsm = gsm_create()) ? 0 : -1; 00080 }
static int gsmtolin_framein | ( | struct ast_trans_pvt * | pvt, | |
struct ast_frame * | f | |||
) | [static] |
decode and store in outbuf.
Definition at line 113 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, len(), LOG_WARNING, MSGSM_FRAME_LEN, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
00114 { 00115 struct gsm_translator_pvt *tmp = pvt->pvt; 00116 int x; 00117 int16_t *dst = (int16_t *)pvt->outbuf; 00118 /* guess format from frame len. 65 for MSGSM, 33 for regular GSM */ 00119 int flen = (f->datalen % MSGSM_FRAME_LEN == 0) ? 00120 MSGSM_FRAME_LEN : GSM_FRAME_LEN; 00121 00122 for (x=0; x < f->datalen; x += flen) { 00123 unsigned char data[2 * GSM_FRAME_LEN]; 00124 unsigned char *src; 00125 int len; 00126 if (flen == MSGSM_FRAME_LEN) { 00127 len = 2*GSM_SAMPLES; 00128 src = data; 00129 /* Translate MSGSM format to Real GSM format before feeding in */ 00130 /* XXX what's the point here! we should just work 00131 * on the full format. 00132 */ 00133 conv65(f->data + x, data); 00134 } else { 00135 len = GSM_SAMPLES; 00136 src = f->data + x; 00137 } 00138 /* XXX maybe we don't need to check */ 00139 if (pvt->samples + len > BUFFER_SAMPLES) { 00140 ast_log(LOG_WARNING, "Out of buffer space\n"); 00141 return -1; 00142 } 00143 if (gsm_decode(tmp->gsm, src, dst + pvt->samples)) { 00144 ast_log(LOG_WARNING, "Invalid GSM data (1)\n"); 00145 return -1; 00146 } 00147 pvt->samples += GSM_SAMPLES; 00148 pvt->datalen += 2 * GSM_SAMPLES; 00149 if (flen == MSGSM_FRAME_LEN) { 00150 if (gsm_decode(tmp->gsm, data + GSM_FRAME_LEN, dst + pvt->samples)) { 00151 ast_log(LOG_WARNING, "Invalid GSM data (2)\n"); 00152 return -1; 00153 } 00154 pvt->samples += GSM_SAMPLES; 00155 pvt->datalen += 2 * GSM_SAMPLES; 00156 } 00157 } 00158 return 0; 00159 }
static struct ast_frame* gsmtolin_sample | ( | void | ) | [static] |
Definition at line 97 of file codec_gsm.c.
References AST_FORMAT_GSM, AST_FRAME_VOICE, f, GSM_SAMPLES, and gsm_slin_ex.
00098 { 00099 static struct ast_frame f; 00100 f.frametype = AST_FRAME_VOICE; 00101 f.subclass = AST_FORMAT_GSM; 00102 f.datalen = sizeof(gsm_slin_ex); 00103 /* All frames are 20 ms long */ 00104 f.samples = GSM_SAMPLES; 00105 f.mallocd = 0; 00106 f.offset = 0; 00107 f.src = __PRETTY_FUNCTION__; 00108 f.data = gsm_slin_ex; 00109 return &f; 00110 }
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 162 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.
00163 { 00164 struct gsm_translator_pvt *tmp = pvt->pvt; 00165 00166 /* XXX We should look at how old the rest of our stream is, and if it 00167 is too old, then we should overwrite it entirely, otherwise we can 00168 get artifacts of earlier talk that do not belong */ 00169 if (pvt->samples + f->samples > BUFFER_SAMPLES) { 00170 ast_log(LOG_WARNING, "Out of buffer space\n"); 00171 return -1; 00172 } 00173 memcpy(tmp->buf + pvt->samples, f->data, f->datalen); 00174 pvt->samples += f->samples; 00175 return 0; 00176 }
static struct ast_frame* lintogsm_frameout | ( | struct ast_trans_pvt * | pvt | ) | [static] |
encode and produce a frame
Definition at line 179 of file codec_gsm.c.
References ast_trans_frameout(), gsm_translator_pvt::buf, gsm_translator_pvt::gsm, GSM_FRAME_LEN, GSM_SAMPLES, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
00180 { 00181 struct gsm_translator_pvt *tmp = pvt->pvt; 00182 int datalen = 0; 00183 int samples = 0; 00184 00185 /* We can't work on anything less than a frame in size */ 00186 if (pvt->samples < GSM_SAMPLES) 00187 return NULL; 00188 while (pvt->samples >= GSM_SAMPLES) { 00189 /* Encode a frame of data */ 00190 gsm_encode(tmp->gsm, tmp->buf + samples, (gsm_byte *) pvt->outbuf + datalen); 00191 datalen += GSM_FRAME_LEN; 00192 samples += GSM_SAMPLES; 00193 pvt->samples -= GSM_SAMPLES; 00194 } 00195 00196 /* Move the data at the end of the buffer to the front */ 00197 if (pvt->samples) 00198 memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2); 00199 00200 return ast_trans_frameout(pvt, datalen, samples); 00201 }
static struct ast_frame* lintogsm_sample | ( | void | ) | [static] |
Definition at line 82 of file codec_gsm.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, f, and slin_gsm_ex.
00083 { 00084 static struct ast_frame f; 00085 f.frametype = AST_FRAME_VOICE; 00086 f.subclass = AST_FORMAT_SLINEAR; 00087 f.datalen = sizeof(slin_gsm_ex); 00088 /* Assume 8000 Hz */ 00089 f.samples = sizeof(slin_gsm_ex)/2; 00090 f.mallocd = 0; 00091 f.offset = 0; 00092 f.src = __PRETTY_FUNCTION__; 00093 f.data = slin_gsm_ex; 00094 return &f; 00095 }
static int load_module | ( | void | ) | [static] |
Definition at line 253 of file codec_gsm.c.
References ast_register_translator, ast_unregister_translator(), gsmtolin, and lintogsm.
00254 { 00255 int res; 00256 00257 res = ast_register_translator(&gsmtolin); 00258 if (!res) 00259 res=ast_register_translator(&lintogsm); 00260 else 00261 ast_unregister_translator(&gsmtolin); 00262 00263 return res; 00264 }
static int reload | ( | void | ) | [static] |
static int unload_module | ( | void | ) | [static] |
Definition at line 242 of file codec_gsm.c.
References ast_unregister_translator(), gsmtolin, and lintogsm.
00243 { 00244 int res; 00245 00246 res = ast_unregister_translator(&lintogsm); 00247 if (!res) 00248 res = ast_unregister_translator(&gsmtolin); 00249 00250 return res; 00251 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, .reload = reload, } [static] |
Definition at line 270 of file codec_gsm.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 270 of file codec_gsm.c.
struct ast_translator gsmtolin [static] |
struct ast_translator lintogsm [static] |