#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <string.h>
#include <stdio.h>
#include <speex/speex.h>
#include "asterisk.h"
#include "asterisk/lock.h"
#include "asterisk/translate.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/options.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "slin_speex_ex.h"
#include "speex_slin_ex.h"
Go to the source code of this file.
Data Structures | |
struct | ast_translator_pvt |
Defines | |
#define | speex_coder_pvt ast_translator_pvt |
#define | TYPE_HIGH 0x0 |
#define | TYPE_LOW 0x1 |
#define | TYPE_MASK 0x3 |
#define | TYPE_SILENCE 0x2 |
Functions | |
AST_MUTEX_DEFINE_STATIC (localuser_lock) | |
char * | description (void) |
Provides a description of the module. | |
char * | key () |
Returns the ASTERISK_GPL_KEY. | |
static void | lintospeex_destroy (struct ast_translator_pvt *pvt) |
static int | lintospeex_framein (struct ast_translator_pvt *tmp, struct ast_frame *f) |
static struct ast_frame * | lintospeex_frameout (struct ast_translator_pvt *tmp) |
static struct ast_translator_pvt * | lintospeex_new (void) |
static struct ast_frame * | lintospeex_sample (void) |
int | load_module (void) |
Initialize the module. | |
static void | parse_config (void) |
int | reload (void) |
Reload stuff. | |
static void | speextolin_destroy (struct ast_translator_pvt *pvt) |
static int | speextolin_framein (struct ast_translator_pvt *tmp, struct ast_frame *f) |
static struct ast_frame * | speextolin_frameout (struct ast_translator_pvt *tmp) |
static struct ast_translator_pvt * | speextolin_new (void) |
static struct ast_frame * | speextolin_sample (void) |
int | unload_module (void) |
Cleanup all module structures, sockets, etc. | |
int | usecount (void) |
Provides a usecount. | |
Variables | |
static int | abr = 0 |
static int | complexity = 2 |
static int | dtx = 0 |
static int | enhancement = 0 |
static struct ast_translator | lintospeex |
static int | localusecnt = 0 |
static int | pp_agc = 0 |
static float | pp_agc_level = 8000 |
static int | pp_denoise = 0 |
static int | pp_dereverb = 0 |
static float | pp_dereverb_decay = 0.4 |
static float | pp_dereverb_level = 0.3 |
static int | pp_vad = 0 |
static int | preproc = 0 |
static int | quality = 3 |
static struct ast_translator | speextolin |
static char * | tdesc = "Speex/PCM16 (signed linear) Codec Translator" |
static int | vad = 0 |
static int | vbr = 0 |
static float | vbr_quality = 4 |
Definition in file codec_speex.c.
#define speex_coder_pvt ast_translator_pvt |
#define TYPE_HIGH 0x0 |
Definition at line 63 of file codec_speex.c.
#define TYPE_LOW 0x1 |
Definition at line 64 of file codec_speex.c.
#define TYPE_MASK 0x3 |
Definition at line 65 of file codec_speex.c.
#define TYPE_SILENCE 0x2 |
Definition at line 62 of file codec_speex.c.
AST_MUTEX_DEFINE_STATIC | ( | localuser_lock | ) |
char* description | ( | void | ) |
Provides a description of the module.
Definition at line 598 of file codec_speex.c.
References tdesc.
00599 { 00600 return tdesc; 00601 }
char* key | ( | void | ) |
Returns the ASTERISK_GPL_KEY.
This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:
char *key(void) { return ASTERISK_GPL_KEY; }
Definition at line 610 of file codec_speex.c.
References ASTERISK_GPL_KEY.
00611 { 00612 return ASTERISK_GPL_KEY; 00613 }
static void lintospeex_destroy | ( | struct ast_translator_pvt * | pvt | ) | [static] |
Definition at line 390 of file codec_speex.c.
References ast_translator_pvt::bits, free, localusecnt, preproc, and ast_translator_pvt::speex.
00391 { 00392 #ifdef _SPEEX_TYPES_H 00393 if (preproc) 00394 speex_preprocess_state_destroy(pvt->pp); 00395 #endif 00396 speex_encoder_destroy(pvt->speex); 00397 speex_bits_destroy(&pvt->bits); 00398 free(pvt); 00399 localusecnt--; 00400 }
static int lintospeex_framein | ( | struct ast_translator_pvt * | tmp, | |
struct ast_frame * | f | |||
) | [static] |
Definition at line 286 of file codec_speex.c.
References ast_log(), ast_translator_pvt::buf, ast_frame::data, ast_frame::datalen, LOG_WARNING, and ast_translator_pvt::tail.
00287 { 00288 /* Just add the frames to our stream */ 00289 /* XXX We should look at how old the rest of our stream is, and if it 00290 is too old, then we should overwrite it entirely, otherwise we can 00291 get artifacts of earlier talk that do not belong */ 00292 if (tmp->tail + f->datalen/2 < sizeof(tmp->buf) / 2) { 00293 memcpy((tmp->buf + tmp->tail), f->data, f->datalen); 00294 tmp->tail += f->datalen/2; 00295 } else { 00296 ast_log(LOG_WARNING, "Out of buffer space\n"); 00297 return -1; 00298 } 00299 return 0; 00300 }
static struct ast_frame* lintospeex_frameout | ( | struct ast_translator_pvt * | tmp | ) | [static] |
Definition at line 302 of file codec_speex.c.
References AST_FORMAT_SPEEX, AST_FRAME_CNG, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_translator_pvt::bits, ast_translator_pvt::buf, ast_frame::data, dtx, ast_translator_pvt::f, ast_translator_pvt::framesize, ast_frame::frametype, ast_frame::mallocd, ast_frame::offset, ast_translator_pvt::outbuf, preproc, ast_translator_pvt::silent_state, ast_translator_pvt::speex, ast_frame::src, ast_frame::subclass, and ast_translator_pvt::tail.
00303 { 00304 #ifndef _SPEEX_TYPES_H 00305 float fbuf[1024]; 00306 int x; 00307 #endif 00308 int len; 00309 int y=0; 00310 int is_speech=1; 00311 /* We can't work on anything less than a frame in size */ 00312 if (tmp->tail < tmp->framesize) 00313 return NULL; 00314 tmp->f.frametype = AST_FRAME_VOICE; 00315 tmp->f.subclass = AST_FORMAT_SPEEX; 00316 tmp->f.mallocd = 0; 00317 tmp->f.offset = AST_FRIENDLY_OFFSET; 00318 tmp->f.src = __PRETTY_FUNCTION__; 00319 tmp->f.data = tmp->outbuf; 00320 speex_bits_reset(&tmp->bits); 00321 while(tmp->tail >= tmp->framesize) { 00322 #ifdef _SPEEX_TYPES_H 00323 /* Preprocess audio */ 00324 if(preproc) 00325 is_speech = speex_preprocess(tmp->pp, tmp->buf, NULL); 00326 /* Encode a frame of data */ 00327 if (is_speech) { 00328 /* If DTX enabled speex_encode returns 0 during silence */ 00329 is_speech = speex_encode_int(tmp->speex, tmp->buf, &tmp->bits) || !dtx; 00330 } else { 00331 /* 5 zeros interpreted by Speex as silence (submode 0) */ 00332 speex_bits_pack(&tmp->bits, 0, 5); 00333 } 00334 #else 00335 /* Convert to floating point */ 00336 for (x=0;x<tmp->framesize;x++) 00337 fbuf[x] = tmp->buf[x]; 00338 /* Encode a frame of data */ 00339 is_speech = speex_encode(tmp->speex, fbuf, &tmp->bits) || !dtx; 00340 #endif 00341 /* Assume 8000 Hz -- 20 ms */ 00342 tmp->tail -= tmp->framesize; 00343 /* Move the data at the end of the buffer to the front */ 00344 if (tmp->tail) 00345 memmove(tmp->buf, tmp->buf + tmp->framesize, tmp->tail * 2); 00346 y++; 00347 } 00348 00349 /* Use AST_FRAME_CNG to signify the start of any silence period */ 00350 if (!is_speech) { 00351 if (tmp->silent_state) { 00352 return NULL; 00353 } else { 00354 tmp->silent_state = 1; 00355 speex_bits_reset(&tmp->bits); 00356 tmp->f.frametype = AST_FRAME_CNG; 00357 } 00358 } else { 00359 tmp->silent_state = 0; 00360 } 00361 00362 /* Terminate bit stream */ 00363 speex_bits_pack(&tmp->bits, 15, 5); 00364 len = speex_bits_write(&tmp->bits, (char *)tmp->outbuf, sizeof(tmp->outbuf)); 00365 tmp->f.datalen = len; 00366 tmp->f.samples = y * 160; 00367 #if 0 00368 { 00369 static int fd = -1; 00370 if (fd < 0) { 00371 fd = open("speex.raw", O_WRONLY|O_TRUNC|O_CREAT); 00372 if (fd > -1) { 00373 write(fd, tmp->f.data, tmp->f.datalen); 00374 close(fd); 00375 } 00376 } 00377 } 00378 #endif 00379 return &tmp->f; 00380 }
static struct ast_translator_pvt* lintospeex_new | ( | void | ) | [static] |
Definition at line 112 of file codec_speex.c.
References abr, complexity, dtx, free, malloc, pp_agc, pp_agc_level, pp_denoise, pp_dereverb, pp_dereverb_decay, pp_dereverb_level, pp_vad, preproc, quality, speex_coder_pvt, vad, vbr, and vbr_quality.
00113 { 00114 struct speex_coder_pvt *tmp; 00115 tmp = malloc(sizeof(struct speex_coder_pvt)); 00116 if (tmp) { 00117 if (!(tmp->speex = speex_encoder_init(&speex_nb_mode))) { 00118 free(tmp); 00119 tmp = NULL; 00120 } else { 00121 speex_bits_init(&tmp->bits); 00122 speex_bits_reset(&tmp->bits); 00123 speex_encoder_ctl(tmp->speex, SPEEX_GET_FRAME_SIZE, &tmp->framesize); 00124 speex_encoder_ctl(tmp->speex, SPEEX_SET_COMPLEXITY, &complexity); 00125 #ifdef _SPEEX_TYPES_H 00126 if (preproc) { 00127 tmp->pp = speex_preprocess_state_init(tmp->framesize, 8000); 00128 speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_VAD, &pp_vad); 00129 speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_AGC, &pp_agc); 00130 speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_AGC_LEVEL, &pp_agc_level); 00131 speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DENOISE, &pp_denoise); 00132 speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB, &pp_dereverb); 00133 speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &pp_dereverb_decay); 00134 speex_preprocess_ctl(tmp->pp, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &pp_dereverb_level); 00135 } 00136 #endif 00137 if (!abr && !vbr) { 00138 speex_encoder_ctl(tmp->speex, SPEEX_SET_QUALITY, &quality); 00139 if (vad) 00140 speex_encoder_ctl(tmp->speex, SPEEX_SET_VAD, &vad); 00141 } 00142 if (vbr) { 00143 speex_encoder_ctl(tmp->speex, SPEEX_SET_VBR, &vbr); 00144 speex_encoder_ctl(tmp->speex, SPEEX_SET_VBR_QUALITY, &vbr_quality); 00145 } 00146 if (abr) { 00147 speex_encoder_ctl(tmp->speex, SPEEX_SET_ABR, &abr); 00148 } 00149 if (dtx) 00150 speex_encoder_ctl(tmp->speex, SPEEX_SET_DTX, &dtx); 00151 tmp->tail = 0; 00152 tmp->silent_state = 0; 00153 } 00154 localusecnt++; 00155 } 00156 return tmp; 00157 }
static struct ast_frame* lintospeex_sample | ( | void | ) | [static] |
Definition at line 179 of file codec_speex.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_frame::data, ast_frame::datalen, ast_frame::frametype, ast_frame::mallocd, ast_frame::offset, ast_frame::samples, slin_speex_ex, ast_frame::src, and ast_frame::subclass.
00180 { 00181 static struct ast_frame f; 00182 f.frametype = AST_FRAME_VOICE; 00183 f.subclass = AST_FORMAT_SLINEAR; 00184 f.datalen = sizeof(slin_speex_ex); 00185 /* Assume 8000 Hz */ 00186 f.samples = sizeof(slin_speex_ex)/2; 00187 f.mallocd = 0; 00188 f.offset = 0; 00189 f.src = __PRETTY_FUNCTION__; 00190 f.data = slin_speex_ex; 00191 return &f; 00192 }
int load_module | ( | void | ) |
Initialize the module.
Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.
Definition at line 586 of file codec_speex.c.
References ast_register_translator(), ast_unregister_translator(), lintospeex, parse_config(), and speextolin.
00587 { 00588 int res; 00589 parse_config(); 00590 res=ast_register_translator(&speextolin); 00591 if (!res) 00592 res=ast_register_translator(&lintospeex); 00593 else 00594 ast_unregister_translator(&speextolin); 00595 return res; 00596 }
static void parse_config | ( | void | ) | [static] |
Definition at line 423 of file codec_speex.c.
References abr, ast_config_destroy(), ast_config_load(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_true(), ast_variable_browse(), ast_verbose(), cfg, complexity, dtx, enhancement, LOG_ERROR, option_verbose, pp_agc, pp_agc_level, pp_denoise, pp_dereverb, pp_dereverb_decay, pp_dereverb_level, pp_vad, preproc, quality, vad, var, vbr, vbr_quality, and VERBOSE_PREFIX_3.
00424 { 00425 struct ast_config *cfg; 00426 struct ast_variable *var; 00427 int res; 00428 float res_f; 00429 00430 if ((cfg = ast_config_load("codecs.conf"))) { 00431 if ((var = ast_variable_browse(cfg, "speex"))) { 00432 while (var) { 00433 if (!strcasecmp(var->name, "quality")) { 00434 res = abs(atoi(var->value)); 00435 if (res > -1 && res < 11) { 00436 if (option_verbose > 2) 00437 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting Quality to %d\n",res); 00438 ast_mutex_lock(&localuser_lock); 00439 quality = res; 00440 ast_mutex_unlock(&localuser_lock); 00441 } else 00442 ast_log(LOG_ERROR,"Error Quality must be 0-10\n"); 00443 } else if (!strcasecmp(var->name, "complexity")) { 00444 res = abs(atoi(var->value)); 00445 if (res > -1 && res < 11) { 00446 if (option_verbose > 2) 00447 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting Complexity to %d\n",res); 00448 ast_mutex_lock(&localuser_lock); 00449 complexity = res; 00450 ast_mutex_unlock(&localuser_lock); 00451 } else 00452 ast_log(LOG_ERROR,"Error! Complexity must be 0-10\n"); 00453 } else if (!strcasecmp(var->name, "vbr_quality")) { 00454 if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0 && res_f <= 10) { 00455 if (option_verbose > 2) 00456 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting VBR Quality to %f\n",res_f); 00457 ast_mutex_lock(&localuser_lock); 00458 vbr_quality = res_f; 00459 ast_mutex_unlock(&localuser_lock); 00460 } else 00461 ast_log(LOG_ERROR,"Error! VBR Quality must be 0-10\n"); 00462 } else if (!strcasecmp(var->name, "abr_quality")) { 00463 ast_log(LOG_ERROR,"Error! ABR Quality setting obsolete, set ABR to desired bitrate\n"); 00464 } else if (!strcasecmp(var->name, "enhancement")) { 00465 ast_mutex_lock(&localuser_lock); 00466 enhancement = ast_true(var->value) ? 1 : 0; 00467 if (option_verbose > 2) 00468 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Perceptual Enhancement Mode. [%s]\n",enhancement ? "on" : "off"); 00469 ast_mutex_unlock(&localuser_lock); 00470 } else if (!strcasecmp(var->name, "vbr")) { 00471 ast_mutex_lock(&localuser_lock); 00472 vbr = ast_true(var->value) ? 1 : 0; 00473 if (option_verbose > 2) 00474 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: VBR Mode. [%s]\n",vbr ? "on" : "off"); 00475 ast_mutex_unlock(&localuser_lock); 00476 } else if (!strcasecmp(var->name, "abr")) { 00477 res = abs(atoi(var->value)); 00478 if (res >= 0) { 00479 if (option_verbose > 2) { 00480 if (res > 0) 00481 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting ABR target bitrate to %d\n",res); 00482 else 00483 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Disabling ABR\n"); 00484 } 00485 ast_mutex_lock(&localuser_lock); 00486 abr = res; 00487 ast_mutex_unlock(&localuser_lock); 00488 } else 00489 ast_log(LOG_ERROR,"Error! ABR target bitrate must be >= 0\n"); 00490 } else if (!strcasecmp(var->name, "vad")) { 00491 ast_mutex_lock(&localuser_lock); 00492 vad = ast_true(var->value) ? 1 : 0; 00493 if (option_verbose > 2) 00494 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: VAD Mode. [%s]\n",vad ? "on" : "off"); 00495 ast_mutex_unlock(&localuser_lock); 00496 } else if (!strcasecmp(var->name, "dtx")) { 00497 ast_mutex_lock(&localuser_lock); 00498 dtx = ast_true(var->value) ? 1 : 0; 00499 if (option_verbose > 2) 00500 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: DTX Mode. [%s]\n",dtx ? "on" : "off"); 00501 ast_mutex_unlock(&localuser_lock); 00502 } else if (!strcasecmp(var->name, "preprocess")) { 00503 ast_mutex_lock(&localuser_lock); 00504 preproc = ast_true(var->value) ? 1 : 0; 00505 if (option_verbose > 2) 00506 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessing. [%s]\n",preproc ? "on" : "off"); 00507 ast_mutex_unlock(&localuser_lock); 00508 } else if (!strcasecmp(var->name, "pp_vad")) { 00509 ast_mutex_lock(&localuser_lock); 00510 pp_vad = ast_true(var->value) ? 1 : 0; 00511 if (option_verbose > 2) 00512 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor VAD. [%s]\n",pp_vad ? "on" : "off"); 00513 ast_mutex_unlock(&localuser_lock); 00514 } else if (!strcasecmp(var->name, "pp_agc")) { 00515 ast_mutex_lock(&localuser_lock); 00516 pp_agc = ast_true(var->value) ? 1 : 0; 00517 if (option_verbose > 2) 00518 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor AGC. [%s]\n",pp_agc ? "on" : "off"); 00519 ast_mutex_unlock(&localuser_lock); 00520 } else if (!strcasecmp(var->name, "pp_agc_level")) { 00521 if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0) { 00522 if (option_verbose > 2) 00523 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting preprocessor AGC Level to %f\n",res_f); 00524 ast_mutex_lock(&localuser_lock); 00525 pp_agc_level = res_f; 00526 ast_mutex_unlock(&localuser_lock); 00527 } else 00528 ast_log(LOG_ERROR,"Error! Preprocessor AGC Level must be >= 0\n"); 00529 } else if (!strcasecmp(var->name, "pp_denoise")) { 00530 ast_mutex_lock(&localuser_lock); 00531 pp_denoise = ast_true(var->value) ? 1 : 0; 00532 if (option_verbose > 2) 00533 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor Denoise. [%s]\n",pp_denoise ? "on" : "off"); 00534 ast_mutex_unlock(&localuser_lock); 00535 } else if (!strcasecmp(var->name, "pp_dereverb")) { 00536 ast_mutex_lock(&localuser_lock); 00537 pp_dereverb = ast_true(var->value) ? 1 : 0; 00538 if (option_verbose > 2) 00539 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Preprocessor Dereverb. [%s]\n",pp_dereverb ? "on" : "off"); 00540 ast_mutex_unlock(&localuser_lock); 00541 } else if (!strcasecmp(var->name, "pp_dereverb_decay")) { 00542 if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0) { 00543 if (option_verbose > 2) 00544 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting preprocessor Dereverb Decay to %f\n",res_f); 00545 ast_mutex_lock(&localuser_lock); 00546 pp_dereverb_decay = res_f; 00547 ast_mutex_unlock(&localuser_lock); 00548 } else 00549 ast_log(LOG_ERROR,"Error! Preprocessor Dereverb Decay must be >= 0\n"); 00550 } else if (!strcasecmp(var->name, "pp_dereverb_level")) { 00551 if (sscanf(var->value, "%f", &res_f) == 1 && res_f >= 0) { 00552 if (option_verbose > 2) 00553 ast_verbose(VERBOSE_PREFIX_3 "CODEC SPEEX: Setting preprocessor Dereverb Level to %f\n",res_f); 00554 ast_mutex_lock(&localuser_lock); 00555 pp_dereverb_level = res_f; 00556 ast_mutex_unlock(&localuser_lock); 00557 } else 00558 ast_log(LOG_ERROR,"Error! Preprocessor Dereverb Level must be >= 0\n"); 00559 } 00560 var = var->next; 00561 } 00562 } 00563 ast_config_destroy(cfg); 00564 } 00565 }
int reload | ( | void | ) |
Reload stuff.
This function is where any reload routines take place. Re-read config files, change signalling, whatever is appropriate on a reload.
Definition at line 567 of file codec_speex.c.
References parse_config().
00568 { 00569 parse_config(); 00570 return 0; 00571 }
static void speextolin_destroy | ( | struct ast_translator_pvt * | pvt | ) | [static] |
Definition at line 382 of file codec_speex.c.
References ast_translator_pvt::bits, free, localusecnt, and ast_translator_pvt::speex.
00383 { 00384 speex_decoder_destroy(pvt->speex); 00385 speex_bits_destroy(&pvt->bits); 00386 free(pvt); 00387 localusecnt--; 00388 }
static int speextolin_framein | ( | struct ast_translator_pvt * | tmp, | |
struct ast_frame * | f | |||
) | [static] |
Definition at line 229 of file codec_speex.c.
References ast_log(), ast_translator_pvt::bits, ast_translator_pvt::buf, ast_frame::data, ast_frame::datalen, ast_translator_pvt::framesize, LOG_WARNING, ast_translator_pvt::speex, and ast_translator_pvt::tail.
00230 { 00231 /* Assuming there's space left, decode into the current buffer at 00232 the tail location. Read in as many frames as there are */ 00233 int x; 00234 int res; 00235 #ifdef _SPEEX_TYPES_H 00236 spx_int16_t out[1024]; 00237 #else 00238 float fout[1024]; 00239 #endif 00240 00241 if (f->datalen == 0) { /* Native PLC interpolation */ 00242 if (tmp->tail + tmp->framesize > sizeof(tmp->buf) / 2) { 00243 ast_log(LOG_WARNING, "Out of buffer space\n"); 00244 return -1; 00245 } 00246 #ifdef _SPEEX_TYPES_H 00247 speex_decode_int(tmp->speex, NULL, tmp->buf + tmp->tail); 00248 #else 00249 speex_decode(tmp->speex, NULL, fout); 00250 for (x=0;x<tmp->framesize;x++) { 00251 tmp->buf[tmp->tail + x] = fout[x]; 00252 } 00253 #endif 00254 tmp->tail += tmp->framesize; 00255 return 0; 00256 } 00257 00258 /* Read in bits */ 00259 speex_bits_read_from(&tmp->bits, f->data, f->datalen); 00260 for(;;) { 00261 #ifdef _SPEEX_TYPES_H 00262 res = speex_decode_int(tmp->speex, &tmp->bits, out); 00263 #else 00264 res = speex_decode(tmp->speex, &tmp->bits, fout); 00265 #endif 00266 if (res < 0) 00267 break; 00268 if (tmp->tail + tmp->framesize < sizeof(tmp->buf) / 2) { 00269 for (x=0;x<tmp->framesize;x++) { 00270 #ifdef _SPEEX_TYPES_H 00271 tmp->buf[tmp->tail + x] = out[x]; 00272 #else 00273 tmp->buf[tmp->tail + x] = fout[x]; 00274 #endif 00275 } 00276 tmp->tail += tmp->framesize; 00277 } else { 00278 ast_log(LOG_WARNING, "Out of buffer space\n"); 00279 return -1; 00280 } 00281 00282 } 00283 return 0; 00284 }
static struct ast_frame* speextolin_frameout | ( | struct ast_translator_pvt * | tmp | ) | [static] |
Definition at line 209 of file codec_speex.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_translator_pvt::buf, ast_frame::data, ast_frame::datalen, ast_translator_pvt::f, ast_frame::frametype, ast_frame::mallocd, ast_frame::offset, ast_frame::samples, ast_frame::src, ast_frame::subclass, and ast_translator_pvt::tail.
00210 { 00211 if (!tmp->tail) 00212 return NULL; 00213 /* Signed linear is no particular frame size, so just send whatever 00214 we have in the buffer in one lump sum */ 00215 tmp->f.frametype = AST_FRAME_VOICE; 00216 tmp->f.subclass = AST_FORMAT_SLINEAR; 00217 tmp->f.datalen = tmp->tail * 2; 00218 /* Assume 8000 Hz */ 00219 tmp->f.samples = tmp->tail; 00220 tmp->f.mallocd = 0; 00221 tmp->f.offset = AST_FRIENDLY_OFFSET; 00222 tmp->f.src = __PRETTY_FUNCTION__; 00223 tmp->f.data = tmp->buf; 00224 /* Reset tail pointer */ 00225 tmp->tail = 0; 00226 return &tmp->f; 00227 }
static struct ast_translator_pvt* speextolin_new | ( | void | ) | [static] |
Definition at line 159 of file codec_speex.c.
References enhancement, free, malloc, and speex_coder_pvt.
00160 { 00161 struct speex_coder_pvt *tmp; 00162 tmp = malloc(sizeof(struct speex_coder_pvt)); 00163 if (tmp) { 00164 if (!(tmp->speex = speex_decoder_init(&speex_nb_mode))) { 00165 free(tmp); 00166 tmp = NULL; 00167 } else { 00168 speex_bits_init(&tmp->bits); 00169 speex_decoder_ctl(tmp->speex, SPEEX_GET_FRAME_SIZE, &tmp->framesize); 00170 if (enhancement) 00171 speex_decoder_ctl(tmp->speex, SPEEX_SET_ENH, &enhancement); 00172 tmp->tail = 0; 00173 } 00174 localusecnt++; 00175 } 00176 return tmp; 00177 }
static struct ast_frame* speextolin_sample | ( | void | ) | [static] |
Definition at line 194 of file codec_speex.c.
References AST_FORMAT_SPEEX, AST_FRAME_VOICE, ast_frame::data, ast_frame::datalen, ast_frame::frametype, ast_frame::mallocd, ast_frame::offset, ast_frame::samples, speex_slin_ex, ast_frame::src, and ast_frame::subclass.
00195 { 00196 static struct ast_frame f; 00197 f.frametype = AST_FRAME_VOICE; 00198 f.subclass = AST_FORMAT_SPEEX; 00199 f.datalen = sizeof(speex_slin_ex); 00200 /* All frames are 20 ms long */ 00201 f.samples = 160; 00202 f.mallocd = 0; 00203 f.offset = 0; 00204 f.src = __PRETTY_FUNCTION__; 00205 f.data = speex_slin_ex; 00206 return &f; 00207 }
int unload_module | ( | void | ) |
Cleanup all module structures, sockets, etc.
This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).
Definition at line 573 of file codec_speex.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_unregister_translator(), lintospeex, localusecnt, and speextolin.
00574 { 00575 int res; 00576 ast_mutex_lock(&localuser_lock); 00577 res = ast_unregister_translator(&lintospeex); 00578 if (!res) 00579 res = ast_unregister_translator(&speextolin); 00580 if (localusecnt) 00581 res = -1; 00582 ast_mutex_unlock(&localuser_lock); 00583 return res; 00584 }
int usecount | ( | void | ) |
Provides a usecount.
This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.
Definition at line 603 of file codec_speex.c.
References STANDARD_USECOUNT.
00604 { 00605 int res; 00606 STANDARD_USECOUNT(res); 00607 return res; 00608 }
int abr = 0 [static] |
int complexity = 2 [static] |
int dtx = 0 [static] |
Definition at line 51 of file codec_speex.c.
Referenced by lintospeex_frameout(), lintospeex_new(), and parse_config().
int enhancement = 0 [static] |
struct ast_translator lintospeex [static] |
int localusecnt = 0 [static] |
Definition at line 84 of file codec_speex.c.
int pp_agc = 0 [static] |
float pp_agc_level = 8000 [static] |
int pp_denoise = 0 [static] |
int pp_dereverb = 0 [static] |
float pp_dereverb_decay = 0.4 [static] |
float pp_dereverb_level = 0.3 [static] |
int pp_vad = 0 [static] |
int preproc = 0 [static] |
Definition at line 53 of file codec_speex.c.
Referenced by lintospeex_destroy(), lintospeex_frameout(), lintospeex_new(), and parse_config().
int quality = 3 [static] |
struct ast_translator speextolin [static] |
char* tdesc = "Speex/PCM16 (signed linear) Codec Translator" [static] |
Definition at line 86 of file codec_speex.c.
int vad = 0 [static] |
int vbr = 0 [static] |
float vbr_quality = 4 [static] |