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 #include "asterisk.h"
00027
00028 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 267492 $")
00029
00030 #include "asterisk/module.h"
00031 #include "asterisk/config.h"
00032 #include "asterisk/translate.h"
00033 #include "asterisk/ulaw.h"
00034 #include "asterisk/utils.h"
00035
00036 #define BUFFER_SAMPLES 8096
00037
00038
00039 #include "asterisk/slin.h"
00040 #include "ex_ulaw.h"
00041
00042
00043 static int ulawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00044 {
00045 int i = f->samples;
00046 unsigned char *src = f->data.ptr;
00047 int16_t *dst = pvt->outbuf.i16 + pvt->samples;
00048
00049 pvt->samples += i;
00050 pvt->datalen += i * 2;
00051
00052
00053 while (i--)
00054 *dst++ = AST_MULAW(*src++);
00055
00056 return 0;
00057 }
00058
00059
00060 static int lintoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
00061 {
00062 int i = f->samples;
00063 char *dst = pvt->outbuf.c + pvt->samples;
00064 int16_t *src = f->data.ptr;
00065
00066 pvt->samples += i;
00067 pvt->datalen += i;
00068
00069 while (i--)
00070 *dst++ = AST_LIN2MU(*src++);
00071
00072 return 0;
00073 }
00074
00075
00076
00077
00078
00079 static struct ast_translator ulawtolin = {
00080 .name = "ulawtolin",
00081 .srcfmt = AST_FORMAT_ULAW,
00082 .dstfmt = AST_FORMAT_SLINEAR,
00083 .framein = ulawtolin_framein,
00084 .sample = ulaw_sample,
00085 .buffer_samples = BUFFER_SAMPLES,
00086 .buf_size = BUFFER_SAMPLES * 2,
00087 };
00088
00089 static struct ast_translator testlawtolin = {
00090 .name = "testlawtolin",
00091 .srcfmt = AST_FORMAT_TESTLAW,
00092 .dstfmt = AST_FORMAT_SLINEAR,
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 .srcfmt = AST_FORMAT_SLINEAR,
00106 .dstfmt = AST_FORMAT_ULAW,
00107 .framein = lintoulaw_framein,
00108 .sample = slin8_sample,
00109 .buf_size = BUFFER_SAMPLES,
00110 .buffer_samples = BUFFER_SAMPLES,
00111 };
00112
00113 static struct ast_translator lintotestlaw = {
00114 .name = "lintotestlaw",
00115 .srcfmt = AST_FORMAT_SLINEAR,
00116 .dstfmt = AST_FORMAT_TESTLAW,
00117 .framein = lintoulaw_framein,
00118 .sample = slin8_sample,
00119 .buf_size = BUFFER_SAMPLES,
00120 .buffer_samples = BUFFER_SAMPLES,
00121 };
00122
00123 static int reload(void)
00124 {
00125 return AST_MODULE_LOAD_SUCCESS;
00126 }
00127
00128 static int unload_module(void)
00129 {
00130 int res;
00131
00132 res = ast_unregister_translator(&lintoulaw);
00133 res |= ast_unregister_translator(&ulawtolin);
00134 res |= ast_unregister_translator(&testlawtolin);
00135 res |= ast_unregister_translator(&lintotestlaw);
00136
00137 return res;
00138 }
00139
00140 static int load_module(void)
00141 {
00142 int res;
00143
00144 res = ast_register_translator(&ulawtolin);
00145 if (!res) {
00146 res = ast_register_translator(&lintoulaw);
00147 res |= ast_register_translator(&lintotestlaw);
00148 res |= ast_register_translator(&testlawtolin);
00149 } else
00150 ast_unregister_translator(&ulawtolin);
00151 if (res)
00152 return AST_MODULE_LOAD_FAILURE;
00153 return AST_MODULE_LOAD_SUCCESS;
00154 }
00155
00156 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "mu-Law Coder/Decoder",
00157 .load = load_module,
00158 .unload = unload_module,
00159 .reload = reload,
00160 );