00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "asterisk.h"
00031
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328259 $")
00033
00034 #include "asterisk/module.h"
00035 #include "asterisk/config.h"
00036 #include "asterisk/translate.h"
00037 #include "asterisk/ulaw.h"
00038 #include "asterisk/utils.h"
00039
00040 #define BUFFER_SAMPLES 8096
00041
00042
00043 #include "asterisk/slin.h"
00044 #include "ex_ulaw.h"
00045
00046
00047 static int ulawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00048 {
00049 int i = f->samples;
00050 unsigned char *src = f->data.ptr;
00051 int16_t *dst = pvt->outbuf.i16 + pvt->samples;
00052
00053 pvt->samples += i;
00054 pvt->datalen += i * 2;
00055
00056
00057 while (i--)
00058 *dst++ = AST_MULAW(*src++);
00059
00060 return 0;
00061 }
00062
00063
00064 static int lintoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00065 {
00066 int i = f->samples;
00067 char *dst = pvt->outbuf.c + pvt->samples;
00068 int16_t *src = f->data.ptr;
00069
00070 pvt->samples += i;
00071 pvt->datalen += i;
00072
00073 while (i--)
00074 *dst++ = AST_LIN2MU(*src++);
00075
00076 return 0;
00077 }
00078
00079
00080
00081
00082
00083 static struct ast_translator ulawtolin = {
00084 .name = "ulawtolin",
00085 .framein = ulawtolin_framein,
00086 .sample = ulaw_sample,
00087 .buffer_samples = BUFFER_SAMPLES,
00088 .buf_size = BUFFER_SAMPLES * 2,
00089 };
00090
00091 static struct ast_translator testlawtolin = {
00092 .name = "testlawtolin",
00093 .framein = ulawtolin_framein,
00094 .sample = ulaw_sample,
00095 .buffer_samples = BUFFER_SAMPLES,
00096 .buf_size = BUFFER_SAMPLES * 2,
00097 };
00098
00099
00100
00101
00102
00103 static struct ast_translator lintoulaw = {
00104 .name = "lintoulaw",
00105 .framein = lintoulaw_framein,
00106 .sample = slin8_sample,
00107 .buf_size = BUFFER_SAMPLES,
00108 .buffer_samples = BUFFER_SAMPLES,
00109 };
00110
00111 static struct ast_translator lintotestlaw = {
00112 .name = "lintotestlaw",
00113 .framein = lintoulaw_framein,
00114 .sample = slin8_sample,
00115 .buf_size = BUFFER_SAMPLES,
00116 .buffer_samples = BUFFER_SAMPLES,
00117 };
00118
00119 static int reload(void)
00120 {
00121 return AST_MODULE_LOAD_SUCCESS;
00122 }
00123
00124 static int unload_module(void)
00125 {
00126 int res;
00127
00128 res = ast_unregister_translator(&lintoulaw);
00129 res |= ast_unregister_translator(&ulawtolin);
00130 res |= ast_unregister_translator(&testlawtolin);
00131 res |= ast_unregister_translator(&lintotestlaw);
00132
00133 return res;
00134 }
00135
00136 static int load_module(void)
00137 {
00138 int res;
00139
00140 ast_format_set(&lintoulaw.src_format, AST_FORMAT_SLINEAR, 0);
00141 ast_format_set(&lintoulaw.dst_format, AST_FORMAT_ULAW, 0);
00142
00143 ast_format_set(&lintotestlaw.src_format, AST_FORMAT_SLINEAR, 0);
00144 ast_format_set(&lintotestlaw.dst_format, AST_FORMAT_TESTLAW, 0);
00145
00146 ast_format_set(&ulawtolin.src_format, AST_FORMAT_ULAW, 0);
00147 ast_format_set(&ulawtolin.dst_format, AST_FORMAT_SLINEAR, 0);
00148
00149 ast_format_set(&testlawtolin.src_format, AST_FORMAT_TESTLAW, 0);
00150 ast_format_set(&testlawtolin.dst_format, AST_FORMAT_SLINEAR, 0);
00151
00152 res = ast_register_translator(&ulawtolin);
00153 if (!res) {
00154 res = ast_register_translator(&lintoulaw);
00155 res |= ast_register_translator(&lintotestlaw);
00156 res |= ast_register_translator(&testlawtolin);
00157 } else
00158 ast_unregister_translator(&ulawtolin);
00159 if (res)
00160 return AST_MODULE_LOAD_FAILURE;
00161 return AST_MODULE_LOAD_SUCCESS;
00162 }
00163
00164 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "mu-Law Coder/Decoder",
00165 .load = load_module,
00166 .unload = unload_module,
00167 .reload = reload,
00168 );