#include "asterisk.h"
#include <fcntl.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <spandsp/bit_operations.h>
#include <spandsp/g711.h>
#include "asterisk/lock.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/options.h"
#include "asterisk/translate.h"
#include "asterisk/channel.h"
#include "asterisk/ulaw.h"
#include "asterisk/utils.h"
#include "slin_ulaw_ex.h"
#include "ulaw_slin_ex.h"
Include dependency graph for codec_ulaw.c:
Go to the source code of this file.
Defines | |
#define | BUFFER_SAMPLES 8096 |
Functions | |
AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,"mu-Law Coder/Decoder",.load=load_module,.unload=unload_module,.reload=reload,) | |
static int | lintoulaw_framein (struct ast_trans_pvt *pvt, struct ast_frame *f) |
convert and store samples in outbuf | |
static struct ast_frame * | lintoulaw_sample (void) |
LinToulaw_Sample. | |
static int | load_module (void) |
static void | parse_config (void) |
static int | reload (void) |
static int | ulawtolin_framein (struct ast_trans_pvt *pvt, struct ast_frame *f) |
convert and store samples in outbuf | |
static struct ast_frame * | ulawtolin_sample (void) |
ulawToLin_Sample | |
static int | unload_module (void) |
Variables | |
static struct ast_translator | lintoulaw |
The complete translator for LinToulaw. | |
static struct ast_translator | ulawtolin |
The complete translator for ulawToLin. |
Definition in file codec_ulaw.c.
#define BUFFER_SAMPLES 8096 |
Definition at line 54 of file codec_ulaw.c.
AST_MODULE_INFO | ( | ASTERISK_GPL_KEY | , | |
AST_MODFLAG_DEFAULT | , | |||
"mu-Law Coder/Decoder" | , | |||
. | load = load_module , |
|||
. | unload = unload_module , |
|||
. | reload = reload | |||
) |
static int lintoulaw_framein | ( | struct ast_trans_pvt * | pvt, | |
struct ast_frame * | f | |||
) | [static] |
convert and store samples in outbuf
Definition at line 79 of file codec_ulaw.c.
References ast_trans_pvt::datalen, f, ast_trans_pvt::outbuf, and ast_trans_pvt::samples.
00080 { 00081 int i = f->samples; 00082 char *dst = pvt->outbuf + pvt->samples; 00083 int16_t *src = f->data; 00084 00085 pvt->samples += i; 00086 pvt->datalen += i; /* 1 byte/sample */ 00087 00088 while (i--) 00089 *dst++ = linear_to_ulaw(*src++); 00090 00091 return 0; 00092 }
static struct ast_frame* lintoulaw_sample | ( | void | ) | [static] |
LinToulaw_Sample.
Definition at line 113 of file codec_ulaw.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, f, and slin_ulaw_ex.
00114 { 00115 static struct ast_frame f; 00116 f.frametype = AST_FRAME_VOICE; 00117 f.subclass = AST_FORMAT_SLINEAR; 00118 f.datalen = sizeof(slin_ulaw_ex); 00119 /* Assume 8000 Hz */ 00120 f.samples = sizeof(slin_ulaw_ex) / 2; 00121 f.mallocd = 0; 00122 f.offset = 0; 00123 f.src = __PRETTY_FUNCTION__; 00124 f.data = slin_ulaw_ex; 00125 return &f; 00126 }
static int load_module | ( | void | ) | [static] |
Definition at line 190 of file codec_ulaw.c.
References ast_register_translator, ast_unregister_translator(), lintoulaw, parse_config(), and ulawtolin.
00191 { 00192 int res; 00193 00194 parse_config(); 00195 res = ast_register_translator(&ulawtolin); 00196 if (!res) 00197 res = ast_register_translator(&lintoulaw); 00198 else 00199 ast_unregister_translator(&ulawtolin); 00200 00201 return res; 00202 }
static void parse_config | ( | void | ) | [static] |
Definition at line 157 of file codec_ulaw.c.
References ast_config_load(), ast_true(), ast_variable_browse(), ast_verbose(), option_verbose, ulawtolin, ast_translator::useplc, var, and VERBOSE_PREFIX_3.
00158 { 00159 struct ast_variable *var; 00160 struct ast_config *cfg = ast_config_load("codecs.conf"); 00161 if (!cfg) 00162 return; 00163 for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) { 00164 if (!strcasecmp(var->name, "genericplc")) { 00165 ulawtolin.useplc = ast_true(var->value) ? 1 : 0; 00166 if (option_verbose > 2) 00167 ast_verbose(VERBOSE_PREFIX_3 "codec_ulaw: %susing generic PLC\n", ulawtolin.useplc ? "" : "not "); 00168 } 00169 } 00170 ast_config_destroy(cfg); 00171 }
static int reload | ( | void | ) | [static] |
Definition at line 173 of file codec_ulaw.c.
References parse_config().
00174 { 00175 parse_config(); 00176 00177 return 0; 00178 }
static int ulawtolin_framein | ( | struct ast_trans_pvt * | pvt, | |
struct ast_frame * | f | |||
) | [static] |
convert and store samples in outbuf
Definition at line 62 of file codec_ulaw.c.
References ast_trans_pvt::datalen, f, ast_trans_pvt::outbuf, and ast_trans_pvt::samples.
00063 { 00064 int i = f->samples; 00065 unsigned char *src = f->data; 00066 int16_t *dst = (int16_t *)pvt->outbuf + pvt->samples; 00067 00068 pvt->samples += i; 00069 pvt->datalen += i * 2; /* 2 bytes/sample */ 00070 00071 /* convert and copy in outbuf */ 00072 while (i--) 00073 *dst++ = ulaw_to_linear(*src++); 00074 00075 return 0; 00076 }
static struct ast_frame* ulawtolin_sample | ( | void | ) | [static] |
ulawToLin_Sample
*
Definition at line 95 of file codec_ulaw.c.
References AST_FORMAT_ULAW, AST_FRAME_VOICE, f, and ulaw_slin_ex.
00096 { 00097 static struct ast_frame f; 00098 f.frametype = AST_FRAME_VOICE; 00099 f.subclass = AST_FORMAT_ULAW; 00100 f.datalen = sizeof(ulaw_slin_ex); 00101 f.samples = sizeof(ulaw_slin_ex); 00102 f.mallocd = 0; 00103 f.offset = 0; 00104 f.src = __PRETTY_FUNCTION__; 00105 f.data = ulaw_slin_ex; 00106 return &f; 00107 }
static int unload_module | ( | void | ) | [static] |
Definition at line 180 of file codec_ulaw.c.
References ast_unregister_translator(), lintoulaw, and ulawtolin.
00181 { 00182 int res; 00183 00184 res = ast_unregister_translator(&lintoulaw); 00185 res |= ast_unregister_translator(&ulawtolin); 00186 00187 return res; 00188 }
struct ast_translator lintoulaw [static] |
The complete translator for LinToulaw.
Definition at line 147 of file codec_ulaw.c.
Referenced by load_module(), and unload_module().
struct ast_translator ulawtolin [static] |
The complete translator for ulawToLin.
Definition at line 132 of file codec_ulaw.c.
Referenced by load_module(), parse_config(), and unload_module().